45 import com.sun.tools.javac.tree.JCTree; |
45 import com.sun.tools.javac.tree.JCTree; |
46 import com.sun.tools.javac.tree.JCTree.*; |
46 import com.sun.tools.javac.tree.JCTree.*; |
47 import com.sun.tools.javac.tree.TreeInfo; |
47 import com.sun.tools.javac.tree.TreeInfo; |
48 import com.sun.tools.javac.tree.TreeScanner; |
48 import com.sun.tools.javac.tree.TreeScanner; |
49 import com.sun.tools.javac.util.*; |
49 import com.sun.tools.javac.util.*; |
|
50 import com.sun.tools.javac.util.DefinedBy.Api; |
50 import com.sun.tools.javac.util.Name; |
51 import com.sun.tools.javac.util.Name; |
51 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
52 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
52 import static com.sun.tools.javac.code.TypeTag.CLASS; |
53 import static com.sun.tools.javac.code.TypeTag.CLASS; |
53 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
54 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
54 |
55 |
82 names = Names.instance(context); |
83 names = Names.instance(context); |
83 types = Types.instance(context); |
84 types = Types.instance(context); |
84 enter = Enter.instance(context); |
85 enter = Enter.instance(context); |
85 } |
86 } |
86 |
87 |
|
88 @DefinedBy(Api.LANGUAGE_MODEL) |
87 public PackageSymbol getPackageElement(CharSequence name) { |
89 public PackageSymbol getPackageElement(CharSequence name) { |
88 String strName = name.toString(); |
90 String strName = name.toString(); |
89 if (strName.equals("")) |
91 if (strName.equals("")) |
90 return syms.unnamedPackage; |
92 return syms.unnamedPackage; |
91 return SourceVersion.isName(strName) |
93 return SourceVersion.isName(strName) |
92 ? nameToSymbol(strName, PackageSymbol.class) |
94 ? nameToSymbol(strName, PackageSymbol.class) |
93 : null; |
95 : null; |
94 } |
96 } |
95 |
97 |
|
98 @DefinedBy(Api.LANGUAGE_MODEL) |
96 public ClassSymbol getTypeElement(CharSequence name) { |
99 public ClassSymbol getTypeElement(CharSequence name) { |
97 String strName = name.toString(); |
100 String strName = name.toString(); |
98 return SourceVersion.isName(strName) |
101 return SourceVersion.isName(strName) |
99 ? nameToSymbol(strName, ClassSymbol.class) |
102 ? nameToSymbol(strName, ClassSymbol.class) |
100 : null; |
103 : null; |
306 public JCTree getTree(Element e) { |
309 public JCTree getTree(Element e) { |
307 Pair<JCTree, ?> treeTop = getTreeAndTopLevel(e); |
310 Pair<JCTree, ?> treeTop = getTreeAndTopLevel(e); |
308 return (treeTop != null) ? treeTop.fst : null; |
311 return (treeTop != null) ? treeTop.fst : null; |
309 } |
312 } |
310 |
313 |
|
314 @DefinedBy(Api.LANGUAGE_MODEL) |
311 public String getDocComment(Element e) { |
315 public String getDocComment(Element e) { |
312 // Our doc comment is contained in a map in our toplevel, |
316 // Our doc comment is contained in a map in our toplevel, |
313 // indexed by our tree. Find our enter environment, which gives |
317 // indexed by our tree. Find our enter environment, which gives |
314 // us our toplevel. It also gives us a tree that contains our |
318 // us our toplevel. It also gives us a tree that contains our |
315 // tree: walk it to find our tree. This is painful. |
319 // tree: walk it to find our tree. This is painful. |
321 if (toplevel.docComments == null) |
325 if (toplevel.docComments == null) |
322 return null; |
326 return null; |
323 return toplevel.docComments.getCommentText(tree); |
327 return toplevel.docComments.getCommentText(tree); |
324 } |
328 } |
325 |
329 |
|
330 @DefinedBy(Api.LANGUAGE_MODEL) |
326 public PackageElement getPackageOf(Element e) { |
331 public PackageElement getPackageOf(Element e) { |
327 return cast(Symbol.class, e).packge(); |
332 return cast(Symbol.class, e).packge(); |
328 } |
333 } |
329 |
334 |
|
335 @DefinedBy(Api.LANGUAGE_MODEL) |
330 public boolean isDeprecated(Element e) { |
336 public boolean isDeprecated(Element e) { |
331 Symbol sym = cast(Symbol.class, e); |
337 Symbol sym = cast(Symbol.class, e); |
332 return (sym.flags() & Flags.DEPRECATED) != 0; |
338 return (sym.flags() & Flags.DEPRECATED) != 0; |
333 } |
339 } |
334 |
340 |
|
341 @DefinedBy(Api.LANGUAGE_MODEL) |
335 public Name getBinaryName(TypeElement type) { |
342 public Name getBinaryName(TypeElement type) { |
336 return cast(TypeSymbol.class, type).flatName(); |
343 return cast(TypeSymbol.class, type).flatName(); |
337 } |
344 } |
338 |
345 |
|
346 @DefinedBy(Api.LANGUAGE_MODEL) |
339 public Map<MethodSymbol, Attribute> getElementValuesWithDefaults( |
347 public Map<MethodSymbol, Attribute> getElementValuesWithDefaults( |
340 AnnotationMirror a) { |
348 AnnotationMirror a) { |
341 Attribute.Compound anno = cast(Attribute.Compound.class, a); |
349 Attribute.Compound anno = cast(Attribute.Compound.class, a); |
342 DeclaredType annotype = a.getAnnotationType(); |
350 DeclaredType annotype = a.getAnnotationType(); |
343 Map<MethodSymbol, Attribute> valmap = anno.getElementValues(); |
351 Map<MethodSymbol, Attribute> valmap = anno.getElementValues(); |
354 } |
362 } |
355 |
363 |
356 /** |
364 /** |
357 * {@inheritDoc} |
365 * {@inheritDoc} |
358 */ |
366 */ |
|
367 @DefinedBy(Api.LANGUAGE_MODEL) |
359 public FilteredMemberList getAllMembers(TypeElement element) { |
368 public FilteredMemberList getAllMembers(TypeElement element) { |
360 Symbol sym = cast(Symbol.class, element); |
369 Symbol sym = cast(Symbol.class, element); |
361 WriteableScope scope = sym.members().dupUnshared(); |
370 WriteableScope scope = sym.members().dupUnshared(); |
362 List<Type> closure = types.closure(sym.asType()); |
371 List<Type> closure = types.closure(sym.asType()); |
363 for (Type t : closure) |
372 for (Type t : closure) |
391 * inherited or directly present. |
400 * inherited or directly present. |
392 * |
401 * |
393 * @param e the element being examined |
402 * @param e the element being examined |
394 * @return all annotations of the element |
403 * @return all annotations of the element |
395 */ |
404 */ |
396 @Override |
405 @Override @DefinedBy(Api.LANGUAGE_MODEL) |
397 public List<Attribute.Compound> getAllAnnotationMirrors(Element e) { |
406 public List<Attribute.Compound> getAllAnnotationMirrors(Element e) { |
398 Symbol sym = cast(Symbol.class, e); |
407 Symbol sym = cast(Symbol.class, e); |
399 List<Attribute.Compound> annos = sym.getAnnotationMirrors(); |
408 List<Attribute.Compound> annos = sym.getAnnotationMirrors(); |
400 while (sym.getKind() == ElementKind.CLASS) { |
409 while (sym.getKind() == ElementKind.CLASS) { |
401 Type sup = ((ClassSymbol) sym).getSuperclass(); |
410 Type sup = ((ClassSymbol) sym).getSuperclass(); |
434 return true; |
443 return true; |
435 } |
444 } |
436 return false; |
445 return false; |
437 } |
446 } |
438 |
447 |
|
448 @DefinedBy(Api.LANGUAGE_MODEL) |
439 public boolean hides(Element hiderEl, Element hideeEl) { |
449 public boolean hides(Element hiderEl, Element hideeEl) { |
440 Symbol hider = cast(Symbol.class, hiderEl); |
450 Symbol hider = cast(Symbol.class, hiderEl); |
441 Symbol hidee = cast(Symbol.class, hideeEl); |
451 Symbol hidee = cast(Symbol.class, hideeEl); |
442 |
452 |
443 // Fields only hide fields; methods only methods; types only types. |
453 // Fields only hide fields; methods only methods; types only types. |
470 // Hidee must be accessible in hider's class. |
480 // Hidee must be accessible in hider's class. |
471 // The method isInheritedIn is poorly named: it checks only access. |
481 // The method isInheritedIn is poorly named: it checks only access. |
472 return hidee.isInheritedIn(hiderClass, types); |
482 return hidee.isInheritedIn(hiderClass, types); |
473 } |
483 } |
474 |
484 |
|
485 @DefinedBy(Api.LANGUAGE_MODEL) |
475 public boolean overrides(ExecutableElement riderEl, |
486 public boolean overrides(ExecutableElement riderEl, |
476 ExecutableElement rideeEl, TypeElement typeEl) { |
487 ExecutableElement rideeEl, TypeElement typeEl) { |
477 MethodSymbol rider = cast(MethodSymbol.class, riderEl); |
488 MethodSymbol rider = cast(MethodSymbol.class, riderEl); |
478 MethodSymbol ridee = cast(MethodSymbol.class, rideeEl); |
489 MethodSymbol ridee = cast(MethodSymbol.class, rideeEl); |
479 ClassSymbol origin = cast(ClassSymbol.class, typeEl); |
490 ClassSymbol origin = cast(ClassSymbol.class, typeEl); |
492 |
503 |
493 // check access and signatures; don't check return types |
504 // check access and signatures; don't check return types |
494 rider.overrides(ridee, origin, types, false); |
505 rider.overrides(ridee, origin, types, false); |
495 } |
506 } |
496 |
507 |
|
508 @DefinedBy(Api.LANGUAGE_MODEL) |
497 public String getConstantExpression(Object value) { |
509 public String getConstantExpression(Object value) { |
498 return Constants.format(value); |
510 return Constants.format(value); |
499 } |
511 } |
500 |
512 |
501 /** |
513 /** |
505 * specified and is subject to change. |
517 * specified and is subject to change. |
506 * |
518 * |
507 * @param w the writer to print the output to |
519 * @param w the writer to print the output to |
508 * @param elements the elements to print |
520 * @param elements the elements to print |
509 */ |
521 */ |
|
522 @DefinedBy(Api.LANGUAGE_MODEL) |
510 public void printElements(java.io.Writer w, Element... elements) { |
523 public void printElements(java.io.Writer w, Element... elements) { |
511 for (Element element : elements) |
524 for (Element element : elements) |
512 (new PrintingProcessor.PrintingElementVisitor(w, this)).visit(element).flush(); |
525 (new PrintingProcessor.PrintingElementVisitor(w, this)).visit(element).flush(); |
513 } |
526 } |
514 |
527 |
|
528 @DefinedBy(Api.LANGUAGE_MODEL) |
515 public Name getName(CharSequence cs) { |
529 public Name getName(CharSequence cs) { |
516 return names.fromString(cs.toString()); |
530 return names.fromString(cs.toString()); |
517 } |
531 } |
518 |
532 |
519 @Override |
533 @Override @DefinedBy(Api.LANGUAGE_MODEL) |
520 public boolean isFunctionalInterface(TypeElement element) { |
534 public boolean isFunctionalInterface(TypeElement element) { |
521 if (element.getKind() != ElementKind.INTERFACE) |
535 if (element.getKind() != ElementKind.INTERFACE) |
522 return false; |
536 return false; |
523 else { |
537 else { |
524 TypeSymbol tsym = cast(TypeSymbol.class, element); |
538 TypeSymbol tsym = cast(TypeSymbol.class, element); |