author | jjg |
Fri, 27 May 2016 13:06:58 -0700 | |
changeset 38617 | d93a7f64e231 |
parent 25874 | 83c19f00452c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15385 | 2 |
* Copyright (c) 2003, 2013, 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 |
||
26 |
package com.sun.tools.doclets.internal.toolkit.util.links; |
|
27 |
||
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 | 30 |
|
31 |
/** |
|
32 |
* A factory that constructs links from given link information. |
|
33 |
* |
|
14260 | 34 |
* <p><b>This is NOT part of any supported API. |
35 |
* If you write code that depends on this, you do so at your own risk. |
|
36 |
* This code and its internal interfaces are subject to change or |
|
37 |
* deletion without notice.</b> |
|
38 |
* |
|
10 | 39 |
* @author Jamie Ho |
40 |
* @since 1.5 |
|
41 |
*/ |
|
38617 | 42 |
@Deprecated |
10 | 43 |
public abstract class LinkFactory { |
44 |
||
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 | 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 | 49 |
*/ |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
50 |
protected abstract Content newContent(); |
10 | 51 |
|
52 |
/** |
|
53 |
* Constructs a link from the given link information. |
|
54 |
* |
|
55 |
* @param linkInfo the information about the link. |
|
56 |
* @return the output of the link. |
|
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 | 59 |
if (linkInfo.type != null) { |
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 | 62 |
if (type.isPrimitive()) { |
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 | 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 | 70 |
} else if (type.asWildcardType() != null) { |
71 |
//Wildcard type. |
|
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 | 74 |
WildcardType wildcardType = type.asWildcardType(); |
75 |
Type[] extendsBounds = wildcardType.extendsBounds(); |
|
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 | 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 | 80 |
} |
81 |
Type[] superBounds = wildcardType.superBounds(); |
|
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 | 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 | 86 |
} |
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 | 89 |
linkInfo.isTypeBound = true; |
90 |
//A type variable. |
|
91 |
Doc owner = type.asTypeVariable().owner(); |
|
92 |
if ((! linkInfo.excludeTypeParameterLinks) && |
|
93 |
owner instanceof ClassDoc) { |
|
94 |
linkInfo.classDoc = (ClassDoc) owner; |
|
17560 | 95 |
Content label = newContent(); |
96 |
label.addContent(type.typeName()); |
|
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 | 99 |
} else { |
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 | 102 |
} |
103 |
||
104 |
Type[] bounds = type.asTypeVariable().bounds(); |
|
105 |
if (! linkInfo.excludeTypeBounds) { |
|
106 |
linkInfo.excludeTypeBounds = true; |
|
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 | 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 | 111 |
} |
112 |
} |
|
113 |
} else if (type.asClassDoc() != null) { |
|
114 |
//A class type. |
|
115 |
if (linkInfo.isTypeBound && |
|
116 |
linkInfo.excludeTypeBoundsLinks) { |
|
117 |
//Since we are excluding type parameter links, we should not |
|
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 | 122 |
} else { |
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 | 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 | 128 |
} |
129 |
} |
|
130 |
} |
|
131 |
||
132 |
if (linkInfo.isVarArg) { |
|
133 |
if (type.dimension().length() > 2) { |
|
134 |
//Javadoc returns var args as array. |
|
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 | 137 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
138 |
link.addContent("..."); |
10 | 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 | 157 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
158 |
return link; |
10 | 159 |
} else if (linkInfo.classDoc != null) { |
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 | 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 | 165 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
166 |
return link; |
10 | 167 |
} else { |
168 |
return null; |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
private void setBoundsLinkInfo(LinkInfo linkInfo, Type bound) { |
|
173 |
linkInfo.classDoc = null; |
|
174 |
linkInfo.label = null; |
|
175 |
linkInfo.type = bound; |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Return the link to the given class. |
|
180 |
* |
|
181 |
* @param linkInfo the information about the link to construct. |
|
182 |
* |
|
183 |
* @return the link for the given class. |
|
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 | 186 |
|
187 |
/** |
|
188 |
* Return the link to the given type parameter. |
|
189 |
* |
|
190 |
* @param linkInfo the information about the link to construct. |
|
191 |
* @param typeParam the type parameter to link to. |
|
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 | 194 |
Type typeParam); |
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 | 197 |
AnnotationDesc annotation); |
198 |
||
10 | 199 |
/** |
200 |
* Return the links to the type parameters. |
|
201 |
* |
|
202 |
* @param linkInfo the information about the link to construct. |
|
203 |
* @return the links to the type parameters. |
|
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 | 206 |
return getTypeParameterLinks(linkInfo, true); |
207 |
} |
|
208 |
||
209 |
/** |
|
210 |
* Return the links to the type parameters. |
|
211 |
* |
|
212 |
* @param linkInfo the information about the link to construct. |
|
213 |
* @param isClassLabel true if this is a class label. False if it is |
|
214 |
* the type parameters portion of the link. |
|
215 |
* @return the links to the type parameters. |
|
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 | 219 |
Type[] vars; |
220 |
if (linkInfo.executableMemberDoc != null) { |
|
221 |
vars = linkInfo.executableMemberDoc.typeParameters(); |
|
222 |
} else if (linkInfo.type != null && |
|
223 |
linkInfo.type.asParameterizedType() != null){ |
|
224 |
vars = linkInfo.type.asParameterizedType().typeArguments(); |
|
225 |
} else if (linkInfo.classDoc != null){ |
|
226 |
vars = linkInfo.classDoc.typeParameters(); |
|
227 |
} else { |
|
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 | 230 |
} |
231 |
if (((linkInfo.includeTypeInClassLinkLabel && isClassLabel) || |
|
232 |
(linkInfo.includeTypeAsSepLink && ! isClassLabel) |
|
233 |
) |
|
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 | 236 |
for (int i = 0; i < vars.length; i++) { |
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 | 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 | 241 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
242 |
links.addContent(">"); |
10 | 243 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
16969
diff
changeset
|
244 |
return links; |
10 | 245 |
} |
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 | 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 | 251 |
AnnotationDesc[] annotations = linkInfo.type.asAnnotatedType().annotations(); |
252 |
for (int i = 0; i < annotations.length; i++) { |
|
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 | 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 | 257 |
} |
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 | 261 |
} |
262 |
} |