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