src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java

Tue, 18 Jun 2013 20:56:04 -0700

author
mfang
date
Tue, 18 Jun 2013 20:56:04 -0700
changeset 1841
792c40d5185a
parent 1750
081d7c72ee92
child 1866
26437287529d
permissions
-rw-r--r--

8015657: jdk8 l10n resource file translation update 3
Reviewed-by: yhuang

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

mercurial