src/share/classes/com/sun/tools/javadoc/DocEnv.java

Thu, 24 May 2018 18:02:46 +0800

author
aoqi
date
Thu, 24 May 2018 18:02:46 +0800
changeset 3446
e468915bad3a
parent 3315
6f0746b6de9f
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aefimov@3315 2 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.javadoc;
aoqi@0 27
aoqi@0 28 import java.lang.reflect.Modifier;
aoqi@0 29 import java.util.*;
aoqi@0 30
aoqi@0 31 import javax.tools.JavaFileManager;
aoqi@0 32
aoqi@0 33 import com.sun.javadoc.*;
aoqi@0 34 import com.sun.source.util.JavacTask;
aoqi@0 35 import com.sun.source.util.TreePath;
aoqi@0 36 import com.sun.tools.doclint.DocLint;
aoqi@0 37 import com.sun.tools.javac.api.BasicJavacTask;
aoqi@0 38 import com.sun.tools.javac.code.*;
aoqi@0 39 import com.sun.tools.javac.code.Symbol.*;
aoqi@0 40 import com.sun.tools.javac.code.Type.ClassType;
aoqi@0 41 import com.sun.tools.javac.comp.Check;
aoqi@0 42 import com.sun.tools.javac.file.JavacFileManager;
aoqi@0 43 import com.sun.tools.javac.tree.JCTree;
aoqi@0 44 import com.sun.tools.javac.tree.JCTree.*;
aoqi@0 45 import com.sun.tools.javac.util.Context;
aoqi@0 46 import com.sun.tools.javac.util.Names;
aoqi@0 47
aoqi@0 48 /**
aoqi@0 49 * Holds the environment for a run of javadoc.
aoqi@0 50 * Holds only the information needed throughout the
aoqi@0 51 * run and not the compiler info that could be GC'ed
aoqi@0 52 * or ported.
aoqi@0 53 *
aoqi@0 54 * <p><b>This is NOT part of any supported API.
aoqi@0 55 * If you write code that depends on this, you do so at your own risk.
aoqi@0 56 * This code and its internal interfaces are subject to change or
aoqi@0 57 * deletion without notice.</b>
aoqi@0 58 *
aoqi@0 59 * @since 1.4
aoqi@0 60 * @author Robert Field
aoqi@0 61 * @author Neal Gafter (rewrite)
aoqi@0 62 * @author Scott Seligman (generics)
aoqi@0 63 */
aoqi@0 64 public class DocEnv {
aoqi@0 65 protected static final Context.Key<DocEnv> docEnvKey =
aoqi@0 66 new Context.Key<DocEnv>();
aoqi@0 67
aoqi@0 68 public static DocEnv instance(Context context) {
aoqi@0 69 DocEnv instance = context.get(docEnvKey);
aoqi@0 70 if (instance == null)
aoqi@0 71 instance = new DocEnv(context);
aoqi@0 72 return instance;
aoqi@0 73 }
aoqi@0 74
aoqi@0 75 private Messager messager;
aoqi@0 76
aoqi@0 77 DocLocale doclocale;
aoqi@0 78
aoqi@0 79 /** Predefined symbols known to the compiler. */
aoqi@0 80 Symtab syms;
aoqi@0 81
aoqi@0 82 /** Referenced directly in RootDocImpl. */
aoqi@0 83 JavadocClassReader reader;
aoqi@0 84
aoqi@0 85 /** Javadoc's own version of the compiler's enter phase. */
aoqi@0 86 JavadocEnter enter;
aoqi@0 87
aoqi@0 88 /** The name table. */
aefimov@3315 89 private final Names names;
aoqi@0 90
aoqi@0 91 /** The encoding name. */
aoqi@0 92 private String encoding;
aoqi@0 93
aoqi@0 94 final Symbol externalizableSym;
aoqi@0 95
aoqi@0 96 /** Access filter (public, protected, ...). */
aoqi@0 97 protected ModifierFilter showAccess;
aoqi@0 98
aoqi@0 99 /** True if we are using a sentence BreakIterator. */
aoqi@0 100 boolean breakiterator;
aoqi@0 101
aoqi@0 102 /**
aoqi@0 103 * True if we do not want to print any notifications at all.
aoqi@0 104 */
aoqi@0 105 boolean quiet = false;
aoqi@0 106
aoqi@0 107 Check chk;
aoqi@0 108 Types types;
aoqi@0 109 JavaFileManager fileManager;
aoqi@0 110 Context context;
aoqi@0 111 DocLint doclint;
aefimov@3315 112 JavaScriptScanner javaScriptScanner;
aoqi@0 113
aoqi@0 114 WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<JCTree, TreePath>();
aoqi@0 115
aoqi@0 116 /** Allow documenting from class files? */
aoqi@0 117 boolean docClasses = false;
aoqi@0 118
aoqi@0 119 /** Does the doclet only expect pre-1.5 doclet API? */
aoqi@0 120 protected boolean legacyDoclet = true;
aoqi@0 121
aoqi@0 122 /**
aoqi@0 123 * Set this to true if you would like to not emit any errors, warnings and
aoqi@0 124 * notices.
aoqi@0 125 */
aoqi@0 126 private boolean silent = false;
aoqi@0 127
aoqi@0 128 /**
aoqi@0 129 * The source language version.
aoqi@0 130 */
aoqi@0 131 protected Source source;
aoqi@0 132
aoqi@0 133 /**
aoqi@0 134 * Constructor
aoqi@0 135 *
aoqi@0 136 * @param context Context for this javadoc instance.
aoqi@0 137 */
aoqi@0 138 protected DocEnv(Context context) {
aoqi@0 139 context.put(docEnvKey, this);
aoqi@0 140 this.context = context;
aoqi@0 141
aoqi@0 142 messager = Messager.instance0(context);
aoqi@0 143 syms = Symtab.instance(context);
aoqi@0 144 reader = JavadocClassReader.instance0(context);
aoqi@0 145 enter = JavadocEnter.instance0(context);
aoqi@0 146 names = Names.instance(context);
aoqi@0 147 externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable"));
aoqi@0 148 chk = Check.instance(context);
aoqi@0 149 types = Types.instance(context);
aoqi@0 150 fileManager = context.get(JavaFileManager.class);
aoqi@0 151 if (fileManager instanceof JavacFileManager) {
aoqi@0 152 ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 // Default. Should normally be reset with setLocale.
aoqi@0 156 this.doclocale = new DocLocale(this, "", breakiterator);
aoqi@0 157 source = Source.instance(context);
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 public void setSilent(boolean silent) {
aoqi@0 161 this.silent = silent;
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 /**
aoqi@0 165 * Look up ClassDoc by qualified name.
aoqi@0 166 */
aoqi@0 167 public ClassDocImpl lookupClass(String name) {
aoqi@0 168 ClassSymbol c = getClassSymbol(name);
aoqi@0 169 if (c != null) {
aoqi@0 170 return getClassDoc(c);
aoqi@0 171 } else {
aoqi@0 172 return null;
aoqi@0 173 }
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 /**
aoqi@0 177 * Load ClassDoc by qualified name.
aoqi@0 178 */
aoqi@0 179 public ClassDocImpl loadClass(String name) {
aoqi@0 180 try {
aoqi@0 181 ClassSymbol c = reader.loadClass(names.fromString(name));
aoqi@0 182 return getClassDoc(c);
aoqi@0 183 } catch (CompletionFailure ex) {
aoqi@0 184 chk.completionError(null, ex);
aoqi@0 185 return null;
aoqi@0 186 }
aoqi@0 187 }
aoqi@0 188
aoqi@0 189 /**
aoqi@0 190 * Look up PackageDoc by qualified name.
aoqi@0 191 */
aoqi@0 192 public PackageDocImpl lookupPackage(String name) {
aoqi@0 193 //### Jing alleges that class check is needed
aoqi@0 194 //### to avoid a compiler bug. Most likely
aoqi@0 195 //### instead a dummy created for error recovery.
aoqi@0 196 //### Should investigate this.
aoqi@0 197 PackageSymbol p = syms.packages.get(names.fromString(name));
aoqi@0 198 ClassSymbol c = getClassSymbol(name);
aoqi@0 199 if (p != null && c == null) {
aoqi@0 200 return getPackageDoc(p);
aoqi@0 201 } else {
aoqi@0 202 return null;
aoqi@0 203 }
aoqi@0 204 }
aoqi@0 205 // where
aoqi@0 206 /** Retrieve class symbol by fully-qualified name.
aoqi@0 207 */
aoqi@0 208 ClassSymbol getClassSymbol(String name) {
aoqi@0 209 // Name may contain nested class qualification.
aoqi@0 210 // Generate candidate flatnames with successively shorter
aoqi@0 211 // package qualifiers and longer nested class qualifiers.
aoqi@0 212 int nameLen = name.length();
aoqi@0 213 char[] nameChars = name.toCharArray();
aoqi@0 214 int idx = name.length();
aoqi@0 215 for (;;) {
aoqi@0 216 ClassSymbol s = syms.classes.get(names.fromChars(nameChars, 0, nameLen));
aoqi@0 217 if (s != null)
aoqi@0 218 return s; // found it!
aoqi@0 219 idx = name.substring(0, idx).lastIndexOf('.');
aoqi@0 220 if (idx < 0) break;
aoqi@0 221 nameChars[idx] = '$';
aoqi@0 222 }
aoqi@0 223 return null;
aoqi@0 224 }
aoqi@0 225
aoqi@0 226 /**
aoqi@0 227 * Set the locale.
aoqi@0 228 */
aoqi@0 229 public void setLocale(String localeName) {
aoqi@0 230 // create locale specifics
aoqi@0 231 doclocale = new DocLocale(this, localeName, breakiterator);
aoqi@0 232 // update Messager if locale has changed.
aoqi@0 233 messager.setLocale(doclocale.locale);
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 /** Check whether this member should be documented. */
aoqi@0 237 public boolean shouldDocument(VarSymbol sym) {
aoqi@0 238 long mod = sym.flags();
aoqi@0 239
aoqi@0 240 if ((mod & Flags.SYNTHETIC) != 0) {
aoqi@0 241 return false;
aoqi@0 242 }
aoqi@0 243
aoqi@0 244 return showAccess.checkModifier(translateModifiers(mod));
aoqi@0 245 }
aoqi@0 246
aoqi@0 247 /** Check whether this member should be documented. */
aoqi@0 248 public boolean shouldDocument(MethodSymbol sym) {
aoqi@0 249 long mod = sym.flags();
aoqi@0 250
aoqi@0 251 if ((mod & Flags.SYNTHETIC) != 0) {
aoqi@0 252 return false;
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 return showAccess.checkModifier(translateModifiers(mod));
aoqi@0 256 }
aoqi@0 257
aoqi@0 258 /** check whether this class should be documented. */
aoqi@0 259 public boolean shouldDocument(ClassSymbol sym) {
aoqi@0 260 return
aoqi@0 261 (sym.flags_field&Flags.SYNTHETIC) == 0 && // no synthetics
aoqi@0 262 (docClasses || getClassDoc(sym).tree != null) &&
aoqi@0 263 isVisible(sym);
aoqi@0 264 }
aoqi@0 265
aoqi@0 266 //### Comment below is inaccurate wrt modifier filter testing
aoqi@0 267 /**
aoqi@0 268 * Check the visibility if this is an nested class.
aoqi@0 269 * if this is not a nested class, return true.
aoqi@0 270 * if this is an static visible nested class,
aoqi@0 271 * return true.
aoqi@0 272 * if this is an visible nested class
aoqi@0 273 * if the outer class is visible return true.
aoqi@0 274 * else return false.
aoqi@0 275 * IMPORTANT: This also allows, static nested classes
aoqi@0 276 * to be defined inside an nested class, which is not
aoqi@0 277 * allowed by the compiler. So such an test case will
aoqi@0 278 * not reach upto this method itself, but if compiler
aoqi@0 279 * allows it, then that will go through.
aoqi@0 280 */
aoqi@0 281 protected boolean isVisible(ClassSymbol sym) {
aoqi@0 282 long mod = sym.flags_field;
aoqi@0 283 if (!showAccess.checkModifier(translateModifiers(mod))) {
aoqi@0 284 return false;
aoqi@0 285 }
aoqi@0 286 ClassSymbol encl = sym.owner.enclClass();
aoqi@0 287 return (encl == null || (mod & Flags.STATIC) != 0 || isVisible(encl));
aoqi@0 288 }
aoqi@0 289
aoqi@0 290 //---------------- print forwarders ----------------//
aoqi@0 291
aoqi@0 292 /**
aoqi@0 293 * Print error message, increment error count.
aoqi@0 294 *
aoqi@0 295 * @param msg message to print.
aoqi@0 296 */
aoqi@0 297 public void printError(String msg) {
aoqi@0 298 if (silent)
aoqi@0 299 return;
aoqi@0 300 messager.printError(msg);
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 /**
aoqi@0 304 * Print error message, increment error count.
aoqi@0 305 *
aoqi@0 306 * @param key selects message from resource
aoqi@0 307 */
aoqi@0 308 public void error(DocImpl doc, String key) {
aoqi@0 309 if (silent)
aoqi@0 310 return;
aoqi@0 311 messager.error(doc==null ? null : doc.position(), key);
aoqi@0 312 }
aoqi@0 313
aoqi@0 314 /**
aoqi@0 315 * Print error message, increment error count.
aoqi@0 316 *
aoqi@0 317 * @param key selects message from resource
aoqi@0 318 */
aoqi@0 319 public void error(SourcePosition pos, String key) {
aoqi@0 320 if (silent)
aoqi@0 321 return;
aoqi@0 322 messager.error(pos, key);
aoqi@0 323 }
aoqi@0 324
aoqi@0 325 /**
aoqi@0 326 * Print error message, increment error count.
aoqi@0 327 *
aoqi@0 328 * @param msg message to print.
aoqi@0 329 */
aoqi@0 330 public void printError(SourcePosition pos, String msg) {
aoqi@0 331 if (silent)
aoqi@0 332 return;
aoqi@0 333 messager.printError(pos, msg);
aoqi@0 334 }
aoqi@0 335
aoqi@0 336 /**
aoqi@0 337 * Print error message, increment error count.
aoqi@0 338 *
aoqi@0 339 * @param key selects message from resource
aoqi@0 340 * @param a1 first argument
aoqi@0 341 */
aoqi@0 342 public void error(DocImpl doc, String key, String a1) {
aoqi@0 343 if (silent)
aoqi@0 344 return;
aoqi@0 345 messager.error(doc==null ? null : doc.position(), key, a1);
aoqi@0 346 }
aoqi@0 347
aoqi@0 348 /**
aoqi@0 349 * Print error message, increment error count.
aoqi@0 350 *
aoqi@0 351 * @param key selects message from resource
aoqi@0 352 * @param a1 first argument
aoqi@0 353 * @param a2 second argument
aoqi@0 354 */
aoqi@0 355 public void error(DocImpl doc, String key, String a1, String a2) {
aoqi@0 356 if (silent)
aoqi@0 357 return;
aoqi@0 358 messager.error(doc==null ? null : doc.position(), key, a1, a2);
aoqi@0 359 }
aoqi@0 360
aoqi@0 361 /**
aoqi@0 362 * Print error message, increment error count.
aoqi@0 363 *
aoqi@0 364 * @param key selects message from resource
aoqi@0 365 * @param a1 first argument
aoqi@0 366 * @param a2 second argument
aoqi@0 367 * @param a3 third argument
aoqi@0 368 */
aoqi@0 369 public void error(DocImpl doc, String key, String a1, String a2, String a3) {
aoqi@0 370 if (silent)
aoqi@0 371 return;
aoqi@0 372 messager.error(doc==null ? null : doc.position(), key, a1, a2, a3);
aoqi@0 373 }
aoqi@0 374
aoqi@0 375 /**
aoqi@0 376 * Print warning message, increment warning count.
aoqi@0 377 *
aoqi@0 378 * @param msg message to print.
aoqi@0 379 */
aoqi@0 380 public void printWarning(String msg) {
aoqi@0 381 if (silent)
aoqi@0 382 return;
aoqi@0 383 messager.printWarning(msg);
aoqi@0 384 }
aoqi@0 385
aoqi@0 386 /**
aoqi@0 387 * Print warning message, increment warning count.
aoqi@0 388 *
aoqi@0 389 * @param key selects message from resource
aoqi@0 390 */
aoqi@0 391 public void warning(DocImpl doc, String key) {
aoqi@0 392 if (silent)
aoqi@0 393 return;
aoqi@0 394 messager.warning(doc==null ? null : doc.position(), key);
aoqi@0 395 }
aoqi@0 396
aoqi@0 397 /**
aoqi@0 398 * Print warning message, increment warning count.
aoqi@0 399 *
aoqi@0 400 * @param msg message to print.
aoqi@0 401 */
aoqi@0 402 public void printWarning(SourcePosition pos, String msg) {
aoqi@0 403 if (silent)
aoqi@0 404 return;
aoqi@0 405 messager.printWarning(pos, msg);
aoqi@0 406 }
aoqi@0 407
aoqi@0 408 /**
aoqi@0 409 * Print warning message, increment warning count.
aoqi@0 410 *
aoqi@0 411 * @param key selects message from resource
aoqi@0 412 * @param a1 first argument
aoqi@0 413 */
aoqi@0 414 public void warning(DocImpl doc, String key, String a1) {
aoqi@0 415 if (silent)
aoqi@0 416 return;
aoqi@0 417 // suppress messages that have (probably) been covered by doclint
aoqi@0 418 if (doclint != null && doc != null && key.startsWith("tag"))
aoqi@0 419 return;
aoqi@0 420 messager.warning(doc==null ? null : doc.position(), key, a1);
aoqi@0 421 }
aoqi@0 422
aoqi@0 423 /**
aoqi@0 424 * Print warning message, increment warning count.
aoqi@0 425 *
aoqi@0 426 * @param key selects message from resource
aoqi@0 427 * @param a1 first argument
aoqi@0 428 * @param a2 second argument
aoqi@0 429 */
aoqi@0 430 public void warning(DocImpl doc, String key, String a1, String a2) {
aoqi@0 431 if (silent)
aoqi@0 432 return;
aoqi@0 433 messager.warning(doc==null ? null : doc.position(), key, a1, a2);
aoqi@0 434 }
aoqi@0 435
aoqi@0 436 /**
aoqi@0 437 * Print warning message, increment warning count.
aoqi@0 438 *
aoqi@0 439 * @param key selects message from resource
aoqi@0 440 * @param a1 first argument
aoqi@0 441 * @param a2 second argument
aoqi@0 442 * @param a3 third argument
aoqi@0 443 */
aoqi@0 444 public void warning(DocImpl doc, String key, String a1, String a2, String a3) {
aoqi@0 445 if (silent)
aoqi@0 446 return;
aoqi@0 447 messager.warning(doc==null ? null : doc.position(), key, a1, a2, a3);
aoqi@0 448 }
aoqi@0 449
aoqi@0 450 /**
aoqi@0 451 * Print warning message, increment warning count.
aoqi@0 452 *
aoqi@0 453 * @param key selects message from resource
aoqi@0 454 * @param a1 first argument
aoqi@0 455 * @param a2 second argument
aoqi@0 456 * @param a3 third argument
aoqi@0 457 */
aoqi@0 458 public void warning(DocImpl doc, String key, String a1, String a2, String a3,
aoqi@0 459 String a4) {
aoqi@0 460 if (silent)
aoqi@0 461 return;
aoqi@0 462 messager.warning(doc==null ? null : doc.position(), key, a1, a2, a3, a4);
aoqi@0 463 }
aoqi@0 464
aoqi@0 465 /**
aoqi@0 466 * Print a message.
aoqi@0 467 *
aoqi@0 468 * @param msg message to print.
aoqi@0 469 */
aoqi@0 470 public void printNotice(String msg) {
aoqi@0 471 if (silent || quiet)
aoqi@0 472 return;
aoqi@0 473 messager.printNotice(msg);
aoqi@0 474 }
aoqi@0 475
aoqi@0 476
aoqi@0 477 /**
aoqi@0 478 * Print a message.
aoqi@0 479 *
aoqi@0 480 * @param key selects message from resource
aoqi@0 481 */
aoqi@0 482 public void notice(String key) {
aoqi@0 483 if (silent || quiet)
aoqi@0 484 return;
aoqi@0 485 messager.notice(key);
aoqi@0 486 }
aoqi@0 487
aoqi@0 488 /**
aoqi@0 489 * Print a message.
aoqi@0 490 *
aoqi@0 491 * @param msg message to print.
aoqi@0 492 */
aoqi@0 493 public void printNotice(SourcePosition pos, String msg) {
aoqi@0 494 if (silent || quiet)
aoqi@0 495 return;
aoqi@0 496 messager.printNotice(pos, msg);
aoqi@0 497 }
aoqi@0 498
aoqi@0 499 /**
aoqi@0 500 * Print a message.
aoqi@0 501 *
aoqi@0 502 * @param key selects message from resource
aoqi@0 503 * @param a1 first argument
aoqi@0 504 */
aoqi@0 505 public void notice(String key, String a1) {
aoqi@0 506 if (silent || quiet)
aoqi@0 507 return;
aoqi@0 508 messager.notice(key, a1);
aoqi@0 509 }
aoqi@0 510
aoqi@0 511 /**
aoqi@0 512 * Print a message.
aoqi@0 513 *
aoqi@0 514 * @param key selects message from resource
aoqi@0 515 * @param a1 first argument
aoqi@0 516 * @param a2 second argument
aoqi@0 517 */
aoqi@0 518 public void notice(String key, String a1, String a2) {
aoqi@0 519 if (silent || quiet)
aoqi@0 520 return;
aoqi@0 521 messager.notice(key, a1, a2);
aoqi@0 522 }
aoqi@0 523
aoqi@0 524 /**
aoqi@0 525 * Print a message.
aoqi@0 526 *
aoqi@0 527 * @param key selects message from resource
aoqi@0 528 * @param a1 first argument
aoqi@0 529 * @param a2 second argument
aoqi@0 530 * @param a3 third argument
aoqi@0 531 */
aoqi@0 532 public void notice(String key, String a1, String a2, String a3) {
aoqi@0 533 if (silent || quiet)
aoqi@0 534 return;
aoqi@0 535 messager.notice(key, a1, a2, a3);
aoqi@0 536 }
aoqi@0 537
aoqi@0 538 /**
aoqi@0 539 * Exit, reporting errors and warnings.
aoqi@0 540 */
aoqi@0 541 public void exit() {
aoqi@0 542 // Messager should be replaced by a more general
aoqi@0 543 // compilation environment. This can probably
aoqi@0 544 // subsume DocEnv as well.
aoqi@0 545 messager.exit();
aoqi@0 546 }
aoqi@0 547
aoqi@0 548 protected Map<PackageSymbol, PackageDocImpl> packageMap =
aoqi@0 549 new HashMap<PackageSymbol, PackageDocImpl>();
aoqi@0 550 /**
aoqi@0 551 * Return the PackageDoc of this package symbol.
aoqi@0 552 */
aoqi@0 553 public PackageDocImpl getPackageDoc(PackageSymbol pack) {
aoqi@0 554 PackageDocImpl result = packageMap.get(pack);
aoqi@0 555 if (result != null) return result;
aoqi@0 556 result = new PackageDocImpl(this, pack);
aoqi@0 557 packageMap.put(pack, result);
aoqi@0 558 return result;
aoqi@0 559 }
aoqi@0 560
aoqi@0 561 /**
aoqi@0 562 * Create the PackageDoc (or a subtype) for a package symbol.
aoqi@0 563 */
aoqi@0 564 void makePackageDoc(PackageSymbol pack, TreePath treePath) {
aoqi@0 565 PackageDocImpl result = packageMap.get(pack);
aoqi@0 566 if (result != null) {
aoqi@0 567 if (treePath != null) result.setTreePath(treePath);
aoqi@0 568 } else {
aoqi@0 569 result = new PackageDocImpl(this, pack, treePath);
aoqi@0 570 packageMap.put(pack, result);
aoqi@0 571 }
aoqi@0 572 }
aoqi@0 573
aoqi@0 574
aoqi@0 575 protected Map<ClassSymbol, ClassDocImpl> classMap =
aoqi@0 576 new HashMap<ClassSymbol, ClassDocImpl>();
aoqi@0 577 /**
aoqi@0 578 * Return the ClassDoc (or a subtype) of this class symbol.
aoqi@0 579 */
aoqi@0 580 public ClassDocImpl getClassDoc(ClassSymbol clazz) {
aoqi@0 581 ClassDocImpl result = classMap.get(clazz);
aoqi@0 582 if (result != null) return result;
aoqi@0 583 if (isAnnotationType(clazz)) {
aoqi@0 584 result = new AnnotationTypeDocImpl(this, clazz);
aoqi@0 585 } else {
aoqi@0 586 result = new ClassDocImpl(this, clazz);
aoqi@0 587 }
aoqi@0 588 classMap.put(clazz, result);
aoqi@0 589 return result;
aoqi@0 590 }
aoqi@0 591
aoqi@0 592 /**
aoqi@0 593 * Create the ClassDoc (or a subtype) for a class symbol.
aoqi@0 594 */
aoqi@0 595 protected void makeClassDoc(ClassSymbol clazz, TreePath treePath) {
aoqi@0 596 ClassDocImpl result = classMap.get(clazz);
aoqi@0 597 if (result != null) {
aoqi@0 598 if (treePath != null) result.setTreePath(treePath);
aoqi@0 599 return;
aoqi@0 600 }
aoqi@0 601 if (isAnnotationType((JCClassDecl) treePath.getLeaf())) { // flags of clazz may not yet be set
aoqi@0 602 result = new AnnotationTypeDocImpl(this, clazz, treePath);
aoqi@0 603 } else {
aoqi@0 604 result = new ClassDocImpl(this, clazz, treePath);
aoqi@0 605 }
aoqi@0 606 classMap.put(clazz, result);
aoqi@0 607 }
aoqi@0 608
aoqi@0 609 protected static boolean isAnnotationType(ClassSymbol clazz) {
aoqi@0 610 return ClassDocImpl.isAnnotationType(clazz);
aoqi@0 611 }
aoqi@0 612
aoqi@0 613 protected static boolean isAnnotationType(JCClassDecl tree) {
aoqi@0 614 return (tree.mods.flags & Flags.ANNOTATION) != 0;
aoqi@0 615 }
aoqi@0 616
aoqi@0 617 protected Map<VarSymbol, FieldDocImpl> fieldMap =
aoqi@0 618 new HashMap<VarSymbol, FieldDocImpl>();
aoqi@0 619 /**
aoqi@0 620 * Return the FieldDoc of this var symbol.
aoqi@0 621 */
aoqi@0 622 public FieldDocImpl getFieldDoc(VarSymbol var) {
aoqi@0 623 FieldDocImpl result = fieldMap.get(var);
aoqi@0 624 if (result != null) return result;
aoqi@0 625 result = new FieldDocImpl(this, var);
aoqi@0 626 fieldMap.put(var, result);
aoqi@0 627 return result;
aoqi@0 628 }
aoqi@0 629 /**
aoqi@0 630 * Create a FieldDoc for a var symbol.
aoqi@0 631 */
aoqi@0 632 protected void makeFieldDoc(VarSymbol var, TreePath treePath) {
aoqi@0 633 FieldDocImpl result = fieldMap.get(var);
aoqi@0 634 if (result != null) {
aoqi@0 635 if (treePath != null) result.setTreePath(treePath);
aoqi@0 636 } else {
aoqi@0 637 result = new FieldDocImpl(this, var, treePath);
aoqi@0 638 fieldMap.put(var, result);
aoqi@0 639 }
aoqi@0 640 }
aoqi@0 641
aoqi@0 642 protected Map<MethodSymbol, ExecutableMemberDocImpl> methodMap =
aoqi@0 643 new HashMap<MethodSymbol, ExecutableMemberDocImpl>();
aoqi@0 644 /**
aoqi@0 645 * Create a MethodDoc for this MethodSymbol.
aoqi@0 646 * Should be called only on symbols representing methods.
aoqi@0 647 */
aoqi@0 648 protected void makeMethodDoc(MethodSymbol meth, TreePath treePath) {
aoqi@0 649 MethodDocImpl result = (MethodDocImpl)methodMap.get(meth);
aoqi@0 650 if (result != null) {
aoqi@0 651 if (treePath != null) result.setTreePath(treePath);
aoqi@0 652 } else {
aoqi@0 653 result = new MethodDocImpl(this, meth, treePath);
aoqi@0 654 methodMap.put(meth, result);
aoqi@0 655 }
aoqi@0 656 }
aoqi@0 657
aoqi@0 658 /**
aoqi@0 659 * Return the MethodDoc for a MethodSymbol.
aoqi@0 660 * Should be called only on symbols representing methods.
aoqi@0 661 */
aoqi@0 662 public MethodDocImpl getMethodDoc(MethodSymbol meth) {
aoqi@0 663 assert !meth.isConstructor() : "not expecting a constructor symbol";
aoqi@0 664 MethodDocImpl result = (MethodDocImpl)methodMap.get(meth);
aoqi@0 665 if (result != null) return result;
aoqi@0 666 result = new MethodDocImpl(this, meth);
aoqi@0 667 methodMap.put(meth, result);
aoqi@0 668 return result;
aoqi@0 669 }
aoqi@0 670
aoqi@0 671 /**
aoqi@0 672 * Create the ConstructorDoc for a MethodSymbol.
aoqi@0 673 * Should be called only on symbols representing constructors.
aoqi@0 674 */
aoqi@0 675 protected void makeConstructorDoc(MethodSymbol meth, TreePath treePath) {
aoqi@0 676 ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth);
aoqi@0 677 if (result != null) {
aoqi@0 678 if (treePath != null) result.setTreePath(treePath);
aoqi@0 679 } else {
aoqi@0 680 result = new ConstructorDocImpl(this, meth, treePath);
aoqi@0 681 methodMap.put(meth, result);
aoqi@0 682 }
aoqi@0 683 }
aoqi@0 684
aoqi@0 685 /**
aoqi@0 686 * Return the ConstructorDoc for a MethodSymbol.
aoqi@0 687 * Should be called only on symbols representing constructors.
aoqi@0 688 */
aoqi@0 689 public ConstructorDocImpl getConstructorDoc(MethodSymbol meth) {
aoqi@0 690 assert meth.isConstructor() : "expecting a constructor symbol";
aoqi@0 691 ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth);
aoqi@0 692 if (result != null) return result;
aoqi@0 693 result = new ConstructorDocImpl(this, meth);
aoqi@0 694 methodMap.put(meth, result);
aoqi@0 695 return result;
aoqi@0 696 }
aoqi@0 697
aoqi@0 698 /**
aoqi@0 699 * Create the AnnotationTypeElementDoc for a MethodSymbol.
aoqi@0 700 * Should be called only on symbols representing annotation type elements.
aoqi@0 701 */
aoqi@0 702 protected void makeAnnotationTypeElementDoc(MethodSymbol meth, TreePath treePath) {
aoqi@0 703 AnnotationTypeElementDocImpl result =
aoqi@0 704 (AnnotationTypeElementDocImpl)methodMap.get(meth);
aoqi@0 705 if (result != null) {
aoqi@0 706 if (treePath != null) result.setTreePath(treePath);
aoqi@0 707 } else {
aoqi@0 708 result =
aoqi@0 709 new AnnotationTypeElementDocImpl(this, meth, treePath);
aoqi@0 710 methodMap.put(meth, result);
aoqi@0 711 }
aoqi@0 712 }
aoqi@0 713
aoqi@0 714 /**
aoqi@0 715 * Return the AnnotationTypeElementDoc for a MethodSymbol.
aoqi@0 716 * Should be called only on symbols representing annotation type elements.
aoqi@0 717 */
aoqi@0 718 public AnnotationTypeElementDocImpl getAnnotationTypeElementDoc(
aoqi@0 719 MethodSymbol meth) {
aoqi@0 720
aoqi@0 721 AnnotationTypeElementDocImpl result =
aoqi@0 722 (AnnotationTypeElementDocImpl)methodMap.get(meth);
aoqi@0 723 if (result != null) return result;
aoqi@0 724 result = new AnnotationTypeElementDocImpl(this, meth);
aoqi@0 725 methodMap.put(meth, result);
aoqi@0 726 return result;
aoqi@0 727 }
aoqi@0 728
aoqi@0 729 // private Map<ClassType, ParameterizedTypeImpl> parameterizedTypeMap =
aoqi@0 730 // new HashMap<ClassType, ParameterizedTypeImpl>();
aoqi@0 731 /**
aoqi@0 732 * Return the ParameterizedType of this instantiation.
aoqi@0 733 // * ### Could use Type.sameTypeAs() instead of equality matching in hashmap
aoqi@0 734 // * ### to avoid some duplication.
aoqi@0 735 */
aoqi@0 736 ParameterizedTypeImpl getParameterizedType(ClassType t) {
aoqi@0 737 return new ParameterizedTypeImpl(this, t);
aoqi@0 738 // ParameterizedTypeImpl result = parameterizedTypeMap.get(t);
aoqi@0 739 // if (result != null) return result;
aoqi@0 740 // result = new ParameterizedTypeImpl(this, t);
aoqi@0 741 // parameterizedTypeMap.put(t, result);
aoqi@0 742 // return result;
aoqi@0 743 }
aoqi@0 744
aoqi@0 745 TreePath getTreePath(JCCompilationUnit tree) {
aoqi@0 746 TreePath p = treePaths.get(tree);
aoqi@0 747 if (p == null)
aoqi@0 748 treePaths.put(tree, p = new TreePath(tree));
aoqi@0 749 return p;
aoqi@0 750 }
aoqi@0 751
aoqi@0 752 TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl tree) {
aoqi@0 753 TreePath p = treePaths.get(tree);
aoqi@0 754 if (p == null)
aoqi@0 755 treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
aoqi@0 756 return p;
aoqi@0 757 }
aoqi@0 758
aoqi@0 759 TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl cdecl, JCTree tree) {
aoqi@0 760 return new TreePath(getTreePath(toplevel, cdecl), tree);
aoqi@0 761 }
aoqi@0 762
aoqi@0 763 /**
aoqi@0 764 * Set the encoding.
aoqi@0 765 */
aoqi@0 766 public void setEncoding(String encoding) {
aoqi@0 767 this.encoding = encoding;
aoqi@0 768 }
aoqi@0 769
aoqi@0 770 /**
aoqi@0 771 * Get the encoding.
aoqi@0 772 */
aoqi@0 773 public String getEncoding() {
aoqi@0 774 return encoding;
aoqi@0 775 }
aoqi@0 776
aoqi@0 777 /**
aoqi@0 778 * Convert modifier bits from private coding used by
aoqi@0 779 * the compiler to that of java.lang.reflect.Modifier.
aoqi@0 780 */
aoqi@0 781 static int translateModifiers(long flags) {
aoqi@0 782 int result = 0;
aoqi@0 783 if ((flags & Flags.ABSTRACT) != 0)
aoqi@0 784 result |= Modifier.ABSTRACT;
aoqi@0 785 if ((flags & Flags.FINAL) != 0)
aoqi@0 786 result |= Modifier.FINAL;
aoqi@0 787 if ((flags & Flags.INTERFACE) != 0)
aoqi@0 788 result |= Modifier.INTERFACE;
aoqi@0 789 if ((flags & Flags.NATIVE) != 0)
aoqi@0 790 result |= Modifier.NATIVE;
aoqi@0 791 if ((flags & Flags.PRIVATE) != 0)
aoqi@0 792 result |= Modifier.PRIVATE;
aoqi@0 793 if ((flags & Flags.PROTECTED) != 0)
aoqi@0 794 result |= Modifier.PROTECTED;
aoqi@0 795 if ((flags & Flags.PUBLIC) != 0)
aoqi@0 796 result |= Modifier.PUBLIC;
aoqi@0 797 if ((flags & Flags.STATIC) != 0)
aoqi@0 798 result |= Modifier.STATIC;
aoqi@0 799 if ((flags & Flags.SYNCHRONIZED) != 0)
aoqi@0 800 result |= Modifier.SYNCHRONIZED;
aoqi@0 801 if ((flags & Flags.TRANSIENT) != 0)
aoqi@0 802 result |= Modifier.TRANSIENT;
aoqi@0 803 if ((flags & Flags.VOLATILE) != 0)
aoqi@0 804 result |= Modifier.VOLATILE;
aoqi@0 805 return result;
aoqi@0 806 }
aoqi@0 807
aoqi@0 808 void initDoclint(Collection<String> opts, Collection<String> customTagNames) {
aoqi@0 809 ArrayList<String> doclintOpts = new ArrayList<String>();
aoqi@0 810
aoqi@0 811 for (String opt: opts) {
aoqi@0 812 doclintOpts.add(opt == null ? DocLint.XMSGS_OPTION : DocLint.XMSGS_CUSTOM_PREFIX + opt);
aoqi@0 813 }
aoqi@0 814
aoqi@0 815 if (doclintOpts.isEmpty()) {
aoqi@0 816 doclintOpts.add(DocLint.XMSGS_OPTION);
aoqi@0 817 } else if (doclintOpts.size() == 1
aoqi@0 818 && doclintOpts.get(0).equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) {
aoqi@0 819 return;
aoqi@0 820 }
aoqi@0 821
aoqi@0 822 String sep = "";
aoqi@0 823 StringBuilder customTags = new StringBuilder();
aoqi@0 824 for (String customTag : customTagNames) {
aoqi@0 825 customTags.append(sep);
aoqi@0 826 customTags.append(customTag);
aoqi@0 827 sep = DocLint.TAGS_SEPARATOR;
aoqi@0 828 }
aoqi@0 829 doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());
aoqi@0 830
aoqi@0 831 JavacTask t = BasicJavacTask.instance(context);
aoqi@0 832 doclint = new DocLint();
aoqi@0 833 // standard doclet normally generates H1, H2
aoqi@0 834 doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
aoqi@0 835 doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
aoqi@0 836 }
aoqi@0 837
aefimov@3315 838 JavaScriptScanner initJavaScriptScanner(boolean allowScriptInComments) {
aefimov@3315 839 if (allowScriptInComments) {
aefimov@3315 840 javaScriptScanner = null;
aefimov@3315 841 } else {
aefimov@3315 842 javaScriptScanner = new JavaScriptScanner();
aefimov@3315 843 }
aefimov@3315 844 return javaScriptScanner;
aefimov@3315 845 }
aefimov@3315 846
aoqi@0 847 boolean showTagMessages() {
aoqi@0 848 return (doclint == null);
aoqi@0 849 }
aoqi@0 850 }

mercurial