author | jjg |
Tue, 25 Sep 2012 13:06:58 -0700 | |
changeset 14049 | 3207422a0f9b |
parent 13842 | 6908f6badce4 |
child 14258 | 8d2148961366 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
13842
6908f6badce4
7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents:
5520
diff
changeset
|
2 |
* Copyright (c) 2001, 2012, 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 |
||
28 |
import com.sun.javadoc.*; |
|
29 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
|
30 |
||
31 |
import java.io.*; |
|
32 |
import java.lang.reflect.*; |
|
33 |
import java.net.*; |
|
34 |
import java.util.*; |
|
35 |
||
36 |
/** |
|
37 |
* Manages the<code>Taglet</code>s used by doclets. |
|
38 |
* |
|
39 |
* This code is not part of an API. |
|
40 |
* It is implementation that is subject to change. |
|
41 |
* Do not use it as an API |
|
42 |
* |
|
43 |
* @author Jamie Ho |
|
44 |
* @since 1.4 |
|
45 |
*/ |
|
46 |
||
47 |
public class TagletManager { |
|
48 |
||
49 |
/** |
|
50 |
* The default seperator for the simple tag option. |
|
51 |
*/ |
|
52 |
public static final char SIMPLE_TAGLET_OPT_SEPERATOR = ':'; |
|
53 |
||
54 |
/** |
|
55 |
* The alternate seperator for simple tag options. Use this |
|
56 |
* with you want the default seperator to be in the name of the |
|
57 |
* custom tag. |
|
58 |
*/ |
|
59 |
public static final String ALT_SIMPLE_TAGLET_OPT_SEPERATOR = "-"; |
|
60 |
||
61 |
/** |
|
62 |
* The map of custom tags. |
|
63 |
*/ |
|
868 | 64 |
private LinkedHashMap<String,Taglet> customTags; |
10 | 65 |
|
66 |
/** |
|
67 |
* The array of custom tags that can appear in packages. |
|
68 |
*/ |
|
69 |
private Taglet[] packageTags; |
|
70 |
||
71 |
/** |
|
72 |
* The array of custom tags that can appear in classes or interfaces. |
|
73 |
*/ |
|
74 |
private Taglet[] typeTags; |
|
75 |
||
76 |
/** |
|
77 |
* The array of custom tags that can appear in fields. |
|
78 |
*/ |
|
79 |
private Taglet[] fieldTags; |
|
80 |
||
81 |
/** |
|
82 |
* The array of custom tags that can appear in constructors. |
|
83 |
*/ |
|
84 |
private Taglet[] constructorTags; |
|
85 |
||
86 |
/** |
|
87 |
* The array of custom tags that can appear in methods. |
|
88 |
*/ |
|
89 |
private Taglet[] methodTags; |
|
90 |
||
91 |
/** |
|
92 |
* The array of custom tags that can appear in the overview. |
|
93 |
*/ |
|
94 |
private Taglet[] overviewTags; |
|
95 |
||
96 |
/** |
|
97 |
* The array of custom tags that can appear in comments. |
|
98 |
*/ |
|
99 |
private Taglet[] inlineTags; |
|
100 |
||
101 |
/** |
|
102 |
* The array of custom tags that can appear in the serialized form. |
|
103 |
*/ |
|
104 |
private Taglet[] serializedFormTags; |
|
105 |
||
106 |
/** |
|
107 |
* The message retriever that will be used to print error messages. |
|
108 |
*/ |
|
109 |
private MessageRetriever message; |
|
110 |
||
111 |
/** |
|
112 |
* Keep track of standard tags. |
|
113 |
*/ |
|
868 | 114 |
private Set<String> standardTags; |
10 | 115 |
|
116 |
/** |
|
117 |
* Keep track of standard tags in lowercase to compare for better |
|
118 |
* error messages when a tag like @docRoot is mistakenly spelled |
|
119 |
* lowercase @docroot. |
|
120 |
*/ |
|
868 | 121 |
private Set<String> standardTagsLowercase; |
10 | 122 |
|
123 |
/** |
|
124 |
* Keep track of overriden standard tags. |
|
125 |
*/ |
|
868 | 126 |
private Set<String> overridenStandardTags; |
10 | 127 |
|
128 |
/** |
|
129 |
* Keep track of the tags that may conflict |
|
130 |
* with standard tags in the future (any custom tag without |
|
131 |
* a period in its name). |
|
132 |
*/ |
|
868 | 133 |
private Set<String> potentiallyConflictingTags; |
10 | 134 |
|
135 |
/** |
|
136 |
* The set of unseen custom tags. |
|
137 |
*/ |
|
868 | 138 |
private Set<String> unseenCustomTags; |
10 | 139 |
|
140 |
/** |
|
141 |
* True if we do not want to use @since tags. |
|
142 |
*/ |
|
143 |
private boolean nosince; |
|
144 |
||
145 |
/** |
|
146 |
* True if we want to use @version tags. |
|
147 |
*/ |
|
148 |
private boolean showversion; |
|
149 |
||
150 |
/** |
|
151 |
* True if we want to use @author tags. |
|
152 |
*/ |
|
153 |
private boolean showauthor; |
|
154 |
||
155 |
/** |
|
156 |
* Construct a new <code>TagletManager</code>. |
|
157 |
* @param nosince true if we do not want to use @since tags. |
|
158 |
* @param showversion true if we want to use @version tags. |
|
159 |
* @param showauthor true if we want to use @author tags. |
|
160 |
* @param message the message retriever to print warnings. |
|
161 |
*/ |
|
162 |
public TagletManager(boolean nosince, boolean showversion, |
|
163 |
boolean showauthor, MessageRetriever message){ |
|
868 | 164 |
overridenStandardTags = new HashSet<String>(); |
165 |
potentiallyConflictingTags = new HashSet<String>(); |
|
166 |
standardTags = new HashSet<String>(); |
|
167 |
standardTagsLowercase = new HashSet<String>(); |
|
168 |
unseenCustomTags = new HashSet<String>(); |
|
169 |
customTags = new LinkedHashMap<String,Taglet>(); |
|
10 | 170 |
this.nosince = nosince; |
171 |
this.showversion = showversion; |
|
172 |
this.showauthor = showauthor; |
|
173 |
this.message = message; |
|
174 |
initStandardTags(); |
|
175 |
initStandardTagsLowercase(); |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Add a new <code>CustomTag</code>. This is used to add a Taglet from within |
|
180 |
* a Doclet. No message is printed to indicate that the Taglet is properly |
|
181 |
* registered because these Taglets are typically added for every execution of the |
|
182 |
* Doclet. We don't want to see this type of error message every time. |
|
183 |
* @param customTag the new <code>CustomTag</code> to add. |
|
184 |
*/ |
|
185 |
public void addCustomTag(Taglet customTag) { |
|
186 |
if (customTag != null) { |
|
187 |
String name = customTag.getName(); |
|
188 |
if (customTags.containsKey(name)) { |
|
189 |
customTags.remove(name); |
|
190 |
} |
|
191 |
customTags.put(name, customTag); |
|
192 |
checkTagName(name); |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
/** |
|
197 |
* Add a new <code>Taglet</code>. Print a message to indicate whether or not |
|
198 |
* the Taglet was registered properly. |
|
199 |
* @param classname the name of the class representing the custom tag. |
|
200 |
* @param tagletPath the path to the class representing the custom tag. |
|
201 |
*/ |
|
202 |
public void addCustomTag(String classname, String tagletPath) { |
|
203 |
try { |
|
868 | 204 |
Class<?> customTagClass = null; |
10 | 205 |
// construct class loader |
206 |
String cpString = null; // make sure env.class.path defaults to dot |
|
207 |
||
208 |
// do prepends to get correct ordering |
|
209 |
cpString = appendPath(System.getProperty("env.class.path"), cpString); |
|
210 |
cpString = appendPath(System.getProperty("java.class.path"), cpString); |
|
211 |
cpString = appendPath(tagletPath, cpString); |
|
212 |
URLClassLoader appClassLoader = new URLClassLoader(pathToURLs(cpString)); |
|
213 |
customTagClass = appClassLoader.loadClass(classname); |
|
214 |
Method meth = customTagClass.getMethod("register", |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
215 |
new Class<?>[] {java.util.Map.class}); |
10 | 216 |
Object[] list = customTags.values().toArray(); |
217 |
Taglet lastTag = (list != null && list.length > 0) |
|
218 |
? (Taglet) list[list.length-1] : null; |
|
219 |
meth.invoke(null, new Object[] {customTags}); |
|
220 |
list = customTags.values().toArray(); |
|
221 |
Object newLastTag = (list != null&& list.length > 0) |
|
868 | 222 |
? list[list.length-1] : null; |
10 | 223 |
if (lastTag != newLastTag) { |
224 |
//New taglets must always be added to the end of the LinkedHashMap. |
|
225 |
//If the current and previous last taglet are not equal, that |
|
226 |
//means a new Taglet has been added. |
|
227 |
message.notice("doclet.Notice_taglet_registered", classname); |
|
228 |
if (newLastTag != null) { |
|
229 |
checkTaglet(newLastTag); |
|
230 |
} |
|
231 |
} |
|
232 |
} catch (Exception exc) { |
|
233 |
message.error("doclet.Error_taglet_not_registered", exc.getClass().getName(), classname); |
|
234 |
} |
|
235 |
||
236 |
} |
|
237 |
||
238 |
private String appendPath(String path1, String path2) { |
|
239 |
if (path1 == null || path1.length() == 0) { |
|
240 |
return path2 == null ? "." : path2; |
|
241 |
} else if (path2 == null || path2.length() == 0) { |
|
242 |
return path1; |
|
243 |
} else { |
|
244 |
return path1 + File.pathSeparator + path2; |
|
245 |
} |
|
246 |
} |
|
247 |
||
248 |
/** |
|
249 |
* Utility method for converting a search path string to an array |
|
250 |
* of directory and JAR file URLs. |
|
251 |
* |
|
252 |
* @param path the search path string |
|
253 |
* @return the resulting array of directory and JAR file URLs |
|
254 |
*/ |
|
255 |
private static URL[] pathToURLs(String path) { |
|
256 |
StringTokenizer st = new StringTokenizer(path, File.pathSeparator); |
|
257 |
URL[] urls = new URL[st.countTokens()]; |
|
258 |
int count = 0; |
|
259 |
while (st.hasMoreTokens()) { |
|
260 |
URL url = fileToURL(new File(st.nextToken())); |
|
261 |
if (url != null) { |
|
262 |
urls[count++] = url; |
|
263 |
} |
|
264 |
} |
|
14049
3207422a0f9b
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents:
13842
diff
changeset
|
265 |
urls = Arrays.copyOf(urls, count); |
10 | 266 |
return urls; |
267 |
} |
|
268 |
||
269 |
/** |
|
270 |
* Returns the directory or JAR file URL corresponding to the specified |
|
271 |
* local file name. |
|
272 |
* |
|
273 |
* @param file the File object |
|
274 |
* @return the resulting directory or JAR file URL, or null if unknown |
|
275 |
*/ |
|
276 |
private static URL fileToURL(File file) { |
|
277 |
String name; |
|
278 |
try { |
|
279 |
name = file.getCanonicalPath(); |
|
280 |
} catch (IOException e) { |
|
281 |
name = file.getAbsolutePath(); |
|
282 |
} |
|
283 |
name = name.replace(File.separatorChar, '/'); |
|
284 |
if (!name.startsWith("/")) { |
|
285 |
name = "/" + name; |
|
286 |
} |
|
287 |
// If the file does not exist, then assume that it's a directory |
|
288 |
if (!file.isFile()) { |
|
289 |
name = name + "/"; |
|
290 |
} |
|
291 |
try { |
|
292 |
return new URL("file", "", name); |
|
293 |
} catch (MalformedURLException e) { |
|
294 |
throw new IllegalArgumentException("file"); |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
||
299 |
/** |
|
300 |
* Add a new <code>SimpleTaglet</code>. If this tag already exists |
|
301 |
* and the header passed as an argument is null, move tag to the back of the |
|
302 |
* list. If this tag already exists and the header passed as an argument is |
|
303 |
* not null, overwrite previous tag with new one. Otherwise, add new |
|
304 |
* SimpleTaglet to list. |
|
305 |
* @param tagName the name of this tag |
|
306 |
* @param header the header to output. |
|
307 |
* @param locations the possible locations that this tag |
|
308 |
* can appear in. |
|
309 |
*/ |
|
310 |
public void addNewSimpleCustomTag(String tagName, String header, String locations) { |
|
311 |
if (tagName == null || locations == null) { |
|
312 |
return; |
|
313 |
} |
|
868 | 314 |
Taglet tag = customTags.get(tagName); |
10 | 315 |
locations = locations.toLowerCase(); |
316 |
if (tag == null || header != null) { |
|
317 |
customTags.remove(tagName); |
|
318 |
customTags.put(tagName, new SimpleTaglet(tagName, header, locations)); |
|
319 |
if (locations != null && locations.indexOf('x') == -1) { |
|
320 |
checkTagName(tagName); |
|
321 |
} |
|
322 |
} else { |
|
323 |
//Move to back |
|
324 |
customTags.remove(tagName); |
|
325 |
customTags.put(tagName, tag); |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
/** |
|
330 |
* Given a tag name, add it to the set of tags it belongs to. |
|
331 |
*/ |
|
332 |
private void checkTagName(String name) { |
|
333 |
if (standardTags.contains(name)) { |
|
334 |
overridenStandardTags.add(name); |
|
335 |
} else { |
|
336 |
if (name.indexOf('.') == -1) { |
|
337 |
potentiallyConflictingTags.add(name); |
|
338 |
} |
|
339 |
unseenCustomTags.add(name); |
|
340 |
} |
|
341 |
} |
|
342 |
||
343 |
/** |
|
344 |
* Check the taglet to see if it is a legacy taglet. Also |
|
345 |
* check its name for errors. |
|
346 |
*/ |
|
347 |
private void checkTaglet(Object taglet) { |
|
348 |
if (taglet instanceof Taglet) { |
|
349 |
checkTagName(((Taglet) taglet).getName()); |
|
350 |
} else if (taglet instanceof com.sun.tools.doclets.Taglet) { |
|
351 |
com.sun.tools.doclets.Taglet legacyTaglet = (com.sun.tools.doclets.Taglet) taglet; |
|
352 |
customTags.remove(legacyTaglet.getName()); |
|
353 |
customTags.put(legacyTaglet.getName(), new LegacyTaglet(legacyTaglet)); |
|
354 |
checkTagName(legacyTaglet.getName()); |
|
355 |
} else { |
|
356 |
throw new IllegalArgumentException("Given object is not a taglet."); |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
/** |
|
361 |
* Given a name of a seen custom tag, remove it from the set of unseen |
|
362 |
* custom tags. |
|
363 |
* @param name the name of the seen custom tag. |
|
364 |
*/ |
|
365 |
public void seenCustomTag(String name) { |
|
366 |
unseenCustomTags.remove(name); |
|
367 |
} |
|
368 |
||
369 |
/** |
|
370 |
* Given an array of <code>Tag</code>s, check for spelling mistakes. |
|
371 |
* @param doc the Doc object that holds the tags. |
|
372 |
* @param tags the list of <code>Tag</code>s to check. |
|
373 |
* @param areInlineTags true if the array of tags are inline and false otherwise. |
|
374 |
*/ |
|
375 |
public void checkTags(Doc doc, Tag[] tags, boolean areInlineTags) { |
|
376 |
if (tags == null) { |
|
377 |
return; |
|
378 |
} |
|
379 |
Taglet taglet; |
|
380 |
for (int i = 0; i < tags.length; i++) { |
|
381 |
String name = tags[i].name(); |
|
382 |
if (name.length() > 0 && name.charAt(0) == '@') { |
|
383 |
name = name.substring(1, name.length()); |
|
384 |
} |
|
385 |
if (! (standardTags.contains(name) || customTags.containsKey(name))) { |
|
386 |
if (standardTagsLowercase.contains(name.toLowerCase())) { |
|
387 |
message.warning(tags[i].position(), "doclet.UnknownTagLowercase", tags[i].name()); |
|
388 |
continue; |
|
389 |
} else { |
|
390 |
message.warning(tags[i].position(), "doclet.UnknownTag", tags[i].name()); |
|
391 |
continue; |
|
392 |
} |
|
393 |
} |
|
394 |
//Check if this tag is being used in the wrong location. |
|
868 | 395 |
if ((taglet = customTags.get(name)) != null) { |
10 | 396 |
if (areInlineTags && ! taglet.isInlineTag()) { |
397 |
printTagMisuseWarn(taglet, tags[i], "inline"); |
|
398 |
} |
|
399 |
if ((doc instanceof RootDoc) && ! taglet.inOverview()) { |
|
400 |
printTagMisuseWarn(taglet, tags[i], "overview"); |
|
401 |
} else if ((doc instanceof PackageDoc) && ! taglet.inPackage()) { |
|
402 |
printTagMisuseWarn(taglet, tags[i], "package"); |
|
403 |
} else if ((doc instanceof ClassDoc) && ! taglet.inType()) { |
|
404 |
printTagMisuseWarn(taglet, tags[i], "class"); |
|
405 |
} else if ((doc instanceof ConstructorDoc) && ! taglet.inConstructor()) { |
|
406 |
printTagMisuseWarn(taglet, tags[i], "constructor"); |
|
407 |
} else if ((doc instanceof FieldDoc) && ! taglet.inField()) { |
|
408 |
printTagMisuseWarn(taglet, tags[i], "field"); |
|
409 |
} else if ((doc instanceof MethodDoc) && ! taglet.inMethod()) { |
|
410 |
printTagMisuseWarn(taglet, tags[i], "method"); |
|
411 |
} |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
415 |
||
416 |
/** |
|
417 |
* Given the taglet, the tag and the type of documentation that the tag |
|
418 |
* was found in, print a tag misuse warning. |
|
419 |
* @param taglet the taglet representing the misused tag. |
|
420 |
* @param tag the misused tag. |
|
421 |
* @param holderType the type of documentation that the misused tag was found in. |
|
422 |
*/ |
|
423 |
private void printTagMisuseWarn(Taglet taglet, Tag tag, String holderType) { |
|
868 | 424 |
Set<String> locationsSet = new LinkedHashSet<String>(); |
10 | 425 |
if (taglet.inOverview()) { |
426 |
locationsSet.add("overview"); |
|
427 |
} |
|
428 |
if (taglet.inPackage()) { |
|
429 |
locationsSet.add("package"); |
|
430 |
} |
|
431 |
if (taglet.inType()) { |
|
432 |
locationsSet.add("class/interface"); |
|
433 |
} |
|
434 |
if (taglet.inConstructor()) { |
|
435 |
locationsSet.add("constructor"); |
|
436 |
} |
|
437 |
if (taglet.inField()) { |
|
438 |
locationsSet.add("field"); |
|
439 |
} |
|
440 |
if (taglet.inMethod()) { |
|
441 |
locationsSet.add("method"); |
|
442 |
} |
|
443 |
if (taglet.isInlineTag()) { |
|
444 |
locationsSet.add("inline text"); |
|
445 |
} |
|
868 | 446 |
String[] locations = locationsSet.toArray(new String[]{}); |
10 | 447 |
if (locations == null || locations.length == 0) { |
448 |
//This known tag is excluded. |
|
449 |
return; |
|
450 |
} |
|
451 |
StringBuffer combined_locations = new StringBuffer(); |
|
452 |
for (int i = 0; i < locations.length; i++) { |
|
453 |
if (i > 0) { |
|
454 |
combined_locations.append(", "); |
|
455 |
} |
|
456 |
combined_locations.append(locations[i]); |
|
457 |
} |
|
458 |
message.warning(tag.position(), "doclet.tag_misuse", |
|
459 |
"@" + taglet.getName(), holderType, combined_locations.toString()); |
|
460 |
} |
|
461 |
||
462 |
/** |
|
463 |
* Return the array of <code>Taglet</code>s that can |
|
464 |
* appear in packages. |
|
465 |
* @return the array of <code>Taglet</code>s that can |
|
466 |
* appear in packages. |
|
467 |
*/ |
|
468 |
public Taglet[] getPackageCustomTags() { |
|
469 |
if (packageTags == null) { |
|
470 |
initCustomTagArrays(); |
|
471 |
} |
|
472 |
return packageTags; |
|
473 |
} |
|
474 |
||
475 |
/** |
|
476 |
* Return the array of <code>Taglet</code>s that can |
|
477 |
* appear in classes or interfaces. |
|
478 |
* @return the array of <code>Taglet</code>s that can |
|
479 |
* appear in classes or interfaces. |
|
480 |
*/ |
|
481 |
public Taglet[] getTypeCustomTags() { |
|
482 |
if (typeTags == null) { |
|
483 |
initCustomTagArrays(); |
|
484 |
} |
|
485 |
return typeTags; |
|
486 |
} |
|
487 |
||
488 |
/** |
|
489 |
* Return the array of inline <code>Taglet</code>s that can |
|
490 |
* appear in comments. |
|
491 |
* @return the array of <code>Taglet</code>s that can |
|
492 |
* appear in comments. |
|
493 |
*/ |
|
494 |
public Taglet[] getInlineCustomTags() { |
|
495 |
if (inlineTags == null) { |
|
496 |
initCustomTagArrays(); |
|
497 |
} |
|
498 |
return inlineTags; |
|
499 |
} |
|
500 |
||
501 |
/** |
|
502 |
* Return the array of <code>Taglet</code>s that can |
|
503 |
* appear in fields. |
|
504 |
* @return the array of <code>Taglet</code>s that can |
|
505 |
* appear in field. |
|
506 |
*/ |
|
507 |
public Taglet[] getFieldCustomTags() { |
|
508 |
if (fieldTags == null) { |
|
509 |
initCustomTagArrays(); |
|
510 |
} |
|
511 |
return fieldTags; |
|
512 |
} |
|
513 |
||
514 |
/** |
|
515 |
* Return the array of <code>Taglet</code>s that can |
|
516 |
* appear in the serialized form. |
|
517 |
* @return the array of <code>Taglet</code>s that can |
|
518 |
* appear in the serialized form. |
|
519 |
*/ |
|
520 |
public Taglet[] getSerializedFormTags() { |
|
521 |
if (serializedFormTags == null) { |
|
522 |
initCustomTagArrays(); |
|
523 |
} |
|
524 |
return serializedFormTags; |
|
525 |
} |
|
526 |
||
527 |
/** |
|
528 |
* @return the array of <code>Taglet</code>s that can |
|
529 |
* appear in the given Doc. |
|
530 |
*/ |
|
531 |
public Taglet[] getCustomTags(Doc doc) { |
|
532 |
if (doc instanceof ConstructorDoc) { |
|
533 |
return getConstructorCustomTags(); |
|
534 |
} else if (doc instanceof MethodDoc) { |
|
535 |
return getMethodCustomTags(); |
|
536 |
} else if (doc instanceof FieldDoc) { |
|
537 |
return getFieldCustomTags(); |
|
538 |
} else if (doc instanceof ClassDoc) { |
|
539 |
return getTypeCustomTags(); |
|
540 |
} else if (doc instanceof PackageDoc) { |
|
541 |
return getPackageCustomTags(); |
|
542 |
} else if (doc instanceof RootDoc) { |
|
543 |
return getOverviewCustomTags(); |
|
544 |
} |
|
545 |
return null; |
|
546 |
} |
|
547 |
||
548 |
/** |
|
549 |
* Return the array of <code>Taglet</code>s that can |
|
550 |
* appear in constructors. |
|
551 |
* @return the array of <code>Taglet</code>s that can |
|
552 |
* appear in constructors. |
|
553 |
*/ |
|
554 |
public Taglet[] getConstructorCustomTags() { |
|
555 |
if (constructorTags == null) { |
|
556 |
initCustomTagArrays(); |
|
557 |
} |
|
558 |
return constructorTags; |
|
559 |
} |
|
560 |
||
561 |
/** |
|
562 |
* Return the array of <code>Taglet</code>s that can |
|
563 |
* appear in methods. |
|
564 |
* @return the array of <code>Taglet</code>s that can |
|
565 |
* appear in methods. |
|
566 |
*/ |
|
567 |
public Taglet[] getMethodCustomTags() { |
|
568 |
if (methodTags == null) { |
|
569 |
initCustomTagArrays(); |
|
570 |
} |
|
571 |
return methodTags; |
|
572 |
} |
|
573 |
||
574 |
/** |
|
575 |
* Return the array of <code>Taglet</code>s that can |
|
576 |
* appear in an overview. |
|
577 |
* @return the array of <code>Taglet</code>s that can |
|
578 |
* appear in overview. |
|
579 |
*/ |
|
580 |
public Taglet[] getOverviewCustomTags() { |
|
581 |
if (overviewTags == null) { |
|
582 |
initCustomTagArrays(); |
|
583 |
} |
|
584 |
return overviewTags; |
|
585 |
} |
|
586 |
||
587 |
/** |
|
588 |
* Initialize the custom tag arrays. |
|
589 |
*/ |
|
590 |
private void initCustomTagArrays() { |
|
868 | 591 |
Iterator<Taglet> it = customTags.values().iterator(); |
592 |
ArrayList<Taglet> pTags = new ArrayList<Taglet>(customTags.size()); |
|
593 |
ArrayList<Taglet> tTags = new ArrayList<Taglet>(customTags.size()); |
|
594 |
ArrayList<Taglet> fTags = new ArrayList<Taglet>(customTags.size()); |
|
595 |
ArrayList<Taglet> cTags = new ArrayList<Taglet>(customTags.size()); |
|
596 |
ArrayList<Taglet> mTags = new ArrayList<Taglet>(customTags.size()); |
|
597 |
ArrayList<Taglet> iTags = new ArrayList<Taglet>(customTags.size()); |
|
598 |
ArrayList<Taglet> oTags = new ArrayList<Taglet>(customTags.size()); |
|
13842
6908f6badce4
7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents:
5520
diff
changeset
|
599 |
ArrayList<Taglet> sTags = new ArrayList<Taglet>(); |
10 | 600 |
Taglet current; |
601 |
while (it.hasNext()) { |
|
868 | 602 |
current = it.next(); |
10 | 603 |
if (current.inPackage() && !current.isInlineTag()) { |
604 |
pTags.add(current); |
|
605 |
} |
|
606 |
if (current.inType() && !current.isInlineTag()) { |
|
607 |
tTags.add(current); |
|
608 |
} |
|
609 |
if (current.inField() && !current.isInlineTag()) { |
|
610 |
fTags.add(current); |
|
611 |
} |
|
612 |
if (current.inConstructor() && !current.isInlineTag()) { |
|
613 |
cTags.add(current); |
|
614 |
} |
|
615 |
if (current.inMethod() && !current.isInlineTag()) { |
|
616 |
mTags.add(current); |
|
617 |
} |
|
618 |
if (current.isInlineTag()) { |
|
619 |
iTags.add(current); |
|
620 |
} |
|
621 |
if (current.inOverview() && !current.isInlineTag()) { |
|
622 |
oTags.add(current); |
|
623 |
} |
|
624 |
} |
|
868 | 625 |
packageTags = pTags.toArray(new Taglet[] {}); |
626 |
typeTags = tTags.toArray(new Taglet[] {}); |
|
627 |
fieldTags = fTags.toArray(new Taglet[] {}); |
|
628 |
constructorTags = cTags.toArray(new Taglet[] {}); |
|
629 |
methodTags = mTags.toArray(new Taglet[] {}); |
|
630 |
overviewTags = oTags.toArray(new Taglet[] {}); |
|
631 |
inlineTags = iTags.toArray(new Taglet[] {}); |
|
10 | 632 |
|
633 |
//Init the serialized form tags |
|
13842
6908f6badce4
7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents:
5520
diff
changeset
|
634 |
sTags.add(customTags.get("serialData")); |
6908f6badce4
7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents:
5520
diff
changeset
|
635 |
sTags.add(customTags.get("throws")); |
6908f6badce4
7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents:
5520
diff
changeset
|
636 |
if (!nosince) |
6908f6badce4
7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents:
5520
diff
changeset
|
637 |
sTags.add(customTags.get("since")); |
6908f6badce4
7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents:
5520
diff
changeset
|
638 |
sTags.add(customTags.get("see")); |
6908f6badce4
7180906: Javadoc tool does not apply parameter -nosince
bpatel
parents:
5520
diff
changeset
|
639 |
serializedFormTags = sTags.toArray(new Taglet[] {}); |
10 | 640 |
} |
641 |
||
642 |
/** |
|
643 |
* Initialize standard Javadoc tags for ordering purposes. |
|
644 |
*/ |
|
645 |
private void initStandardTags() { |
|
646 |
Taglet temp; |
|
647 |
customTags.put((temp = new ParamTaglet()).getName(), temp); |
|
648 |
customTags.put((temp = new ReturnTaglet()).getName(), temp); |
|
649 |
customTags.put((temp = new ThrowsTaglet()).getName(), temp); |
|
650 |
customTags.put((temp = new SimpleTaglet("exception", |
|
651 |
null, SimpleTaglet.METHOD + SimpleTaglet.CONSTRUCTOR)).getName(), temp); |
|
652 |
if (!nosince) { |
|
653 |
customTags.put((temp = new SimpleTaglet("since", message.getText("doclet.Since"), |
|
654 |
SimpleTaglet.ALL)).getName(), temp); |
|
655 |
} |
|
656 |
if (showversion) { |
|
657 |
customTags.put((temp = new SimpleTaglet("version", message.getText("doclet.Version"), |
|
658 |
SimpleTaglet.PACKAGE + SimpleTaglet.TYPE + SimpleTaglet.OVERVIEW)).getName(), temp); |
|
659 |
} |
|
660 |
if (showauthor) { |
|
661 |
customTags.put((temp = new SimpleTaglet("author", message.getText("doclet.Author"), |
|
662 |
SimpleTaglet.PACKAGE + SimpleTaglet.TYPE + SimpleTaglet.OVERVIEW)).getName(), temp); |
|
663 |
} |
|
664 |
customTags.put((temp = new SimpleTaglet("serialData", message.getText("doclet.SerialData"), |
|
665 |
SimpleTaglet.EXCLUDED)).getName(), temp); |
|
666 |
customTags.put((temp = new SimpleTaglet("factory", message.getText("doclet.Factory"), |
|
667 |
SimpleTaglet.METHOD)).getName(), temp); |
|
668 |
customTags.put((temp = new SeeTaglet()).getName(), temp); |
|
669 |
//Standard inline tags |
|
670 |
customTags.put((temp = new DocRootTaglet()).getName(), temp); |
|
671 |
customTags.put((temp = new InheritDocTaglet()).getName(), temp); |
|
672 |
customTags.put((temp = new ValueTaglet()).getName(), temp); |
|
673 |
customTags.put((temp = new LegacyTaglet(new LiteralTaglet())).getName(), |
|
674 |
temp); |
|
675 |
customTags.put((temp = new LegacyTaglet(new CodeTaglet())).getName(), |
|
676 |
temp); |
|
677 |
||
678 |
//Keep track of the names of standard tags for error |
|
679 |
//checking purposes. |
|
680 |
standardTags.add("param"); |
|
681 |
standardTags.add("return"); |
|
682 |
standardTags.add("throws"); |
|
683 |
standardTags.add("exception"); |
|
684 |
standardTags.add("since"); |
|
685 |
standardTags.add("version"); |
|
686 |
standardTags.add("author"); |
|
687 |
standardTags.add("see"); |
|
688 |
standardTags.add("deprecated"); |
|
689 |
standardTags.add("link"); |
|
690 |
standardTags.add("linkplain"); |
|
691 |
standardTags.add("inheritDoc"); |
|
692 |
standardTags.add("docRoot"); |
|
693 |
standardTags.add("value"); |
|
694 |
standardTags.add("serial"); |
|
695 |
standardTags.add("serialData"); |
|
696 |
standardTags.add("serialField"); |
|
697 |
standardTags.add("Text"); |
|
698 |
standardTags.add("literal"); |
|
699 |
standardTags.add("code"); |
|
700 |
} |
|
701 |
||
702 |
/** |
|
703 |
* Initialize lowercase version of standard Javadoc tags. |
|
704 |
*/ |
|
705 |
private void initStandardTagsLowercase() { |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
706 |
Iterator<String> it = standardTags.iterator(); |
10 | 707 |
while (it.hasNext()) { |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
708 |
standardTagsLowercase.add(it.next().toLowerCase()); |
10 | 709 |
} |
710 |
} |
|
711 |
||
712 |
public boolean isKnownCustomTag(String tagName) { |
|
713 |
return customTags.containsKey(tagName); |
|
714 |
} |
|
715 |
||
716 |
/** |
|
717 |
* Print a list of {@link Taglet}s that might conflict with |
|
718 |
* standard tags in the future and a list of standard tags |
|
719 |
* that have been overriden. |
|
720 |
*/ |
|
721 |
public void printReport() { |
|
722 |
printReportHelper("doclet.Notice_taglet_conflict_warn", potentiallyConflictingTags); |
|
723 |
printReportHelper("doclet.Notice_taglet_overriden", overridenStandardTags); |
|
724 |
printReportHelper("doclet.Notice_taglet_unseen", unseenCustomTags); |
|
725 |
} |
|
726 |
||
868 | 727 |
private void printReportHelper(String noticeKey, Set<String> names) { |
10 | 728 |
if (names.size() > 0) { |
868 | 729 |
String[] namesArray = names.toArray(new String[] {}); |
10 | 730 |
String result = " "; |
731 |
for (int i = 0; i < namesArray.length; i++) { |
|
732 |
result += "@" + namesArray[i]; |
|
733 |
if (i + 1 < namesArray.length) { |
|
734 |
result += ", "; |
|
735 |
} |
|
736 |
} |
|
737 |
message.notice(noticeKey, result); |
|
738 |
} |
|
739 |
} |
|
740 |
||
741 |
/** |
|
742 |
* Given the name of a tag, return the corresponding taglet. |
|
743 |
* Return null if the tag is unknown. |
|
744 |
* |
|
745 |
* @param name the name of the taglet to retrieve. |
|
746 |
* @return return the corresponding taglet. Return null if the tag is |
|
747 |
* unknown. |
|
748 |
*/ |
|
749 |
public Taglet getTaglet(String name) { |
|
750 |
if (name.indexOf("@") == 0) { |
|
868 | 751 |
return customTags.get(name.substring(1)); |
10 | 752 |
} else { |
868 | 753 |
return customTags.get(name); |
10 | 754 |
} |
755 |
||
756 |
} |
|
757 |
} |