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

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 184
905e151a185a
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

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

mercurial