author | ksrini |
Sun, 15 Jun 2014 08:41:57 -0700 | |
changeset 25454 | 376a52c9540c |
parent 22163 | 3651128c74eb |
permissions | -rw-r--r-- |
10 | 1 |
/* |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 2001, 2014, 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.taglets; |
|
27 |
||
14258 | 28 |
import java.util.*; |
29 |
||
10 | 30 |
import com.sun.javadoc.*; |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
31 |
import com.sun.tools.doclets.internal.toolkit.Content; |
10 | 32 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
33 |
||
34 |
/** |
|
35 |
* A taglet that represents the @param tag. |
|
36 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
37 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
38 |
* 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:
14259
diff
changeset
|
39 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
40 |
* deletion without notice.</b> |
10 | 41 |
* |
42 |
* @author Jamie Ho |
|
43 |
* @since 1.4 |
|
44 |
*/ |
|
45 |
public class ParamTaglet extends BaseTaglet implements InheritableTaglet { |
|
46 |
||
47 |
/** |
|
48 |
* Construct a ParamTaglet. |
|
49 |
*/ |
|
50 |
public ParamTaglet() { |
|
51 |
name = "param"; |
|
52 |
} |
|
53 |
||
54 |
/** |
|
55 |
* Given an array of <code>Parameter</code>s, return |
|
56 |
* a name/rank number map. If the array is null, then |
|
57 |
* null is returned. |
|
58 |
* @param params The array of parmeters (from type or executable member) to |
|
59 |
* check. |
|
60 |
* @return a name-rank number map. |
|
61 |
*/ |
|
868 | 62 |
private static Map<String,String> getRankMap(Object[] params){ |
10 | 63 |
if (params == null) { |
64 |
return null; |
|
65 |
} |
|
22163 | 66 |
HashMap<String,String> result = new HashMap<>(); |
10 | 67 |
for (int i = 0; i < params.length; i++) { |
68 |
String name = params[i] instanceof Parameter ? |
|
69 |
((Parameter) params[i]).name() : |
|
70 |
((TypeVariable) params[i]).typeName(); |
|
71 |
result.put(name, String.valueOf(i)); |
|
72 |
} |
|
73 |
return result; |
|
74 |
} |
|
75 |
||
76 |
/** |
|
77 |
* {@inheritDoc} |
|
78 |
*/ |
|
79 |
public void inherit(DocFinder.Input input, DocFinder.Output output) { |
|
80 |
if (input.tagId == null) { |
|
81 |
input.isTypeVariableParamTag = ((ParamTag) input.tag).isTypeParameter(); |
|
82 |
Object[] parameters = input.isTypeVariableParamTag ? |
|
83 |
(Object[]) ((MethodDoc) input.tag.holder()).typeParameters() : |
|
84 |
(Object[]) ((MethodDoc) input.tag.holder()).parameters(); |
|
85 |
String target = ((ParamTag) input.tag).parameterName(); |
|
86 |
int i; |
|
87 |
for (i = 0; i < parameters.length; i++) { |
|
88 |
String name = parameters[i] instanceof Parameter ? |
|
89 |
((Parameter) parameters[i]).name() : |
|
90 |
((TypeVariable) parameters[i]).typeName(); |
|
91 |
if (name.equals(target)) { |
|
92 |
input.tagId = String.valueOf(i); |
|
93 |
break; |
|
94 |
} |
|
95 |
} |
|
96 |
if (i == parameters.length) { |
|
97 |
//Someone used {@inheritDoc} on an invalid @param tag. |
|
98 |
//We don't know where to inherit from. |
|
99 |
//XXX: in the future when Configuration is available here, |
|
100 |
//print a warning for this mistake. |
|
101 |
return; |
|
102 |
} |
|
103 |
} |
|
104 |
ParamTag[] tags = input.isTypeVariableParamTag ? |
|
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14260
diff
changeset
|
105 |
((MethodDoc)input.element).typeParamTags() : ((MethodDoc)input.element).paramTags(); |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
106 |
Map<String, String> rankMap = getRankMap(input.isTypeVariableParamTag ? |
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14260
diff
changeset
|
107 |
(Object[]) ((MethodDoc)input.element).typeParameters() : |
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14260
diff
changeset
|
108 |
(Object[]) ((MethodDoc)input.element).parameters()); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
109 |
for (ParamTag tag : tags) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
110 |
if (rankMap.containsKey(tag.parameterName()) && |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
111 |
rankMap.get(tag.parameterName()).equals((input.tagId))) { |
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14260
diff
changeset
|
112 |
output.holder = input.element; |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
113 |
output.holderTag = tag; |
10 | 114 |
output.inlineTags = input.isFirstSentence ? |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
115 |
tag.firstSentenceTags() : tag.inlineTags(); |
10 | 116 |
return; |
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* {@inheritDoc} |
|
123 |
*/ |
|
124 |
public boolean inField() { |
|
125 |
return false; |
|
126 |
} |
|
127 |
||
128 |
/** |
|
129 |
* {@inheritDoc} |
|
130 |
*/ |
|
131 |
public boolean inMethod() { |
|
132 |
return true; |
|
133 |
} |
|
134 |
||
135 |
/** |
|
136 |
* {@inheritDoc} |
|
137 |
*/ |
|
138 |
public boolean inOverview() { |
|
139 |
return false; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* {@inheritDoc} |
|
144 |
*/ |
|
145 |
public boolean inPackage() { |
|
146 |
return false; |
|
147 |
} |
|
148 |
||
149 |
/** |
|
150 |
* {@inheritDoc} |
|
151 |
*/ |
|
152 |
public boolean inType() { |
|
153 |
return true; |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* {@inheritDoc} |
|
158 |
*/ |
|
159 |
public boolean isInlineTag() { |
|
160 |
return false; |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* Given an array of <code>ParamTag</code>s,return its string representation. |
|
165 |
* @param holder the member that holds the param tags. |
|
166 |
* @param writer the TagletWriter that will write this tag. |
|
167 |
* @return the TagletOutput representation of these <code>ParamTag</code>s. |
|
168 |
*/ |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
169 |
public Content getTagletOutput(Doc holder, TagletWriter writer) { |
10 | 170 |
if (holder instanceof ExecutableMemberDoc) { |
171 |
ExecutableMemberDoc member = (ExecutableMemberDoc) holder; |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
172 |
Content output = getTagletOutput(false, member, writer, |
10 | 173 |
member.typeParameters(), member.typeParamTags()); |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
174 |
output.addContent(getTagletOutput(true, member, writer, |
10 | 175 |
member.parameters(), member.paramTags())); |
176 |
return output; |
|
177 |
} else { |
|
178 |
ClassDoc classDoc = (ClassDoc) holder; |
|
179 |
return getTagletOutput(false, classDoc, writer, |
|
180 |
classDoc.typeParameters(), classDoc.typeParamTags()); |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
/** |
|
185 |
* Given an array of <code>ParamTag</code>s,return its string representation. |
|
186 |
* Try to inherit the param tags that are missing. |
|
187 |
* |
|
14259 | 188 |
* @param holder the doc that holds the param tags. |
10 | 189 |
* @param writer the TagletWriter that will write this tag. |
190 |
* @param formalParameters The array of parmeters (from type or executable |
|
191 |
* member) to check. |
|
192 |
* |
|
193 |
* @return the TagletOutput representation of these <code>ParamTag</code>s. |
|
194 |
*/ |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
195 |
private Content getTagletOutput(boolean isNonTypeParams, Doc holder, |
10 | 196 |
TagletWriter writer, Object[] formalParameters, ParamTag[] paramTags) { |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
197 |
Content result = writer.getOutputInstance(); |
22163 | 198 |
Set<String> alreadyDocumented = new HashSet<>(); |
10 | 199 |
if (paramTags.length > 0) { |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
200 |
result.addContent( |
10 | 201 |
processParamTags(isNonTypeParams, paramTags, |
202 |
getRankMap(formalParameters), writer, alreadyDocumented) |
|
203 |
); |
|
204 |
} |
|
205 |
if (alreadyDocumented.size() != formalParameters.length) { |
|
206 |
//Some parameters are missing corresponding @param tags. |
|
207 |
//Try to inherit them. |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
208 |
result.addContent(getInheritedTagletOutput (isNonTypeParams, holder, |
10 | 209 |
writer, formalParameters, alreadyDocumented)); |
210 |
} |
|
211 |
return result; |
|
212 |
} |
|
213 |
||
214 |
/** |
|
215 |
* Loop through each indivitual parameter. It it does not have a |
|
216 |
* corresponding param tag, try to inherit it. |
|
217 |
*/ |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
218 |
private Content getInheritedTagletOutput(boolean isNonTypeParams, Doc holder, |
10 | 219 |
TagletWriter writer, Object[] formalParameters, |
868 | 220 |
Set<String> alreadyDocumented) { |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
221 |
Content result = writer.getOutputInstance(); |
10 | 222 |
if ((! alreadyDocumented.contains(null)) && |
223 |
holder instanceof MethodDoc) { |
|
224 |
for (int i = 0; i < formalParameters.length; i++) { |
|
225 |
if (alreadyDocumented.contains(String.valueOf(i))) { |
|
226 |
continue; |
|
227 |
} |
|
228 |
//This parameter does not have any @param documentation. |
|
229 |
//Try to inherit it. |
|
230 |
DocFinder.Output inheritedDoc = |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
231 |
DocFinder.search(writer.configuration(), new DocFinder.Input((MethodDoc) holder, this, |
10 | 232 |
String.valueOf(i), ! isNonTypeParams)); |
233 |
if (inheritedDoc.inlineTags != null && |
|
234 |
inheritedDoc.inlineTags.length > 0) { |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
235 |
result.addContent( |
10 | 236 |
processParamTag(isNonTypeParams, writer, |
237 |
(ParamTag) inheritedDoc.holderTag, |
|
238 |
isNonTypeParams ? |
|
239 |
((Parameter) formalParameters[i]).name(): |
|
240 |
((TypeVariable) formalParameters[i]).typeName(), |
|
241 |
alreadyDocumented.size() == 0)); |
|
242 |
} |
|
243 |
alreadyDocumented.add(String.valueOf(i)); |
|
244 |
} |
|
245 |
} |
|
246 |
return result; |
|
247 |
} |
|
248 |
||
249 |
/** |
|
250 |
* Given an array of <code>Tag</code>s representing this custom |
|
251 |
* tag, return its string representation. Print a warning for param |
|
252 |
* tags that do not map to parameters. Print a warning for param |
|
253 |
* tags that are duplicated. |
|
254 |
* |
|
255 |
* @param paramTags the array of <code>ParamTag</code>s to convert. |
|
256 |
* @param writer the TagletWriter that will write this tag. |
|
257 |
* @param alreadyDocumented the set of exceptions that have already |
|
258 |
* been documented. |
|
259 |
* @param rankMap a {@link java.util.Map} which holds ordering |
|
260 |
* information about the parameters. |
|
14259 | 261 |
* @param rankMap a {@link java.util.Map} which holds a mapping |
10 | 262 |
* of a rank of a parameter to its name. This is |
263 |
* used to ensure that the right name is used |
|
264 |
* when parameter documentation is inherited. |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
265 |
* @return the Content representation of this <code>Tag</code>. |
10 | 266 |
*/ |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
267 |
private Content processParamTags(boolean isNonTypeParams, |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
268 |
ParamTag[] paramTags, Map<String, String> rankMap, TagletWriter writer, |
868 | 269 |
Set<String> alreadyDocumented) { |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
270 |
Content result = writer.getOutputInstance(); |
10 | 271 |
if (paramTags.length > 0) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
272 |
for (ParamTag pt : paramTags) { |
10 | 273 |
String paramName = isNonTypeParams ? |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
274 |
pt.parameterName() : "<" + pt.parameterName() + ">"; |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
275 |
if (!rankMap.containsKey(pt.parameterName())) { |
10 | 276 |
writer.getMsgRetriever().warning(pt.position(), |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
277 |
isNonTypeParams ? |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
278 |
"doclet.Parameters_warn" : |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
279 |
"doclet.Type_Parameters_warn", |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
280 |
paramName); |
10 | 281 |
} |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
282 |
String rank = rankMap.get(pt.parameterName()); |
10 | 283 |
if (rank != null && alreadyDocumented.contains(rank)) { |
284 |
writer.getMsgRetriever().warning(pt.position(), |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
285 |
isNonTypeParams ? |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
286 |
"doclet.Parameters_dup_warn" : |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
287 |
"doclet.Type_Parameters_dup_warn", |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
288 |
paramName); |
10 | 289 |
} |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
290 |
result.addContent(processParamTag(isNonTypeParams, writer, pt, |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17574
diff
changeset
|
291 |
pt.parameterName(), alreadyDocumented.size() == 0)); |
10 | 292 |
alreadyDocumented.add(rank); |
293 |
} |
|
294 |
} |
|
295 |
return result; |
|
296 |
} |
|
297 |
/** |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
298 |
* Convert the individual ParamTag into Content. |
10 | 299 |
* |
300 |
* @param isNonTypeParams true if this is just a regular param tag. False |
|
301 |
* if this is a type param tag. |
|
302 |
* @param writer the taglet writer for output writing. |
|
303 |
* @param paramTag the tag whose inline tags will be printed. |
|
304 |
* @param name the name of the parameter. We can't rely on |
|
305 |
* the name in the param tag because we might be |
|
306 |
* inheriting documentation. |
|
307 |
* @param isFirstParam true if this is the first param tag being printed. |
|
308 |
* |
|
309 |
*/ |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
310 |
private Content processParamTag(boolean isNonTypeParams, |
10 | 311 |
TagletWriter writer, ParamTag paramTag, String name, |
312 |
boolean isFirstParam) { |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
313 |
Content result = writer.getOutputInstance(); |
10 | 314 |
String header = writer.configuration().getText( |
315 |
isNonTypeParams ? "doclet.Parameters" : "doclet.TypeParameters"); |
|
316 |
if (isFirstParam) { |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
317 |
result.addContent(writer.getParamHeader(header)); |
10 | 318 |
} |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17547
diff
changeset
|
319 |
result.addContent(writer.paramTagOutput(paramTag, |
10 | 320 |
name)); |
321 |
return result; |
|
322 |
} |
|
323 |
} |