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