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 1997-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 com.sun.javadoc.*; |
duke@1 | 29 | |
duke@1 | 30 | import static com.sun.javadoc.LanguageVersion.*; |
duke@1 | 31 | |
duke@1 | 32 | import com.sun.tools.javac.util.List; |
duke@1 | 33 | import com.sun.tools.javac.util.ListBuffer; |
duke@1 | 34 | import com.sun.tools.javac.util.Name; |
duke@1 | 35 | import com.sun.tools.javac.util.Position; |
duke@1 | 36 | |
duke@1 | 37 | import com.sun.tools.javac.code.Flags; |
duke@1 | 38 | import com.sun.tools.javac.code.Kinds; |
duke@1 | 39 | import com.sun.tools.javac.code.TypeTags; |
duke@1 | 40 | import com.sun.tools.javac.code.Type; |
duke@1 | 41 | import com.sun.tools.javac.code.Type.ClassType; |
duke@1 | 42 | import com.sun.tools.javac.code.Scope; |
duke@1 | 43 | import com.sun.tools.javac.code.Symbol; |
duke@1 | 44 | import com.sun.tools.javac.code.Symbol.*; |
duke@1 | 45 | |
duke@1 | 46 | import com.sun.tools.javac.comp.AttrContext; |
duke@1 | 47 | import com.sun.tools.javac.comp.Env; |
duke@1 | 48 | |
duke@1 | 49 | import com.sun.tools.javac.tree.JCTree; |
duke@1 | 50 | import com.sun.tools.javac.tree.JCTree.JCFieldAccess; |
duke@1 | 51 | import com.sun.tools.javac.tree.JCTree.JCImport; |
duke@1 | 52 | import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
duke@1 | 53 | import com.sun.tools.javac.tree.TreeInfo; |
duke@1 | 54 | |
jjg@113 | 55 | import com.sun.tools.javac.util.Names; |
duke@1 | 56 | import static com.sun.tools.javac.code.Flags.*; |
duke@1 | 57 | import static com.sun.tools.javac.code.Kinds.*; |
duke@1 | 58 | |
duke@1 | 59 | import java.io.File; |
duke@1 | 60 | import java.util.Set; |
duke@1 | 61 | import java.util.HashSet; |
duke@1 | 62 | import java.lang.reflect.Modifier; |
duke@1 | 63 | |
duke@1 | 64 | /** |
duke@1 | 65 | * Represents a java class and provides access to information |
duke@1 | 66 | * about the class, the class' comment and tags, and the |
duke@1 | 67 | * members of the class. A ClassDocImpl only exists if it was |
duke@1 | 68 | * processed in this run of javadoc. References to classes |
duke@1 | 69 | * which may or may not have been processed in this run are |
duke@1 | 70 | * referred to using Type (which can be converted to ClassDocImpl, |
duke@1 | 71 | * if possible). |
duke@1 | 72 | * |
duke@1 | 73 | * @see Type |
duke@1 | 74 | * |
duke@1 | 75 | * @since 1.2 |
duke@1 | 76 | * @author Robert Field |
duke@1 | 77 | * @author Neal Gafter (rewrite) |
duke@1 | 78 | * @author Scott Seligman (generics, enums, annotations) |
duke@1 | 79 | */ |
duke@1 | 80 | |
duke@1 | 81 | public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { |
duke@1 | 82 | |
duke@1 | 83 | public final ClassType type; // protected->public for debugging |
duke@1 | 84 | protected final ClassSymbol tsym; |
duke@1 | 85 | |
duke@1 | 86 | boolean isIncluded = false; // Set in RootDocImpl |
duke@1 | 87 | |
duke@1 | 88 | private SerializedForm serializedForm; |
duke@1 | 89 | |
duke@1 | 90 | /** |
duke@1 | 91 | * Constructor |
duke@1 | 92 | */ |
duke@1 | 93 | public ClassDocImpl(DocEnv env, ClassSymbol sym) { |
duke@1 | 94 | this(env, sym, null, null, null); |
duke@1 | 95 | } |
duke@1 | 96 | |
duke@1 | 97 | /** |
duke@1 | 98 | * Constructor |
duke@1 | 99 | */ |
duke@1 | 100 | public ClassDocImpl(DocEnv env, ClassSymbol sym, String documentation, |
duke@1 | 101 | JCClassDecl tree, Position.LineMap lineMap) { |
duke@1 | 102 | super(env, sym, documentation, tree, lineMap); |
duke@1 | 103 | this.type = (ClassType)sym.type; |
duke@1 | 104 | this.tsym = sym; |
duke@1 | 105 | } |
duke@1 | 106 | |
duke@1 | 107 | /** |
duke@1 | 108 | * Returns the flags in terms of javac's flags |
duke@1 | 109 | */ |
duke@1 | 110 | protected long getFlags() { |
duke@1 | 111 | return getFlags(tsym); |
duke@1 | 112 | } |
duke@1 | 113 | |
duke@1 | 114 | /** |
duke@1 | 115 | * Returns the flags of a ClassSymbol in terms of javac's flags |
duke@1 | 116 | */ |
duke@1 | 117 | static long getFlags(ClassSymbol clazz) { |
duke@1 | 118 | while (true) { |
duke@1 | 119 | try { |
duke@1 | 120 | return clazz.flags(); |
duke@1 | 121 | } catch (CompletionFailure ex) { |
duke@1 | 122 | // quietly ignore completion failures |
duke@1 | 123 | } |
duke@1 | 124 | } |
duke@1 | 125 | } |
duke@1 | 126 | |
duke@1 | 127 | /** |
duke@1 | 128 | * Is a ClassSymbol an annotation type? |
duke@1 | 129 | */ |
duke@1 | 130 | static boolean isAnnotationType(ClassSymbol clazz) { |
duke@1 | 131 | return (getFlags(clazz) & Flags.ANNOTATION) != 0; |
duke@1 | 132 | } |
duke@1 | 133 | |
duke@1 | 134 | /** |
duke@1 | 135 | * Identify the containing class |
duke@1 | 136 | */ |
duke@1 | 137 | protected ClassSymbol getContainingClass() { |
duke@1 | 138 | return tsym.owner.enclClass(); |
duke@1 | 139 | } |
duke@1 | 140 | |
duke@1 | 141 | /** |
duke@1 | 142 | * Return true if this is a class, not an interface. |
duke@1 | 143 | */ |
duke@1 | 144 | public boolean isClass() { |
duke@1 | 145 | return !Modifier.isInterface(getModifiers()); |
duke@1 | 146 | } |
duke@1 | 147 | |
duke@1 | 148 | /** |
duke@1 | 149 | * Return true if this is a ordinary class, |
duke@1 | 150 | * not an enumeration, exception, an error, or an interface. |
duke@1 | 151 | */ |
duke@1 | 152 | public boolean isOrdinaryClass() { |
duke@1 | 153 | if (isEnum() || isInterface() || isAnnotationType()) { |
duke@1 | 154 | return false; |
duke@1 | 155 | } |
duke@1 | 156 | for (Type t = type; t.tag == TypeTags.CLASS; t = env.types.supertype(t)) { |
duke@1 | 157 | if (t.tsym == env.syms.errorType.tsym || |
duke@1 | 158 | t.tsym == env.syms.exceptionType.tsym) { |
duke@1 | 159 | return false; |
duke@1 | 160 | } |
duke@1 | 161 | } |
duke@1 | 162 | return true; |
duke@1 | 163 | } |
duke@1 | 164 | |
duke@1 | 165 | /** |
duke@1 | 166 | * Return true if this is an enumeration. |
duke@1 | 167 | * (For legacy doclets, return false.) |
duke@1 | 168 | */ |
duke@1 | 169 | public boolean isEnum() { |
duke@1 | 170 | return (getFlags() & Flags.ENUM) != 0 |
duke@1 | 171 | && |
duke@1 | 172 | !env.legacyDoclet; |
duke@1 | 173 | } |
duke@1 | 174 | |
duke@1 | 175 | /** |
duke@1 | 176 | * Return true if this is an interface, but not an annotation type. |
duke@1 | 177 | * Overridden by AnnotationTypeDocImpl. |
duke@1 | 178 | */ |
duke@1 | 179 | public boolean isInterface() { |
duke@1 | 180 | return Modifier.isInterface(getModifiers()); |
duke@1 | 181 | } |
duke@1 | 182 | |
duke@1 | 183 | /** |
duke@1 | 184 | * Return true if this is an exception class |
duke@1 | 185 | */ |
duke@1 | 186 | public boolean isException() { |
duke@1 | 187 | if (isEnum() || isInterface() || isAnnotationType()) { |
duke@1 | 188 | return false; |
duke@1 | 189 | } |
duke@1 | 190 | for (Type t = type; t.tag == TypeTags.CLASS; t = env.types.supertype(t)) { |
duke@1 | 191 | if (t.tsym == env.syms.exceptionType.tsym) { |
duke@1 | 192 | return true; |
duke@1 | 193 | } |
duke@1 | 194 | } |
duke@1 | 195 | return false; |
duke@1 | 196 | } |
duke@1 | 197 | |
duke@1 | 198 | /** |
duke@1 | 199 | * Return true if this is an error class |
duke@1 | 200 | */ |
duke@1 | 201 | public boolean isError() { |
duke@1 | 202 | if (isEnum() || isInterface() || isAnnotationType()) { |
duke@1 | 203 | return false; |
duke@1 | 204 | } |
duke@1 | 205 | for (Type t = type; t.tag == TypeTags.CLASS; t = env.types.supertype(t)) { |
duke@1 | 206 | if (t.tsym == env.syms.errorType.tsym) { |
duke@1 | 207 | return true; |
duke@1 | 208 | } |
duke@1 | 209 | } |
duke@1 | 210 | return false; |
duke@1 | 211 | } |
duke@1 | 212 | |
duke@1 | 213 | /** |
duke@1 | 214 | * Return true if this is a throwable class |
duke@1 | 215 | */ |
duke@1 | 216 | public boolean isThrowable() { |
duke@1 | 217 | if (isEnum() || isInterface() || isAnnotationType()) { |
duke@1 | 218 | return false; |
duke@1 | 219 | } |
duke@1 | 220 | for (Type t = type; t.tag == TypeTags.CLASS; t = env.types.supertype(t)) { |
duke@1 | 221 | if (t.tsym == env.syms.throwableType.tsym) { |
duke@1 | 222 | return true; |
duke@1 | 223 | } |
duke@1 | 224 | } |
duke@1 | 225 | return false; |
duke@1 | 226 | } |
duke@1 | 227 | |
duke@1 | 228 | /** |
duke@1 | 229 | * Return true if this class is abstract |
duke@1 | 230 | */ |
duke@1 | 231 | public boolean isAbstract() { |
duke@1 | 232 | return Modifier.isAbstract(getModifiers()); |
duke@1 | 233 | } |
duke@1 | 234 | |
duke@1 | 235 | /** |
duke@1 | 236 | * Returns true if this class was synthesized by the compiler. |
duke@1 | 237 | */ |
duke@1 | 238 | public boolean isSynthetic() { |
duke@1 | 239 | return (getFlags() & Flags.SYNTHETIC) != 0; |
duke@1 | 240 | } |
duke@1 | 241 | |
duke@1 | 242 | /** |
duke@1 | 243 | * Return true if this class is included in the active set. |
duke@1 | 244 | * A ClassDoc is included iff either it is specified on the |
duke@1 | 245 | * commandline, or if it's containing package is specified |
duke@1 | 246 | * on the command line, or if it is a member class of an |
duke@1 | 247 | * included class. |
duke@1 | 248 | */ |
duke@1 | 249 | |
duke@1 | 250 | public boolean isIncluded() { |
duke@1 | 251 | if (isIncluded) { |
duke@1 | 252 | return true; |
duke@1 | 253 | } |
duke@1 | 254 | if (env.shouldDocument(tsym)) { |
duke@1 | 255 | // Class is nameable from top-level and |
duke@1 | 256 | // the class and all enclosing classes |
duke@1 | 257 | // pass the modifier filter. |
duke@1 | 258 | if (containingPackage().isIncluded()) { |
duke@1 | 259 | return isIncluded=true; |
duke@1 | 260 | } |
duke@1 | 261 | ClassDoc outer = containingClass(); |
duke@1 | 262 | if (outer != null && outer.isIncluded()) { |
duke@1 | 263 | return isIncluded=true; |
duke@1 | 264 | } |
duke@1 | 265 | } |
duke@1 | 266 | return false; |
duke@1 | 267 | } |
duke@1 | 268 | |
duke@1 | 269 | /** |
duke@1 | 270 | * Return the package that this class is contained in. |
duke@1 | 271 | */ |
duke@1 | 272 | public PackageDoc containingPackage() { |
duke@1 | 273 | PackageDocImpl p = env.getPackageDoc(tsym.packge()); |
duke@1 | 274 | SourcePosition po = position(); |
duke@1 | 275 | if (po != null && p.setDocPath == false && p.zipDocPath == null) { |
duke@1 | 276 | //Set the package path if possible |
duke@1 | 277 | File packageDir = po.file().getParentFile(); |
duke@1 | 278 | if (packageDir != null |
duke@1 | 279 | && (new File(packageDir, "package.html")).exists()) { |
duke@1 | 280 | p.setDocPath(packageDir.getPath()); |
duke@1 | 281 | } else { |
duke@1 | 282 | p.setDocPath(null); |
duke@1 | 283 | } |
duke@1 | 284 | } |
duke@1 | 285 | return p; |
duke@1 | 286 | } |
duke@1 | 287 | |
duke@1 | 288 | /** |
duke@1 | 289 | * Return the class name without package qualifier - but with |
duke@1 | 290 | * enclosing class qualifier - as a String. |
duke@1 | 291 | * <pre> |
duke@1 | 292 | * Examples: |
duke@1 | 293 | * for java.util.Hashtable |
duke@1 | 294 | * return Hashtable |
duke@1 | 295 | * for java.util.Map.Entry |
duke@1 | 296 | * return Map.Entry |
duke@1 | 297 | * </pre> |
duke@1 | 298 | */ |
duke@1 | 299 | public String name() { |
duke@1 | 300 | return getClassName(tsym, false); |
duke@1 | 301 | } |
duke@1 | 302 | |
duke@1 | 303 | /** |
duke@1 | 304 | * Return the qualified class name as a String. |
duke@1 | 305 | * <pre> |
duke@1 | 306 | * Example: |
duke@1 | 307 | * for java.util.Hashtable |
duke@1 | 308 | * return java.util.Hashtable |
duke@1 | 309 | * if no qualifier, just return flat name |
duke@1 | 310 | * </pre> |
duke@1 | 311 | */ |
duke@1 | 312 | public String qualifiedName() { |
duke@1 | 313 | return getClassName(tsym, true); |
duke@1 | 314 | } |
duke@1 | 315 | |
duke@1 | 316 | /** |
duke@1 | 317 | * Return unqualified name of type excluding any dimension information. |
duke@1 | 318 | * <p> |
duke@1 | 319 | * For example, a two dimensional array of String returns 'String'. |
duke@1 | 320 | */ |
duke@1 | 321 | public String typeName() { |
duke@1 | 322 | return name(); |
duke@1 | 323 | } |
duke@1 | 324 | |
duke@1 | 325 | /** |
duke@1 | 326 | * Return qualified name of type excluding any dimension information. |
duke@1 | 327 | *<p> |
duke@1 | 328 | * For example, a two dimensional array of String |
duke@1 | 329 | * returns 'java.lang.String'. |
duke@1 | 330 | */ |
duke@1 | 331 | public String qualifiedTypeName() { |
duke@1 | 332 | return qualifiedName(); |
duke@1 | 333 | } |
duke@1 | 334 | |
duke@1 | 335 | /** |
duke@1 | 336 | * Return the simple name of this type. |
duke@1 | 337 | */ |
duke@1 | 338 | public String simpleTypeName() { |
duke@1 | 339 | return tsym.name.toString(); |
duke@1 | 340 | } |
duke@1 | 341 | |
duke@1 | 342 | /** |
duke@1 | 343 | * Return the qualified name and any type parameters. |
duke@1 | 344 | * Each parameter is a type variable with optional bounds. |
duke@1 | 345 | */ |
duke@1 | 346 | public String toString() { |
duke@1 | 347 | return classToString(env, tsym, true); |
duke@1 | 348 | } |
duke@1 | 349 | |
duke@1 | 350 | /** |
duke@1 | 351 | * Return the class name as a string. If "full" is true the name is |
duke@1 | 352 | * qualified, otherwise it is qualified by its enclosing class(es) only. |
duke@1 | 353 | */ |
duke@1 | 354 | static String getClassName(ClassSymbol c, boolean full) { |
duke@1 | 355 | if (full) { |
duke@1 | 356 | return c.getQualifiedName().toString(); |
duke@1 | 357 | } else { |
duke@1 | 358 | String n = ""; |
duke@1 | 359 | for ( ; c != null; c = c.owner.enclClass()) { |
duke@1 | 360 | n = c.name + (n.equals("") ? "" : ".") + n; |
duke@1 | 361 | } |
duke@1 | 362 | return n; |
duke@1 | 363 | } |
duke@1 | 364 | } |
duke@1 | 365 | |
duke@1 | 366 | /** |
duke@1 | 367 | * Return the class name with any type parameters as a string. |
duke@1 | 368 | * Each parameter is a type variable with optional bounds. |
duke@1 | 369 | * If "full" is true all names are qualified, otherwise they are |
duke@1 | 370 | * qualified by their enclosing class(es) only. |
duke@1 | 371 | */ |
duke@1 | 372 | static String classToString(DocEnv env, ClassSymbol c, boolean full) { |
duke@1 | 373 | StringBuffer s = new StringBuffer(); |
duke@1 | 374 | if (!c.isInner()) { // if c is not an inner class |
duke@1 | 375 | s.append(getClassName(c, full)); |
duke@1 | 376 | } else { |
duke@1 | 377 | // c is an inner class, so include type params of outer. |
duke@1 | 378 | ClassSymbol encl = c.owner.enclClass(); |
duke@1 | 379 | s.append(classToString(env, encl, full)) |
duke@1 | 380 | .append('.') |
duke@1 | 381 | .append(c.name); |
duke@1 | 382 | } |
duke@1 | 383 | s.append(TypeMaker.typeParametersString(env, c, full)); |
duke@1 | 384 | return s.toString(); |
duke@1 | 385 | } |
duke@1 | 386 | |
duke@1 | 387 | /** |
duke@1 | 388 | * Is this class (or any enclosing class) generic? That is, does |
duke@1 | 389 | * it have type parameters? |
duke@1 | 390 | */ |
duke@1 | 391 | static boolean isGeneric(ClassSymbol c) { |
duke@1 | 392 | return c.type.allparams().nonEmpty(); |
duke@1 | 393 | } |
duke@1 | 394 | |
duke@1 | 395 | /** |
duke@1 | 396 | * Return the formal type parameters of this class or interface. |
duke@1 | 397 | * Return an empty array if there are none. |
duke@1 | 398 | */ |
duke@1 | 399 | public TypeVariable[] typeParameters() { |
duke@1 | 400 | if (env.legacyDoclet) { |
duke@1 | 401 | return new TypeVariable[0]; |
duke@1 | 402 | } |
duke@1 | 403 | TypeVariable res[] = new TypeVariable[type.getTypeArguments().length()]; |
duke@1 | 404 | TypeMaker.getTypes(env, type.getTypeArguments(), res); |
duke@1 | 405 | return res; |
duke@1 | 406 | } |
duke@1 | 407 | |
duke@1 | 408 | /** |
duke@1 | 409 | * Return the type parameter tags of this class or interface. |
duke@1 | 410 | */ |
duke@1 | 411 | public ParamTag[] typeParamTags() { |
duke@1 | 412 | return (env.legacyDoclet) |
duke@1 | 413 | ? new ParamTag[0] |
duke@1 | 414 | : comment().typeParamTags(); |
duke@1 | 415 | } |
duke@1 | 416 | |
duke@1 | 417 | /** |
duke@1 | 418 | * Return the modifier string for this class. If it's an interface |
duke@1 | 419 | * exclude 'abstract' keyword from the modifier string |
duke@1 | 420 | */ |
duke@1 | 421 | public String modifiers() { |
duke@1 | 422 | return Modifier.toString(modifierSpecifier()); |
duke@1 | 423 | } |
duke@1 | 424 | |
duke@1 | 425 | public int modifierSpecifier() { |
duke@1 | 426 | int modifiers = getModifiers(); |
duke@1 | 427 | return (isInterface() || isAnnotationType()) |
duke@1 | 428 | ? modifiers & ~Modifier.ABSTRACT |
duke@1 | 429 | : modifiers; |
duke@1 | 430 | } |
duke@1 | 431 | |
duke@1 | 432 | /** |
duke@1 | 433 | * Return the superclass of this class |
duke@1 | 434 | * |
duke@1 | 435 | * @return the ClassDocImpl for the superclass of this class, null |
duke@1 | 436 | * if there is no superclass. |
duke@1 | 437 | */ |
duke@1 | 438 | public ClassDoc superclass() { |
duke@1 | 439 | if (isInterface() || isAnnotationType()) return null; |
duke@1 | 440 | if (tsym == env.syms.objectType.tsym) return null; |
duke@1 | 441 | ClassSymbol c = (ClassSymbol)env.types.supertype(type).tsym; |
duke@1 | 442 | if (c == null || c == tsym) c = (ClassSymbol)env.syms.objectType.tsym; |
duke@1 | 443 | return env.getClassDoc(c); |
duke@1 | 444 | } |
duke@1 | 445 | |
duke@1 | 446 | /** |
duke@1 | 447 | * Return the superclass of this class. Return null if this is an |
duke@1 | 448 | * interface. A superclass is represented by either a |
duke@1 | 449 | * <code>ClassDoc</code> or a <code>ParameterizedType</code>. |
duke@1 | 450 | */ |
duke@1 | 451 | public com.sun.javadoc.Type superclassType() { |
duke@1 | 452 | if (isInterface() || isAnnotationType() || |
duke@1 | 453 | (tsym == env.syms.objectType.tsym)) |
duke@1 | 454 | return null; |
duke@1 | 455 | Type sup = env.types.supertype(type); |
duke@1 | 456 | return TypeMaker.getType(env, |
duke@1 | 457 | (sup != type) ? sup : env.syms.objectType); |
duke@1 | 458 | } |
duke@1 | 459 | |
duke@1 | 460 | /** |
duke@1 | 461 | * Test whether this class is a subclass of the specified class. |
duke@1 | 462 | * |
duke@1 | 463 | * @param cd the candidate superclass. |
duke@1 | 464 | * @return true if cd is a superclass of this class. |
duke@1 | 465 | */ |
duke@1 | 466 | public boolean subclassOf(ClassDoc cd) { |
duke@1 | 467 | return tsym.isSubClass(((ClassDocImpl)cd).tsym, env.types); |
duke@1 | 468 | } |
duke@1 | 469 | |
duke@1 | 470 | /** |
duke@1 | 471 | * Return interfaces implemented by this class or interfaces |
duke@1 | 472 | * extended by this interface. |
duke@1 | 473 | * |
duke@1 | 474 | * @return An array of ClassDocImpl representing the interfaces. |
duke@1 | 475 | * Return an empty array if there are no interfaces. |
duke@1 | 476 | */ |
duke@1 | 477 | public ClassDoc[] interfaces() { |
duke@1 | 478 | ListBuffer<ClassDocImpl> ta = new ListBuffer<ClassDocImpl>(); |
duke@1 | 479 | for (Type t : env.types.interfaces(type)) { |
duke@1 | 480 | ta.append(env.getClassDoc((ClassSymbol)t.tsym)); |
duke@1 | 481 | } |
duke@1 | 482 | //### Cache ta here? |
duke@1 | 483 | return ta.toArray(new ClassDocImpl[ta.length()]); |
duke@1 | 484 | } |
duke@1 | 485 | |
duke@1 | 486 | /** |
duke@1 | 487 | * Return interfaces implemented by this class or interfaces extended |
duke@1 | 488 | * by this interface. Includes only directly-declared interfaces, not |
duke@1 | 489 | * inherited interfaces. |
duke@1 | 490 | * Return an empty array if there are no interfaces. |
duke@1 | 491 | */ |
duke@1 | 492 | public com.sun.javadoc.Type[] interfaceTypes() { |
duke@1 | 493 | //### Cache result here? |
duke@1 | 494 | return TypeMaker.getTypes(env, env.types.interfaces(type)); |
duke@1 | 495 | } |
duke@1 | 496 | |
duke@1 | 497 | /** |
duke@1 | 498 | * Return fields in class. |
duke@1 | 499 | * @param filter include only the included fields if filter==true |
duke@1 | 500 | */ |
duke@1 | 501 | public FieldDoc[] fields(boolean filter) { |
duke@1 | 502 | return fields(filter, false); |
duke@1 | 503 | } |
duke@1 | 504 | |
duke@1 | 505 | /** |
duke@1 | 506 | * Return included fields in class. |
duke@1 | 507 | */ |
duke@1 | 508 | public FieldDoc[] fields() { |
duke@1 | 509 | return fields(true, false); |
duke@1 | 510 | } |
duke@1 | 511 | |
duke@1 | 512 | /** |
duke@1 | 513 | * Return the enum constants if this is an enum type. |
duke@1 | 514 | */ |
duke@1 | 515 | public FieldDoc[] enumConstants() { |
duke@1 | 516 | return fields(false, true); |
duke@1 | 517 | } |
duke@1 | 518 | |
duke@1 | 519 | /** |
duke@1 | 520 | * Return fields in class. |
duke@1 | 521 | * @param filter if true, return only the included fields |
duke@1 | 522 | * @param enumConstants if true, return the enum constants instead |
duke@1 | 523 | */ |
duke@1 | 524 | private FieldDoc[] fields(boolean filter, boolean enumConstants) { |
duke@1 | 525 | List<FieldDocImpl> fields = List.nil(); |
duke@1 | 526 | for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) { |
duke@1 | 527 | if (e.sym != null && e.sym.kind == VAR) { |
duke@1 | 528 | VarSymbol s = (VarSymbol)e.sym; |
duke@1 | 529 | boolean isEnum = ((s.flags() & Flags.ENUM) != 0) && |
duke@1 | 530 | !env.legacyDoclet; |
duke@1 | 531 | if (isEnum == enumConstants && |
duke@1 | 532 | (!filter || env.shouldDocument(s))) { |
duke@1 | 533 | fields = fields.prepend(env.getFieldDoc(s)); |
duke@1 | 534 | } |
duke@1 | 535 | } |
duke@1 | 536 | } |
duke@1 | 537 | return fields.toArray(new FieldDocImpl[fields.length()]); |
duke@1 | 538 | } |
duke@1 | 539 | |
duke@1 | 540 | /** |
duke@1 | 541 | * Return methods in class. |
duke@1 | 542 | * This method is overridden by AnnotationTypeDocImpl. |
duke@1 | 543 | * |
duke@1 | 544 | * @param filter include only the included methods if filter==true |
duke@1 | 545 | * @return an array of MethodDocImpl for representing the visible |
duke@1 | 546 | * methods in this class. Does not include constructors. |
duke@1 | 547 | */ |
duke@1 | 548 | public MethodDoc[] methods(boolean filter) { |
jjg@113 | 549 | Names names = tsym.name.table.names; |
duke@1 | 550 | List<MethodDocImpl> methods = List.nil(); |
duke@1 | 551 | for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) { |
duke@1 | 552 | if (e.sym != null && |
duke@1 | 553 | e.sym.kind == Kinds.MTH && e.sym.name != names.init) { |
duke@1 | 554 | MethodSymbol s = (MethodSymbol)e.sym; |
duke@1 | 555 | if (!filter || env.shouldDocument(s)) { |
duke@1 | 556 | methods = methods.prepend(env.getMethodDoc(s)); |
duke@1 | 557 | } |
duke@1 | 558 | } |
duke@1 | 559 | } |
duke@1 | 560 | //### Cache methods here? |
duke@1 | 561 | return methods.toArray(new MethodDocImpl[methods.length()]); |
duke@1 | 562 | } |
duke@1 | 563 | |
duke@1 | 564 | /** |
duke@1 | 565 | * Return included methods in class. |
duke@1 | 566 | * |
duke@1 | 567 | * @return an array of MethodDocImpl for representing the visible |
duke@1 | 568 | * methods in this class. Does not include constructors. |
duke@1 | 569 | */ |
duke@1 | 570 | public MethodDoc[] methods() { |
duke@1 | 571 | return methods(true); |
duke@1 | 572 | } |
duke@1 | 573 | |
duke@1 | 574 | /** |
duke@1 | 575 | * Return constructors in class. |
duke@1 | 576 | * |
duke@1 | 577 | * @param filter include only the included constructors if filter==true |
duke@1 | 578 | * @return an array of ConstructorDocImpl for representing the visible |
duke@1 | 579 | * constructors in this class. |
duke@1 | 580 | */ |
duke@1 | 581 | public ConstructorDoc[] constructors(boolean filter) { |
jjg@113 | 582 | Names names = tsym.name.table.names; |
duke@1 | 583 | List<ConstructorDocImpl> constructors = List.nil(); |
duke@1 | 584 | for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) { |
duke@1 | 585 | if (e.sym != null && |
duke@1 | 586 | e.sym.kind == Kinds.MTH && e.sym.name == names.init) { |
duke@1 | 587 | MethodSymbol s = (MethodSymbol)e.sym; |
duke@1 | 588 | if (!filter || env.shouldDocument(s)) { |
duke@1 | 589 | constructors = constructors.prepend(env.getConstructorDoc(s)); |
duke@1 | 590 | } |
duke@1 | 591 | } |
duke@1 | 592 | } |
duke@1 | 593 | //### Cache constructors here? |
duke@1 | 594 | return constructors.toArray(new ConstructorDocImpl[constructors.length()]); |
duke@1 | 595 | } |
duke@1 | 596 | |
duke@1 | 597 | /** |
duke@1 | 598 | * Return included constructors in class. |
duke@1 | 599 | * |
duke@1 | 600 | * @return an array of ConstructorDocImpl for representing the visible |
duke@1 | 601 | * constructors in this class. |
duke@1 | 602 | */ |
duke@1 | 603 | public ConstructorDoc[] constructors() { |
duke@1 | 604 | return constructors(true); |
duke@1 | 605 | } |
duke@1 | 606 | |
duke@1 | 607 | /** |
duke@1 | 608 | * Adds all inner classes of this class, and their |
duke@1 | 609 | * inner classes recursively, to the list l. |
duke@1 | 610 | */ |
duke@1 | 611 | void addAllClasses(ListBuffer<ClassDocImpl> l, boolean filtered) { |
duke@1 | 612 | try { |
duke@1 | 613 | if (isSynthetic()) return; |
duke@1 | 614 | // sometimes synthetic classes are not marked synthetic |
duke@1 | 615 | if (!JavadocTool.isValidClassName(tsym.name.toString())) return; |
duke@1 | 616 | if (filtered && !env.shouldDocument(tsym)) return; |
duke@1 | 617 | if (l.contains(this)) return; |
duke@1 | 618 | l.append(this); |
duke@1 | 619 | List<ClassDocImpl> more = List.nil(); |
duke@1 | 620 | for (Scope.Entry e = tsym.members().elems; e != null; |
duke@1 | 621 | e = e.sibling) { |
duke@1 | 622 | if (e.sym != null && e.sym.kind == Kinds.TYP) { |
duke@1 | 623 | ClassSymbol s = (ClassSymbol)e.sym; |
duke@1 | 624 | ClassDocImpl c = env.getClassDoc(s); |
duke@1 | 625 | if (c.isSynthetic()) continue; |
duke@1 | 626 | if (c != null) more = more.prepend(c); |
duke@1 | 627 | } |
duke@1 | 628 | } |
duke@1 | 629 | // this extra step preserves the ordering from oldjavadoc |
duke@1 | 630 | for (; more.nonEmpty(); more=more.tail) { |
duke@1 | 631 | more.head.addAllClasses(l, filtered); |
duke@1 | 632 | } |
duke@1 | 633 | } catch (CompletionFailure e) { |
duke@1 | 634 | // quietly ignore completion failures |
duke@1 | 635 | } |
duke@1 | 636 | } |
duke@1 | 637 | |
duke@1 | 638 | /** |
duke@1 | 639 | * Return inner classes within this class. |
duke@1 | 640 | * |
duke@1 | 641 | * @param filter include only the included inner classes if filter==true. |
duke@1 | 642 | * @return an array of ClassDocImpl for representing the visible |
duke@1 | 643 | * classes defined in this class. Anonymous and local classes |
duke@1 | 644 | * are not included. |
duke@1 | 645 | */ |
duke@1 | 646 | public ClassDoc[] innerClasses(boolean filter) { |
duke@1 | 647 | ListBuffer<ClassDocImpl> innerClasses = new ListBuffer<ClassDocImpl>(); |
duke@1 | 648 | for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) { |
duke@1 | 649 | if (e.sym != null && e.sym.kind == Kinds.TYP) { |
duke@1 | 650 | ClassSymbol s = (ClassSymbol)e.sym; |
duke@1 | 651 | if ((s.flags_field & Flags.SYNTHETIC) != 0) continue; |
duke@1 | 652 | if (!filter || env.isVisible(s)) { |
duke@1 | 653 | innerClasses.prepend(env.getClassDoc(s)); |
duke@1 | 654 | } |
duke@1 | 655 | } |
duke@1 | 656 | } |
duke@1 | 657 | //### Cache classes here? |
duke@1 | 658 | return innerClasses.toArray(new ClassDocImpl[innerClasses.length()]); |
duke@1 | 659 | } |
duke@1 | 660 | |
duke@1 | 661 | /** |
duke@1 | 662 | * Return included inner classes within this class. |
duke@1 | 663 | * |
duke@1 | 664 | * @return an array of ClassDocImpl for representing the visible |
duke@1 | 665 | * classes defined in this class. Anonymous and local classes |
duke@1 | 666 | * are not included. |
duke@1 | 667 | */ |
duke@1 | 668 | public ClassDoc[] innerClasses() { |
duke@1 | 669 | return innerClasses(true); |
duke@1 | 670 | } |
duke@1 | 671 | |
duke@1 | 672 | /** |
duke@1 | 673 | * Find a class within the context of this class. |
duke@1 | 674 | * Search order: qualified name, in this class (inner), |
duke@1 | 675 | * in this package, in the class imports, in the package |
duke@1 | 676 | * imports. |
duke@1 | 677 | * Return the ClassDocImpl if found, null if not found. |
duke@1 | 678 | */ |
duke@1 | 679 | //### The specified search order is not the normal rule the |
duke@1 | 680 | //### compiler would use. Leave as specified or change it? |
duke@1 | 681 | public ClassDoc findClass(String className) { |
duke@1 | 682 | ClassDoc searchResult = searchClass(className); |
duke@1 | 683 | if (searchResult == null) { |
duke@1 | 684 | ClassDocImpl enclosingClass = (ClassDocImpl)containingClass(); |
duke@1 | 685 | //Expand search space to include enclosing class. |
duke@1 | 686 | while (enclosingClass != null && enclosingClass.containingClass() != null) { |
duke@1 | 687 | enclosingClass = (ClassDocImpl)enclosingClass.containingClass(); |
duke@1 | 688 | } |
duke@1 | 689 | searchResult = enclosingClass == null ? |
duke@1 | 690 | null : enclosingClass.searchClass(className); |
duke@1 | 691 | } |
duke@1 | 692 | return searchResult; |
duke@1 | 693 | } |
duke@1 | 694 | |
duke@1 | 695 | private ClassDoc searchClass(String className) { |
jjg@113 | 696 | Names names = tsym.name.table.names; |
duke@1 | 697 | |
duke@1 | 698 | // search by qualified name first |
duke@1 | 699 | ClassDoc cd = env.lookupClass(className); |
duke@1 | 700 | if (cd != null) { |
duke@1 | 701 | return cd; |
duke@1 | 702 | } |
duke@1 | 703 | |
duke@1 | 704 | // search inner classes |
duke@1 | 705 | //### Add private entry point to avoid creating array? |
duke@1 | 706 | //### Replicate code in innerClasses here to avoid consing? |
duke@1 | 707 | ClassDoc innerClasses[] = innerClasses(); |
duke@1 | 708 | for (int i = 0; i < innerClasses.length; i++) { |
duke@1 | 709 | if (innerClasses[i].name().equals(className) || |
duke@1 | 710 | //### This is from original javadoc but it looks suspicious to me... |
duke@1 | 711 | //### I believe it is attempting to compensate for the confused |
duke@1 | 712 | //### convention of including the nested class qualifiers in the |
duke@1 | 713 | //### 'name' of the inner class, rather than the true simple name. |
duke@1 | 714 | innerClasses[i].name().endsWith(className)) { |
duke@1 | 715 | return innerClasses[i]; |
duke@1 | 716 | } else { |
duke@1 | 717 | ClassDoc innercd = ((ClassDocImpl) innerClasses[i]).searchClass(className); |
duke@1 | 718 | if (innercd != null) { |
duke@1 | 719 | return innercd; |
duke@1 | 720 | } |
duke@1 | 721 | } |
duke@1 | 722 | } |
duke@1 | 723 | |
duke@1 | 724 | // check in this package |
duke@1 | 725 | cd = containingPackage().findClass(className); |
duke@1 | 726 | if (cd != null) { |
duke@1 | 727 | return cd; |
duke@1 | 728 | } |
duke@1 | 729 | |
duke@1 | 730 | // make sure that this symbol has been completed |
duke@1 | 731 | if (tsym.completer != null) { |
duke@1 | 732 | tsym.complete(); |
duke@1 | 733 | } |
duke@1 | 734 | |
duke@1 | 735 | // search imports |
duke@1 | 736 | |
duke@1 | 737 | if (tsym.sourcefile != null) { |
duke@1 | 738 | |
duke@1 | 739 | //### This information is available only for source classes. |
duke@1 | 740 | |
duke@1 | 741 | Env<AttrContext> compenv = env.enter.getEnv(tsym); |
duke@1 | 742 | if (compenv == null) return null; |
duke@1 | 743 | |
duke@1 | 744 | Scope s = compenv.toplevel.namedImportScope; |
duke@1 | 745 | for (Scope.Entry e = s.lookup(names.fromString(className)); e.scope != null; e = e.next()) { |
duke@1 | 746 | if (e.sym.kind == Kinds.TYP) { |
duke@1 | 747 | ClassDoc c = env.getClassDoc((ClassSymbol)e.sym); |
duke@1 | 748 | return c; |
duke@1 | 749 | } |
duke@1 | 750 | } |
duke@1 | 751 | |
duke@1 | 752 | s = compenv.toplevel.starImportScope; |
duke@1 | 753 | for (Scope.Entry e = s.lookup(names.fromString(className)); e.scope != null; e = e.next()) { |
duke@1 | 754 | if (e.sym.kind == Kinds.TYP) { |
duke@1 | 755 | ClassDoc c = env.getClassDoc((ClassSymbol)e.sym); |
duke@1 | 756 | return c; |
duke@1 | 757 | } |
duke@1 | 758 | } |
duke@1 | 759 | } |
duke@1 | 760 | |
duke@1 | 761 | return null; // not found |
duke@1 | 762 | } |
duke@1 | 763 | |
duke@1 | 764 | |
duke@1 | 765 | private boolean hasParameterTypes(MethodSymbol method, String[] argTypes) { |
duke@1 | 766 | |
duke@1 | 767 | if (argTypes == null) { |
duke@1 | 768 | // wildcard |
duke@1 | 769 | return true; |
duke@1 | 770 | } |
duke@1 | 771 | |
duke@1 | 772 | int i = 0; |
duke@1 | 773 | List<Type> types = method.type.getParameterTypes(); |
duke@1 | 774 | |
duke@1 | 775 | if (argTypes.length != types.length()) { |
duke@1 | 776 | return false; |
duke@1 | 777 | } |
duke@1 | 778 | |
duke@1 | 779 | for (Type t : types) { |
duke@1 | 780 | String argType = argTypes[i++]; |
duke@1 | 781 | // For vararg method, "T..." matches type T[]. |
duke@1 | 782 | if (i == argTypes.length) { |
duke@1 | 783 | argType = argType.replace("...", "[]"); |
duke@1 | 784 | } |
duke@1 | 785 | if (!hasTypeName(env.types.erasure(t), argType)) { //###(gj) |
duke@1 | 786 | return false; |
duke@1 | 787 | } |
duke@1 | 788 | } |
duke@1 | 789 | return true; |
duke@1 | 790 | } |
duke@1 | 791 | // where |
duke@1 | 792 | private boolean hasTypeName(Type t, String name) { |
duke@1 | 793 | return |
duke@1 | 794 | name.equals(TypeMaker.getTypeName(t, true)) |
duke@1 | 795 | || |
duke@1 | 796 | name.equals(TypeMaker.getTypeName(t, false)) |
duke@1 | 797 | || |
duke@1 | 798 | (qualifiedName() + "." + name).equals(TypeMaker.getTypeName(t, true)); |
duke@1 | 799 | } |
duke@1 | 800 | |
duke@1 | 801 | |
duke@1 | 802 | |
duke@1 | 803 | /** |
duke@1 | 804 | * Find a method in this class scope. |
duke@1 | 805 | * Search order: this class, interfaces, superclasses, outerclasses. |
duke@1 | 806 | * Note that this is not necessarily what the compiler would do! |
duke@1 | 807 | * |
duke@1 | 808 | * @param methodName the unqualified name to search for. |
duke@1 | 809 | * @param paramTypeArray the array of Strings for method parameter types. |
duke@1 | 810 | * @return the first MethodDocImpl which matches, null if not found. |
duke@1 | 811 | */ |
duke@1 | 812 | public MethodDocImpl findMethod(String methodName, String[] paramTypes) { |
duke@1 | 813 | // Use hash table 'searched' to avoid searching same class twice. |
duke@1 | 814 | //### It is not clear how this could happen. |
duke@1 | 815 | return searchMethod(methodName, paramTypes, new HashSet<ClassDocImpl>()); |
duke@1 | 816 | } |
duke@1 | 817 | |
duke@1 | 818 | private MethodDocImpl searchMethod(String methodName, |
duke@1 | 819 | String[] paramTypes, Set<ClassDocImpl> searched) { |
duke@1 | 820 | //### Note that this search is not necessarily what the compiler would do! |
duke@1 | 821 | |
duke@1 | 822 | ClassDocImpl cdi; |
duke@1 | 823 | MethodDocImpl mdi; |
duke@1 | 824 | |
duke@1 | 825 | if (searched.contains(this)) { |
duke@1 | 826 | return null; |
duke@1 | 827 | } |
duke@1 | 828 | searched.add(this); |
duke@1 | 829 | |
duke@1 | 830 | //DEBUG |
duke@1 | 831 | /*---------------------------------* |
duke@1 | 832 | System.out.print("searching " + this + " for " + methodName); |
duke@1 | 833 | if (paramTypes == null) { |
duke@1 | 834 | System.out.println("()"); |
duke@1 | 835 | } else { |
duke@1 | 836 | System.out.print("("); |
duke@1 | 837 | for (int k=0; k < paramTypes.length; k++) { |
duke@1 | 838 | System.out.print(paramTypes[k]); |
duke@1 | 839 | if ((k + 1) < paramTypes.length) { |
duke@1 | 840 | System.out.print(", "); |
duke@1 | 841 | } |
duke@1 | 842 | } |
duke@1 | 843 | System.out.println(")"); |
duke@1 | 844 | } |
duke@1 | 845 | *---------------------------------*/ |
duke@1 | 846 | |
duke@1 | 847 | // search current class |
jjg@113 | 848 | Names names = tsym.name.table.names; |
duke@1 | 849 | Scope.Entry e = tsym.members().lookup(names.fromString(methodName)); |
duke@1 | 850 | |
duke@1 | 851 | //### Using modifier filter here isn't really correct, |
duke@1 | 852 | //### but emulates the old behavior. Instead, we should |
duke@1 | 853 | //### apply the normal rules of visibility and inheritance. |
duke@1 | 854 | |
duke@1 | 855 | if (paramTypes == null) { |
duke@1 | 856 | // If no parameters specified, we are allowed to return |
duke@1 | 857 | // any method with a matching name. In practice, the old |
duke@1 | 858 | // code returned the first method, which is now the last! |
duke@1 | 859 | // In order to provide textually identical results, we |
duke@1 | 860 | // attempt to emulate the old behavior. |
duke@1 | 861 | MethodSymbol lastFound = null; |
duke@1 | 862 | for (; e.scope != null; e = e.next()) { |
duke@1 | 863 | if (e.sym.kind == Kinds.MTH) { |
duke@1 | 864 | //### Should intern methodName as Name. |
duke@1 | 865 | if (e.sym.name.toString().equals(methodName)) { |
duke@1 | 866 | lastFound = (MethodSymbol)e.sym; |
duke@1 | 867 | } |
duke@1 | 868 | } |
duke@1 | 869 | } |
duke@1 | 870 | if (lastFound != null) { |
duke@1 | 871 | return env.getMethodDoc(lastFound); |
duke@1 | 872 | } |
duke@1 | 873 | } else { |
duke@1 | 874 | for (; e.scope != null; e = e.next()) { |
duke@1 | 875 | if (e.sym != null && |
duke@1 | 876 | e.sym.kind == Kinds.MTH) { |
duke@1 | 877 | //### Should intern methodName as Name. |
duke@1 | 878 | if (hasParameterTypes((MethodSymbol)e.sym, paramTypes)) { |
duke@1 | 879 | return env.getMethodDoc((MethodSymbol)e.sym); |
duke@1 | 880 | } |
duke@1 | 881 | } |
duke@1 | 882 | } |
duke@1 | 883 | } |
duke@1 | 884 | |
duke@1 | 885 | //### If we found a MethodDoc above, but which did not pass |
duke@1 | 886 | //### the modifier filter, we should return failure here! |
duke@1 | 887 | |
duke@1 | 888 | // search superclass |
duke@1 | 889 | cdi = (ClassDocImpl)superclass(); |
duke@1 | 890 | if (cdi != null) { |
duke@1 | 891 | mdi = cdi.searchMethod(methodName, paramTypes, searched); |
duke@1 | 892 | if (mdi != null) { |
duke@1 | 893 | return mdi; |
duke@1 | 894 | } |
duke@1 | 895 | } |
duke@1 | 896 | |
duke@1 | 897 | // search interfaces |
duke@1 | 898 | ClassDoc intf[] = interfaces(); |
duke@1 | 899 | for (int i = 0; i < intf.length; i++) { |
duke@1 | 900 | cdi = (ClassDocImpl)intf[i]; |
duke@1 | 901 | mdi = cdi.searchMethod(methodName, paramTypes, searched); |
duke@1 | 902 | if (mdi != null) { |
duke@1 | 903 | return mdi; |
duke@1 | 904 | } |
duke@1 | 905 | } |
duke@1 | 906 | |
duke@1 | 907 | // search enclosing class |
duke@1 | 908 | cdi = (ClassDocImpl)containingClass(); |
duke@1 | 909 | if (cdi != null) { |
duke@1 | 910 | mdi = cdi.searchMethod(methodName, paramTypes, searched); |
duke@1 | 911 | if (mdi != null) { |
duke@1 | 912 | return mdi; |
duke@1 | 913 | } |
duke@1 | 914 | } |
duke@1 | 915 | |
duke@1 | 916 | //###(gj) As a temporary measure until type variables are better |
duke@1 | 917 | //### handled, try again without the parameter types. |
duke@1 | 918 | //### This should most often find the right method, and occassionally |
duke@1 | 919 | //### find the wrong one. |
duke@1 | 920 | //if (paramTypes != null) { |
duke@1 | 921 | // return findMethod(methodName, null); |
duke@1 | 922 | //} |
duke@1 | 923 | |
duke@1 | 924 | return null; |
duke@1 | 925 | } |
duke@1 | 926 | |
duke@1 | 927 | /** |
duke@1 | 928 | * Find constructor in this class. |
duke@1 | 929 | * |
duke@1 | 930 | * @param constrName the unqualified name to search for. |
duke@1 | 931 | * @param paramTypeArray the array of Strings for constructor parameters. |
duke@1 | 932 | * @return the first ConstructorDocImpl which matches, null if not found. |
duke@1 | 933 | */ |
duke@1 | 934 | public ConstructorDoc findConstructor(String constrName, |
duke@1 | 935 | String[] paramTypes) { |
jjg@113 | 936 | Names names = tsym.name.table.names; |
duke@1 | 937 | for (Scope.Entry e = tsym.members().lookup(names.fromString("<init>")); e.scope != null; e = e.next()) { |
duke@1 | 938 | if (e.sym.kind == Kinds.MTH) { |
duke@1 | 939 | if (hasParameterTypes((MethodSymbol)e.sym, paramTypes)) { |
duke@1 | 940 | return env.getConstructorDoc((MethodSymbol)e.sym); |
duke@1 | 941 | } |
duke@1 | 942 | } |
duke@1 | 943 | } |
duke@1 | 944 | |
duke@1 | 945 | //###(gj) As a temporary measure until type variables are better |
duke@1 | 946 | //### handled, try again without the parameter types. |
duke@1 | 947 | //### This will often find the right constructor, and occassionally |
duke@1 | 948 | //### find the wrong one. |
duke@1 | 949 | //if (paramTypes != null) { |
duke@1 | 950 | // return findConstructor(constrName, null); |
duke@1 | 951 | //} |
duke@1 | 952 | |
duke@1 | 953 | return null; |
duke@1 | 954 | } |
duke@1 | 955 | |
duke@1 | 956 | /** |
duke@1 | 957 | * Find a field in this class scope. |
duke@1 | 958 | * Search order: this class, outerclasses, interfaces, |
duke@1 | 959 | * superclasses. IMP: If see tag is defined in an inner class, |
duke@1 | 960 | * which extends a super class and if outerclass and the super |
duke@1 | 961 | * class have a visible field in common then Java compiler cribs |
duke@1 | 962 | * about the ambiguity, but the following code will search in the |
duke@1 | 963 | * above given search order. |
duke@1 | 964 | * |
duke@1 | 965 | * @param fieldName the unqualified name to search for. |
duke@1 | 966 | * @return the first FieldDocImpl which matches, null if not found. |
duke@1 | 967 | */ |
duke@1 | 968 | public FieldDoc findField(String fieldName) { |
duke@1 | 969 | return searchField(fieldName, new HashSet<ClassDocImpl>()); |
duke@1 | 970 | } |
duke@1 | 971 | |
duke@1 | 972 | private FieldDocImpl searchField(String fieldName, Set<ClassDocImpl> searched) { |
jjg@113 | 973 | Names names = tsym.name.table.names; |
duke@1 | 974 | if (searched.contains(this)) { |
duke@1 | 975 | return null; |
duke@1 | 976 | } |
duke@1 | 977 | searched.add(this); |
duke@1 | 978 | |
duke@1 | 979 | for (Scope.Entry e = tsym.members().lookup(names.fromString(fieldName)); e.scope != null; e = e.next()) { |
duke@1 | 980 | if (e.sym.kind == Kinds.VAR) { |
duke@1 | 981 | //### Should intern fieldName as Name. |
duke@1 | 982 | return env.getFieldDoc((VarSymbol)e.sym); |
duke@1 | 983 | } |
duke@1 | 984 | } |
duke@1 | 985 | |
duke@1 | 986 | //### If we found a FieldDoc above, but which did not pass |
duke@1 | 987 | //### the modifier filter, we should return failure here! |
duke@1 | 988 | |
duke@1 | 989 | ClassDocImpl cdi = (ClassDocImpl)containingClass(); |
duke@1 | 990 | if (cdi != null) { |
duke@1 | 991 | FieldDocImpl fdi = cdi.searchField(fieldName, searched); |
duke@1 | 992 | if (fdi != null) { |
duke@1 | 993 | return fdi; |
duke@1 | 994 | } |
duke@1 | 995 | } |
duke@1 | 996 | |
duke@1 | 997 | // search superclass |
duke@1 | 998 | cdi = (ClassDocImpl)superclass(); |
duke@1 | 999 | if (cdi != null) { |
duke@1 | 1000 | FieldDocImpl fdi = cdi.searchField(fieldName, searched); |
duke@1 | 1001 | if (fdi != null) { |
duke@1 | 1002 | return fdi; |
duke@1 | 1003 | } |
duke@1 | 1004 | } |
duke@1 | 1005 | |
duke@1 | 1006 | // search interfaces |
duke@1 | 1007 | ClassDoc intf[] = interfaces(); |
duke@1 | 1008 | for (int i = 0; i < intf.length; i++) { |
duke@1 | 1009 | cdi = (ClassDocImpl)intf[i]; |
duke@1 | 1010 | FieldDocImpl fdi = cdi.searchField(fieldName, searched); |
duke@1 | 1011 | if (fdi != null) { |
duke@1 | 1012 | return fdi; |
duke@1 | 1013 | } |
duke@1 | 1014 | } |
duke@1 | 1015 | |
duke@1 | 1016 | return null; |
duke@1 | 1017 | } |
duke@1 | 1018 | |
duke@1 | 1019 | /** |
duke@1 | 1020 | * Get the list of classes declared as imported. |
duke@1 | 1021 | * These are called "single-type-import declarations" in the JLS. |
duke@1 | 1022 | * This method is deprecated in the ClassDoc interface. |
duke@1 | 1023 | * |
duke@1 | 1024 | * @return an array of ClassDocImpl representing the imported classes. |
duke@1 | 1025 | * |
duke@1 | 1026 | * @deprecated Import declarations are implementation details that |
duke@1 | 1027 | * should not be exposed here. In addition, not all imported |
duke@1 | 1028 | * classes are imported through single-type-import declarations. |
duke@1 | 1029 | */ |
duke@1 | 1030 | @Deprecated |
duke@1 | 1031 | public ClassDoc[] importedClasses() { |
duke@1 | 1032 | // information is not available for binary classfiles |
duke@1 | 1033 | if (tsym.sourcefile == null) return new ClassDoc[0]; |
duke@1 | 1034 | |
duke@1 | 1035 | ListBuffer<ClassDocImpl> importedClasses = new ListBuffer<ClassDocImpl>(); |
duke@1 | 1036 | |
duke@1 | 1037 | Env<AttrContext> compenv = env.enter.getEnv(tsym); |
duke@1 | 1038 | if (compenv == null) return new ClassDocImpl[0]; |
duke@1 | 1039 | |
jjg@113 | 1040 | Name asterisk = tsym.name.table.names.asterisk; |
duke@1 | 1041 | for (JCTree t : compenv.toplevel.defs) { |
duke@1 | 1042 | if (t.getTag() == JCTree.IMPORT) { |
duke@1 | 1043 | JCTree imp = ((JCImport) t).qualid; |
duke@1 | 1044 | if ((TreeInfo.name(imp) != asterisk) && |
duke@1 | 1045 | (imp.type.tsym.kind & Kinds.TYP) != 0) { |
duke@1 | 1046 | importedClasses.append( |
duke@1 | 1047 | env.getClassDoc((ClassSymbol)imp.type.tsym)); |
duke@1 | 1048 | } |
duke@1 | 1049 | } |
duke@1 | 1050 | } |
duke@1 | 1051 | |
duke@1 | 1052 | return importedClasses.toArray(new ClassDocImpl[importedClasses.length()]); |
duke@1 | 1053 | } |
duke@1 | 1054 | |
duke@1 | 1055 | /** |
duke@1 | 1056 | * Get the list of packages declared as imported. |
duke@1 | 1057 | * These are called "type-import-on-demand declarations" in the JLS. |
duke@1 | 1058 | * This method is deprecated in the ClassDoc interface. |
duke@1 | 1059 | * |
duke@1 | 1060 | * @return an array of PackageDocImpl representing the imported packages. |
duke@1 | 1061 | * |
duke@1 | 1062 | * ###NOTE: the syntax supports importing all inner classes from a class as well. |
duke@1 | 1063 | * @deprecated Import declarations are implementation details that |
duke@1 | 1064 | * should not be exposed here. In addition, this method's |
duke@1 | 1065 | * return type does not allow for all type-import-on-demand |
duke@1 | 1066 | * declarations to be returned. |
duke@1 | 1067 | */ |
duke@1 | 1068 | @Deprecated |
duke@1 | 1069 | public PackageDoc[] importedPackages() { |
duke@1 | 1070 | // information is not available for binary classfiles |
duke@1 | 1071 | if (tsym.sourcefile == null) return new PackageDoc[0]; |
duke@1 | 1072 | |
duke@1 | 1073 | ListBuffer<PackageDocImpl> importedPackages = new ListBuffer<PackageDocImpl>(); |
duke@1 | 1074 | |
duke@1 | 1075 | //### Add the implicit "import java.lang.*" to the result |
jjg@113 | 1076 | Names names = tsym.name.table.names; |
duke@1 | 1077 | importedPackages.append(env.getPackageDoc(env.reader.enterPackage(names.java_lang))); |
duke@1 | 1078 | |
duke@1 | 1079 | Env<AttrContext> compenv = env.enter.getEnv(tsym); |
duke@1 | 1080 | if (compenv == null) return new PackageDocImpl[0]; |
duke@1 | 1081 | |
duke@1 | 1082 | for (JCTree t : compenv.toplevel.defs) { |
duke@1 | 1083 | if (t.getTag() == JCTree.IMPORT) { |
duke@1 | 1084 | JCTree imp = ((JCImport) t).qualid; |
duke@1 | 1085 | if (TreeInfo.name(imp) == names.asterisk) { |
duke@1 | 1086 | JCFieldAccess sel = (JCFieldAccess)imp; |
duke@1 | 1087 | Symbol s = sel.selected.type.tsym; |
duke@1 | 1088 | PackageDocImpl pdoc = env.getPackageDoc(s.packge()); |
duke@1 | 1089 | if (!importedPackages.contains(pdoc)) |
duke@1 | 1090 | importedPackages.append(pdoc); |
duke@1 | 1091 | } |
duke@1 | 1092 | } |
duke@1 | 1093 | } |
duke@1 | 1094 | |
duke@1 | 1095 | return importedPackages.toArray(new PackageDocImpl[importedPackages.length()]); |
duke@1 | 1096 | } |
duke@1 | 1097 | |
duke@1 | 1098 | /** |
duke@1 | 1099 | * Return the type's dimension information. |
duke@1 | 1100 | * Always return "", as this is not an array type. |
duke@1 | 1101 | */ |
duke@1 | 1102 | public String dimension() { |
duke@1 | 1103 | return ""; |
duke@1 | 1104 | } |
duke@1 | 1105 | |
duke@1 | 1106 | /** |
duke@1 | 1107 | * Return this type as a class, which it already is. |
duke@1 | 1108 | */ |
duke@1 | 1109 | public ClassDoc asClassDoc() { |
duke@1 | 1110 | return this; |
duke@1 | 1111 | } |
duke@1 | 1112 | |
duke@1 | 1113 | /** |
duke@1 | 1114 | * Return null (unless overridden), as this is not an annotation type. |
duke@1 | 1115 | */ |
duke@1 | 1116 | public AnnotationTypeDoc asAnnotationTypeDoc() { |
duke@1 | 1117 | return null; |
duke@1 | 1118 | } |
duke@1 | 1119 | |
duke@1 | 1120 | /** |
duke@1 | 1121 | * Return null, as this is not a class instantiation. |
duke@1 | 1122 | */ |
duke@1 | 1123 | public ParameterizedType asParameterizedType() { |
duke@1 | 1124 | return null; |
duke@1 | 1125 | } |
duke@1 | 1126 | |
duke@1 | 1127 | /** |
duke@1 | 1128 | * Return null, as this is not a type variable. |
duke@1 | 1129 | */ |
duke@1 | 1130 | public TypeVariable asTypeVariable() { |
duke@1 | 1131 | return null; |
duke@1 | 1132 | } |
duke@1 | 1133 | |
duke@1 | 1134 | /** |
duke@1 | 1135 | * Return null, as this is not a wildcard type. |
duke@1 | 1136 | */ |
duke@1 | 1137 | public WildcardType asWildcardType() { |
duke@1 | 1138 | return null; |
duke@1 | 1139 | } |
duke@1 | 1140 | |
duke@1 | 1141 | /** |
duke@1 | 1142 | * Return false, as this is not a primitive type. |
duke@1 | 1143 | */ |
duke@1 | 1144 | public boolean isPrimitive() { |
duke@1 | 1145 | return false; |
duke@1 | 1146 | } |
duke@1 | 1147 | |
duke@1 | 1148 | //--- Serialization --- |
duke@1 | 1149 | |
duke@1 | 1150 | //### These methods ignore modifier filter. |
duke@1 | 1151 | |
duke@1 | 1152 | /** |
duke@1 | 1153 | * Return true if this class implements <code>java.io.Serializable</code>. |
duke@1 | 1154 | * |
duke@1 | 1155 | * Since <code>java.io.Externalizable</code> extends |
duke@1 | 1156 | * <code>java.io.Serializable</code>, |
duke@1 | 1157 | * Externalizable objects are also Serializable. |
duke@1 | 1158 | */ |
duke@1 | 1159 | public boolean isSerializable() { |
duke@1 | 1160 | try { |
duke@1 | 1161 | return env.types.isSubtype(type, env.syms.serializableType); |
duke@1 | 1162 | } catch (CompletionFailure ex) { |
duke@1 | 1163 | // quietly ignore completion failures |
duke@1 | 1164 | return false; |
duke@1 | 1165 | } |
duke@1 | 1166 | } |
duke@1 | 1167 | |
duke@1 | 1168 | /** |
duke@1 | 1169 | * Return true if this class implements |
duke@1 | 1170 | * <code>java.io.Externalizable</code>. |
duke@1 | 1171 | */ |
duke@1 | 1172 | public boolean isExternalizable() { |
duke@1 | 1173 | try { |
duke@1 | 1174 | return env.types.isSubtype(type, env.externalizableSym.type); |
duke@1 | 1175 | } catch (CompletionFailure ex) { |
duke@1 | 1176 | // quietly ignore completion failures |
duke@1 | 1177 | return false; |
duke@1 | 1178 | } |
duke@1 | 1179 | } |
duke@1 | 1180 | |
duke@1 | 1181 | /** |
duke@1 | 1182 | * Return the serialization methods for this class. |
duke@1 | 1183 | * |
duke@1 | 1184 | * @return an array of <code>MethodDocImpl</code> that represents |
duke@1 | 1185 | * the serialization methods for this class. |
duke@1 | 1186 | */ |
duke@1 | 1187 | public MethodDoc[] serializationMethods() { |
duke@1 | 1188 | if (serializedForm == null) { |
duke@1 | 1189 | serializedForm = new SerializedForm(env, tsym, this); |
duke@1 | 1190 | } |
duke@1 | 1191 | //### Clone this? |
duke@1 | 1192 | return serializedForm.methods(); |
duke@1 | 1193 | } |
duke@1 | 1194 | |
duke@1 | 1195 | /** |
duke@1 | 1196 | * Return the Serializable fields of class.<p> |
duke@1 | 1197 | * |
duke@1 | 1198 | * Return either a list of default fields documented by |
duke@1 | 1199 | * <code>serial</code> tag<br> |
duke@1 | 1200 | * or return a single <code>FieldDoc</code> for |
duke@1 | 1201 | * <code>serialPersistentField</code> member. |
duke@1 | 1202 | * There should be a <code>serialField</code> tag for |
duke@1 | 1203 | * each Serializable field defined by an <code>ObjectStreamField</code> |
duke@1 | 1204 | * array component of <code>serialPersistentField</code>. |
duke@1 | 1205 | * |
duke@1 | 1206 | * @returns an array of <code>FieldDoc</code> for the Serializable fields |
duke@1 | 1207 | * of this class. |
duke@1 | 1208 | * |
duke@1 | 1209 | * @see #definesSerializableFields() |
duke@1 | 1210 | * @see SerialFieldTagImpl |
duke@1 | 1211 | */ |
duke@1 | 1212 | public FieldDoc[] serializableFields() { |
duke@1 | 1213 | if (serializedForm == null) { |
duke@1 | 1214 | serializedForm = new SerializedForm(env, tsym, this); |
duke@1 | 1215 | } |
duke@1 | 1216 | //### Clone this? |
duke@1 | 1217 | return serializedForm.fields(); |
duke@1 | 1218 | } |
duke@1 | 1219 | |
duke@1 | 1220 | /** |
duke@1 | 1221 | * Return true if Serializable fields are explicitly defined with |
duke@1 | 1222 | * the special class member <code>serialPersistentFields</code>. |
duke@1 | 1223 | * |
duke@1 | 1224 | * @see #serializableFields() |
duke@1 | 1225 | * @see SerialFieldTagImpl |
duke@1 | 1226 | */ |
duke@1 | 1227 | public boolean definesSerializableFields() { |
duke@1 | 1228 | if (!isSerializable() || isExternalizable()) { |
duke@1 | 1229 | return false; |
duke@1 | 1230 | } else { |
duke@1 | 1231 | if (serializedForm == null) { |
duke@1 | 1232 | serializedForm = new SerializedForm(env, tsym, this); |
duke@1 | 1233 | } |
duke@1 | 1234 | //### Clone this? |
duke@1 | 1235 | return serializedForm.definesSerializableFields(); |
duke@1 | 1236 | } |
duke@1 | 1237 | } |
duke@1 | 1238 | |
duke@1 | 1239 | /** |
duke@1 | 1240 | * Determine if a class is a RuntimeException. |
duke@1 | 1241 | * <p> |
duke@1 | 1242 | * Used only by ThrowsTagImpl. |
duke@1 | 1243 | */ |
duke@1 | 1244 | boolean isRuntimeException() { |
duke@1 | 1245 | return tsym.isSubClass(env.syms.runtimeExceptionType.tsym, env.types); |
duke@1 | 1246 | } |
duke@1 | 1247 | |
duke@1 | 1248 | /** |
duke@1 | 1249 | * Return the source position of the entity, or null if |
duke@1 | 1250 | * no position is available. |
duke@1 | 1251 | */ |
duke@1 | 1252 | public SourcePosition position() { |
duke@1 | 1253 | if (tsym.sourcefile == null) return null; |
duke@1 | 1254 | return SourcePositionImpl.make(tsym.sourcefile.toString(), |
duke@1 | 1255 | (tree==null) ? Position.NOPOS : tree.pos, |
duke@1 | 1256 | lineMap); |
duke@1 | 1257 | } |
duke@1 | 1258 | } |