author | mcimadamore |
Fri, 16 Dec 2016 15:27:34 +0000 | |
changeset 42827 | 36468b5fa7f4 |
parent 40606 | eb2c81860c86 |
permissions | -rw-r--r-- |
10 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
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 | 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 | 45 |
|
46 |
/** |
|
47 |
* A factory that constructs links from given link information. |
|
48 |
* |
|
14260 | 49 |
* <p><b>This is NOT part of any supported API. |
50 |
* If you write code that depends on this, you do so at your own risk. |
|
51 |
* This code and its internal interfaces are subject to change or |
|
52 |
* deletion without notice.</b> |
|
53 |
* |
|
10 | 54 |
* @author Jamie Ho |
55 |
*/ |
|
56 |
public abstract class LinkFactory { |
|
57 |
||
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 | 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 | 62 |
*/ |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
63 |
protected abstract Content newContent(); |
10 | 64 |
|
65 |
/** |
|
66 |
* Constructs a link from the given link information. |
|
67 |
* |
|
68 |
* @param linkInfo the information about the link. |
|
69 |
* @return the output of the link. |
|
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 | 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 | 85 |
} |
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 | 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 | 196 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
197 |
return link; |
10 | 198 |
} else { |
199 |
return null; |
|
200 |
} |
|
201 |
} |
|
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 | 205 |
linkInfo.label = null; |
206 |
linkInfo.type = bound; |
|
207 |
} |
|
208 |
||
209 |
/** |
|
210 |
* Return the link to the given class. |
|
211 |
* |
|
212 |
* @param linkInfo the information about the link to construct. |
|
213 |
* |
|
214 |
* @return the link for the given class. |
|
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 | 217 |
|
218 |
/** |
|
219 |
* Return the link to the given type parameter. |
|
220 |
* |
|
221 |
* @param linkInfo the information about the link to construct. |
|
222 |
* @param typeParam the type parameter to link to. |
|
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 | 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 | 227 |
|
10 | 228 |
/** |
229 |
* Return the links to the type parameters. |
|
230 |
* |
|
231 |
* @param linkInfo the information about the link to construct. |
|
232 |
* @return the links to the type parameters. |
|
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 | 235 |
return getTypeParameterLinks(linkInfo, true); |
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
* Return the links to the type parameters. |
|
240 |
* |
|
241 |
* @param linkInfo the information about the link to construct. |
|
242 |
* @param isClassLabel true if this is a class label. False if it is |
|
243 |
* the type parameters portion of the link. |
|
244 |
* @return the links to the type parameters. |
|
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 | 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 | 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 | 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 | 279 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
280 |
links.addContent(">"); |
10 | 281 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
282 |
return links; |
10 | 283 |
} |
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 | 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 | 299 |
} |
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 | 303 |
} |
304 |
} |