langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/links/LinkFactory.java
author mcimadamore
Fri, 16 Dec 2016 15:27:34 +0000
changeset 42827 36468b5fa7f4
parent 40606 eb2c81860c86
permissions -rw-r--r--
8181370: Convert anonymous inner classes into lambdas/method references Reviewed-by: jjg, rfield, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
     2
 * Copyright (c) 2003, 2016, 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
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    26
package jdk.javadoc.internal.doclets.toolkit.util.links;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    27
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    28
import java.util.ArrayList;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    29
import java.util.List;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    31
import javax.lang.model.element.AnnotationMirror;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    32
import javax.lang.model.element.Element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    33
import javax.lang.model.element.TypeElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    34
import javax.lang.model.element.TypeParameterElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    35
import javax.lang.model.type.ArrayType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    36
import javax.lang.model.type.DeclaredType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    37
import javax.lang.model.type.TypeMirror;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    38
import javax.lang.model.type.TypeVariable;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    39
import javax.lang.model.type.WildcardType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    40
import javax.lang.model.util.SimpleTypeVisitor9;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    41
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    42
import jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    43
import jdk.javadoc.internal.doclets.toolkit.Content;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    44
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * A factory that constructs links from given link information.
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    49
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    50
 *  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
    51
 *  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
    52
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    53
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
public abstract class LinkFactory {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    59
     * Return an empty instance of a content object.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     *
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    61
     * @return an empty instance of a content object.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    63
    protected abstract Content newContent();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * Constructs a link from the given link information.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * @param linkInfo the information about the link.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * @return the output of the link.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    71
    public Content getLink(LinkInfo linkInfo) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    72
        Utils utils = ((LinkInfoImpl) linkInfo).configuration.utils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        if (linkInfo.type != null) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    74
            SimpleTypeVisitor9<Content, LinkInfo> linkVisitor =
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    75
                    new SimpleTypeVisitor9<Content, LinkInfo>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    76
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    77
                TypeMirror componentType = utils.getComponentType(linkInfo.type);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    78
                Content link = newContent();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    79
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    80
                // handles primitives, no types and error types
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 35426
diff changeset
    81
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    82
                protected Content defaultAction(TypeMirror type, LinkInfo linkInfo) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    83
                    link.addContent(utils.getTypeName(type, false));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    84
                    return link;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    87
                int currentDepth = 0;
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 35426
diff changeset
    88
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    89
                public Content visitArray(ArrayType type, LinkInfo linkInfo) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    90
                    // keep track of the dimension depth and replace the last dimension
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    91
                    // specifier with vararags, when the stack is fully unwound.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    92
                    currentDepth++;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    93
                    linkInfo.type = type.getComponentType();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    94
                    visit(linkInfo.type, linkInfo);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    95
                    currentDepth--;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    96
                    if (utils.isAnnotated(type)) {
16969
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
    97
                        linkInfo.type = type;
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    98
                        link.addContent(" ");
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
    99
                        link.addContent(getTypeAnnotationLinks(linkInfo));
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   100
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   101
                    // use vararg if required
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   102
                    if (linkInfo.isVarArg && currentDepth == 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   103
                        link.addContent("...");
16969
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   104
                    } else {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   105
                        link.addContent("[]");
16969
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   106
                    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   107
                    return link;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   108
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   109
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 35426
diff changeset
   110
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   111
                public Content visitWildcard(WildcardType type, LinkInfo linkInfo) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   112
                    linkInfo.isTypeBound = true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   113
                    link.addContent("?");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   114
                    TypeMirror extendsBound = type.getExtendsBound();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   115
                    if (extendsBound != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   116
                        link.addContent(" extends ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   117
                        setBoundsLinkInfo(linkInfo, extendsBound);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   118
                        link.addContent(getLink(linkInfo));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   119
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   120
                    TypeMirror superBound = type.getSuperBound();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   121
                    if (superBound != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   122
                        link.addContent(" super ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   123
                        setBoundsLinkInfo(linkInfo, superBound);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   124
                        link.addContent(getLink(linkInfo));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   125
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   126
                    return link;
16969
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   127
                }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   128
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 35426
diff changeset
   129
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   130
                public Content visitTypeVariable(TypeVariable type, LinkInfo linkInfo) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   131
                    link.addContent(getTypeAnnotationLinks(linkInfo));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   132
                    linkInfo.isTypeBound = true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   133
                    TypeVariable typevariable = (utils.isArrayType(type))
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   134
                            ? (TypeVariable) componentType
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   135
                            : type;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   136
                    Element owner = typevariable.asElement().getEnclosingElement();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   137
                    if ((!linkInfo.excludeTypeParameterLinks) && utils.isTypeElement(owner)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   138
                        linkInfo.typeElement = (TypeElement) owner;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   139
                        Content label = newContent();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   140
                        label.addContent(utils.getTypeName(type, false));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   141
                        linkInfo.label = label;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   142
                        link.addContent(getClassLink(linkInfo));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   143
                    } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   144
                        // No need to link method type parameters.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   145
                        link.addContent(utils.getTypeName(typevariable, false));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   146
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   147
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   148
                    if (!linkInfo.excludeTypeBounds) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   149
                        linkInfo.excludeTypeBounds = true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   150
                        TypeParameterElement tpe = ((TypeParameterElement) typevariable.asElement());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   151
                        boolean more = false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   152
                        List<? extends TypeMirror> bounds = utils.getBounds(tpe);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   153
                        for (TypeMirror bound : bounds) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   154
                            // we get everything as extends java.lang.Object we suppress
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   155
                            // all of them except those that have multiple extends
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   156
                            if (bounds.size() == 1 &&
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   157
                                    bound.equals(utils.getObjectType()) &&
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   158
                                    !utils.isAnnotated(bound)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   159
                                continue;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   160
                            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   161
                            link.addContent(more ? " & " : " extends ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   162
                            setBoundsLinkInfo(linkInfo, bound);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   163
                            link.addContent(getLink(linkInfo));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   164
                            more = true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   165
                        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   166
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   167
                    return link;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   168
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   169
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 35426
diff changeset
   170
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   171
                public Content visitDeclared(DeclaredType type, LinkInfo linkInfo) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   172
                    if (linkInfo.isTypeBound && linkInfo.excludeTypeBoundsLinks) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   173
                        // Since we are excluding type parameter links, we should not
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   174
                        // be linking to the type bound.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   175
                        link.addContent(utils.getTypeName(type, false));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   176
                        link.addContent(getTypeParameterLinks(linkInfo));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   177
                        return link;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   178
                    } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   179
                        link = newContent();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   180
                        link.addContent(getTypeAnnotationLinks(linkInfo));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   181
                        linkInfo.typeElement = utils.asTypeElement(type);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   182
                        link.addContent(getClassLink(linkInfo));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   183
                        if (linkInfo.includeTypeAsSepLink) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   184
                            link.addContent(getTypeParameterLinks(linkInfo, false));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   185
                        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   186
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   187
                    return link;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   188
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   189
            };
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   190
            return linkVisitor.visit(linkInfo.type, linkInfo);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   191
        } else if (linkInfo.typeElement != null) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   192
            Content link = newContent();
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   193
            link.addContent(getClassLink(linkInfo));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
            if (linkInfo.includeTypeAsSepLink) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   195
                link.addContent(getTypeParameterLinks(linkInfo, false));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   197
            return link;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   203
    private void setBoundsLinkInfo(LinkInfo linkInfo, TypeMirror bound) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   204
        linkInfo.typeElement = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        linkInfo.label = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        linkInfo.type = bound;
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 link to the given class.
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
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     * @return the link for the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   216
    protected abstract Content getClassLink(LinkInfo linkInfo);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * Return the link to the given type parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     * @param linkInfo     the information about the link to construct.
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
     * @param typeParam the type parameter to link to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   224
    protected abstract Content getTypeParameterLink(LinkInfo linkInfo, TypeMirror typeParam);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   226
    protected abstract Content getTypeAnnotationLink(LinkInfo linkInfo, AnnotationMirror annotation);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   227
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * Return the links to the type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     * @param linkInfo     the information about the link to construct.
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     * @return the links to the type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   234
    public Content getTypeParameterLinks(LinkInfo linkInfo) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        return getTypeParameterLinks(linkInfo, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     * Return the links to the type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * @param linkInfo     the information about the link to construct.
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * @param isClassLabel true if this is a class label.  False if it is
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     *                     the type parameters portion of the link.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     * @return the links to the type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     */
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   246
    public Content getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   247
        Utils utils = ((LinkInfoImpl)linkInfo).utils;
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   248
        Content links = newContent();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   249
        List<TypeMirror> vars = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   250
        TypeMirror ctype = linkInfo.type != null
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   251
                ? utils.getComponentType(linkInfo.type)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   252
                : null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   253
        if (linkInfo.executableElement != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   254
            linkInfo.executableElement.getTypeParameters().stream().forEach((t) -> {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   255
                vars.add(t.asType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   256
            });
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   257
        } else if (linkInfo.type != null && utils.isDeclaredType(linkInfo.type)) {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40606
diff changeset
   258
            ((DeclaredType)linkInfo.type).getTypeArguments().stream().forEach(vars::add);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   259
        } else if (ctype != null && utils.isDeclaredType(ctype)) {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40606
diff changeset
   260
            ((DeclaredType)ctype).getTypeArguments().stream().forEach(vars::add);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   261
        } else if (linkInfo.typeElement != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   262
            linkInfo.typeElement.getTypeParameters().stream().forEach((t) -> {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   263
                vars.add(t.asType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   264
            });
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        } else {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   266
            // Nothing to document.
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   267
            return links;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   269
        if (((linkInfo.includeTypeInClassLinkLabel && isClassLabel)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   270
                || (linkInfo.includeTypeAsSepLink && !isClassLabel)) && !vars.isEmpty()) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   271
            links.addContent("<");
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   272
            boolean many = false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   273
            for (TypeMirror t : vars) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   274
                if (many) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   275
                    links.addContent(",");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
                }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   277
                links.addContent(getTypeParameterLink(linkInfo, t));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   278
                many = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   280
            links.addContent(">");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        }
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   282
        return links;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   285
    public Content getTypeAnnotationLinks(LinkInfo linkInfo) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   286
        Utils utils = ((LinkInfoImpl)linkInfo).utils;
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   287
        Content links = newContent();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   288
        if (!utils.isAnnotated(linkInfo.type))
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   289
            return links;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   290
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   291
        List<? extends AnnotationMirror> annotations = linkInfo.type.getAnnotationMirrors();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   292
        boolean needSpace = false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   293
        for (AnnotationMirror anno : annotations) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   294
            if (needSpace) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   295
                links.addContent(" ");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   296
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   297
            links.addContent(getTypeAnnotationLink(linkInfo, anno));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   298
            needSpace = true;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   299
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14260
diff changeset
   300
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   301
        links.addContent(" ");
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 16969
diff changeset
   302
        return links;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
}