langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkFactory.java
author jjg
Fri, 27 May 2016 13:06:58 -0700
changeset 38617 d93a7f64e231
parent 25874 83c19f00452c
permissions -rw-r--r--
8157606: deprecate com.sun.javadoc API Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.internal.toolkit.util.links;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.javadoc.*;
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    29
import com.sun.tools.doclets.internal.toolkit.Content;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * A factory that constructs links from given link information.
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    34
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    35
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    36
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    37
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    38
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * @since 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 */
38617
d93a7f64e231 8157606: deprecate com.sun.javadoc API
jjg
parents: 25874
diff changeset
    42
@Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
public abstract class LinkFactory {
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    /**
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    46
     * Return an empty instance of a content object.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
     *
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    48
     * @return an empty instance of a content object.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    50
    protected abstract Content newContent();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * Constructs a link from the given link information.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * @param linkInfo the information about the link.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * @return the output of the link.
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    58
    public Content getLink(LinkInfo linkInfo) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        if (linkInfo.type != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
            Type type = linkInfo.type;
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    61
            Content link = newContent();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
            if (type.isPrimitive()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
                //Just a primitive.
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    64
                link.addContent(type.typeName());
16969
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
    65
            } else if (type.asAnnotatedType() != null && type.dimension().length() == 0) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    66
                link.addContent(getTypeAnnotationLinks(linkInfo));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
    67
                linkInfo.type = type.asAnnotatedType().underlyingType();
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    68
                link.addContent(getLink(linkInfo));
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    69
                return link;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
            } else if (type.asWildcardType() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
                //Wildcard type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
                linkInfo.isTypeBound = true;
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    73
                link.addContent("?");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
                WildcardType wildcardType = type.asWildcardType();
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
                Type[] extendsBounds = wildcardType.extendsBounds();
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
                for (int i = 0; i < extendsBounds.length; i++) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    77
                    link.addContent(i > 0 ? ", " : " extends ");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
                    setBoundsLinkInfo(linkInfo, extendsBounds[i]);
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    79
                    link.addContent(getLink(linkInfo));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
                Type[] superBounds = wildcardType.superBounds();
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
                for (int i = 0; i < superBounds.length; i++) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    83
                    link.addContent(i > 0 ? ", " : " super ");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
                    setBoundsLinkInfo(linkInfo, superBounds[i]);
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    85
                    link.addContent(getLink(linkInfo));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            } else if (type.asTypeVariable()!= null) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    88
                link.addContent(getTypeAnnotationLinks(linkInfo));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
                linkInfo.isTypeBound = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
                //A type variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
                Doc owner = type.asTypeVariable().owner();
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
                if ((! linkInfo.excludeTypeParameterLinks) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
                        owner instanceof ClassDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
                    linkInfo.classDoc = (ClassDoc) owner;
17560
9f6771abbd1a 8011650: reduce use of RawHtml nodes in doclet
jjg
parents: 17559
diff changeset
    95
                    Content label = newContent();
9f6771abbd1a 8011650: reduce use of RawHtml nodes in doclet
jjg
parents: 17559
diff changeset
    96
                    label.addContent(type.typeName());
9f6771abbd1a 8011650: reduce use of RawHtml nodes in doclet
jjg
parents: 17559
diff changeset
    97
                    linkInfo.label = label;
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    98
                    link.addContent(getClassLink(linkInfo));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                    //No need to link method type parameters.
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   101
                    link.addContent(type.typeName());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
                Type[] bounds = type.asTypeVariable().bounds();
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
                if (! linkInfo.excludeTypeBounds) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
                    linkInfo.excludeTypeBounds = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
                    for (int i = 0; i < bounds.length; i++) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   108
                        link.addContent(i > 0 ? " & " : " extends ");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
                        setBoundsLinkInfo(linkInfo, bounds[i]);
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   110
                        link.addContent(getLink(linkInfo));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            } else if (type.asClassDoc() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
                //A class type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
                if (linkInfo.isTypeBound &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
                        linkInfo.excludeTypeBoundsLinks) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                    //Since we are excluding type parameter links, we should not
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
                    //be linking to the type bound.
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   119
                    link.addContent(type.typeName());
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   120
                    link.addContent(getTypeParameterLinks(linkInfo));
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   121
                    return link;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
                    linkInfo.classDoc = type.asClassDoc();
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   124
                    link = newContent();
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   125
                    link.addContent(getClassLink(linkInfo));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
                    if (linkInfo.includeTypeAsSepLink) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   127
                        link.addContent(getTypeParameterLinks(linkInfo, false));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
            if (linkInfo.isVarArg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                if (type.dimension().length() > 2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                    //Javadoc returns var args as array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
                    //Strip out the first [] from the var arg.
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   136
                    link.addContent(type.dimension().substring(2));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   138
                link.addContent("...");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            } else {
16969
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   140
                while (type != null && type.dimension().length() > 0) {
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   141
                    if (type.asAnnotatedType() != null) {
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   142
                        linkInfo.type = type;
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   143
                        link.addContent(" ");
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   144
                        link.addContent(getTypeAnnotationLinks(linkInfo));
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   145
                        link.addContent("[]");
16969
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   146
                        type = type.asAnnotatedType().underlyingType().getElementType();
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   147
                    } else {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   148
                        link.addContent("[]");
16969
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   149
                        type = type.getElementType();
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   150
                    }
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   151
                }
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   152
                linkInfo.type = type;
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   153
                Content newLink = newContent();
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   154
                newLink.addContent(getTypeAnnotationLinks(linkInfo));
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   155
                newLink.addContent(link);
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   156
                link = newLink;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   158
            return link;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        } else if (linkInfo.classDoc != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            //Just a class link
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   161
            Content link = newContent();
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   162
            link.addContent(getClassLink(linkInfo));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
            if (linkInfo.includeTypeAsSepLink) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   164
                link.addContent(getTypeParameterLinks(linkInfo, false));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
            }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   166
            return link;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    private void setBoundsLinkInfo(LinkInfo linkInfo, Type bound) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        linkInfo.classDoc = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        linkInfo.label = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        linkInfo.type = bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * Return the link to the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * @param linkInfo the information about the link to construct.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * @return the link for the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   185
    protected abstract Content getClassLink(LinkInfo linkInfo);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     * Return the link to the given type parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * @param linkInfo     the information about the link to construct.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * @param typeParam the type parameter to link to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   193
    protected abstract Content getTypeParameterLink(LinkInfo linkInfo,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        Type typeParam);
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   196
    protected abstract Content getTypeAnnotationLink(LinkInfo linkInfo,
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   197
            AnnotationDesc annotation);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   198
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * Return the links to the type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     * @param linkInfo     the information about the link to construct.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * @return the links to the type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   205
    public Content getTypeParameterLinks(LinkInfo linkInfo) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        return getTypeParameterLinks(linkInfo, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     * Return the links to the type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     * @param linkInfo     the information about the link to construct.
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     * @param isClassLabel true if this is a class label.  False if it is
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     *                     the type parameters portion of the link.
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * @return the links to the type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   217
    public Content getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) {
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   218
        Content links = newContent();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        Type[] vars;
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        if (linkInfo.executableMemberDoc != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
            vars = linkInfo.executableMemberDoc.typeParameters();
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        } else if (linkInfo.type != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                linkInfo.type.asParameterizedType() != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            vars =  linkInfo.type.asParameterizedType().typeArguments();
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        } else if (linkInfo.classDoc != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
            vars = linkInfo.classDoc.typeParameters();
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
            //Nothing to document.
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   229
            return links;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        if (((linkInfo.includeTypeInClassLinkLabel && isClassLabel) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
             (linkInfo.includeTypeAsSepLink && ! isClassLabel)
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
              )
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
            && vars.length > 0) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   235
            links.addContent("<");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            for (int i = 0; i < vars.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                if (i > 0) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   238
                    links.addContent(",");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   240
                links.addContent(getTypeParameterLink(linkInfo, vars[i]));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   242
            links.addContent(">");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   244
        return links;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   247
    public Content getTypeAnnotationLinks(LinkInfo linkInfo) {
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   248
        Content links = newContent();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   249
        if (linkInfo.type.asAnnotatedType() == null)
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   250
            return links;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   251
        AnnotationDesc[] annotations = linkInfo.type.asAnnotatedType().annotations();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   252
        for (int i = 0; i < annotations.length; i++) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   253
            if (i > 0) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   254
                links.addContent(" ");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   255
            }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   256
            links.addContent(getTypeAnnotationLink(linkInfo, annotations[i]));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   257
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   258
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   259
        links.addContent(" ");
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   260
        return links;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
}