|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.tools.javac.model.JavacElements
public class JavacElements
Utility methods for operating on program elements.
This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
| Field Summary | |
|---|---|
private Enter |
enter
|
private JavaCompiler |
javaCompiler
|
private static Context.Key<JavacElements> |
KEY
|
private Names |
names
|
private Symtab |
syms
|
private Types |
types
|
| Constructor Summary | |
|---|---|
JavacElements(Context context)
Public for use only by JavacProcessingEnvironment |
|
| Method Summary | ||
|---|---|---|
private void |
addMembers(Scope scope,
Type type)
|
|
private static
|
cast(java.lang.Class<T> clazz,
java.lang.Object o)
Returns an object cast to the specified type. |
|
private static boolean |
containsAnnoOfType(List<Attribute.Compound> annos,
Type type)
Tests whether a list of annotations contains an annotation of a given type. |
|
List<Attribute.Compound> |
getAllAnnotationMirrors(Element e)
Returns all annotations of an element, whether inherited or directly present. |
|
FilteredMemberList |
getAllMembers(TypeElement element)
Returns all members of a type element, whether inherited or declared directly. |
|
static
|
getAnnotation(Symbol.ClassSymbol annotated,
java.lang.Class<A> annoType)
An internal-use utility that creates a reified annotation. |
|
static
|
getAnnotation(Symbol annotated,
java.lang.Class<A> annoType)
An internal-use utility that creates a reified annotation. |
|
Name |
getBinaryName(TypeElement type)
Returns the binary name of a type element. |
|
java.lang.String |
getConstantExpression(java.lang.Object value)
Returns the text of a constant expression representing a primitive value or a string. |
|
java.lang.String |
getDocComment(Element e)
Returns the text of the documentation ("Javadoc") comment of an element. |
|
java.util.Map<Symbol.MethodSymbol,Attribute> |
getElementValuesWithDefaults(AnnotationMirror a)
Returns the values of an annotation's elements, including defaults. |
|
private Env<AttrContext> |
getEnterEnv(Symbol sym)
Returns a symbol's enter environment, or null if it has none. |
|
Name |
getName(java.lang.CharSequence cs)
Return a name with the same sequence of characters as the argument. |
|
Symbol.PackageSymbol |
getPackageElement(java.lang.CharSequence name)
Returns a package given its fully qualified name. |
|
PackageElement |
getPackageOf(Element e)
Returns the package of an element. |
|
JavacSourcePosition |
getSourcePosition(Element e)
|
|
JavacSourcePosition |
getSourcePosition(Element e,
AnnotationMirror a)
|
|
JavacSourcePosition |
getSourcePosition(Element e,
AnnotationMirror a,
AnnotationValue v)
|
|
JCTree |
getTree(Element e)
Returns the tree node corresponding to this element, or null if none can be found. |
|
private Pair<JCTree,JCTree.JCCompilationUnit> |
getTreeAndTopLevel(Element e)
Returns the tree node and compilation unit corresponding to this element, or null if they can't be found. |
|
Pair<JCTree,JCTree.JCCompilationUnit> |
getTreeAndTopLevel(Element e,
AnnotationMirror a,
AnnotationValue v)
Returns the best approximation for the tree node and compilation unit corresponding to the given element, annotation and value. |
|
Symbol.ClassSymbol |
getTypeElement(java.lang.CharSequence name)
Returns a type element given its canonical name. |
|
boolean |
hides(Element hiderEl,
Element hideeEl)
Tests whether one type, method, or field hides another. |
|
static JavacElements |
instance(Context context)
|
|
boolean |
isDeprecated(Element e)
Returns true if the element is deprecated, false otherwise. |
|
private boolean |
isInherited(Type annotype)
Tests whether an annotation type is @Inherited. |
|
private JCTree |
matchAnnoToTree(AnnotationMirror findme,
Element e,
JCTree tree)
Returns the tree for an annotation given the annotated element and the element's own tree. |
|
private JCTree |
matchAnnoToTree(Attribute.Compound findme,
Attribute attr,
JCTree tree)
Returns the tree for an annotation given an Attribute to search (recursively) and its corresponding tree. |
|
private JCTree |
matchAnnoToTree(Attribute.Compound findme,
List<Attribute.Compound> annos,
List<JCTree.JCAnnotation> trees)
Returns the tree for an annotation given a list of annotations in which to search (recursively) and their corresponding trees. |
|
private
|
nameToSymbol(java.lang.String nameStr,
java.lang.Class<S> clazz)
Returns a symbol given the type's or packages's canonical name, or null if the name isn't found. |
|
boolean |
overrides(ExecutableElement riderEl,
ExecutableElement rideeEl,
TypeElement typeEl)
Tests whether one method, as a member of a given type, overrides another method. |
|
void |
printElements(java.io.Writer w,
Element... elements)
Print a representation of the elements to the given writer in the specified order. |
|
private JCTree.JCExpression |
scanForAssign(Symbol.MethodSymbol sym,
JCTree tree)
Scans for a JCAssign node with a LHS matching a given symbol, and returns its RHS. |
|
void |
setContext(Context context)
Use a new context. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private JavaCompiler javaCompiler
private Symtab syms
private Names names
private Types types
private Enter enter
private static final Context.Key<JavacElements> KEY
| Constructor Detail |
|---|
public JavacElements(Context context)
| Method Detail |
|---|
public static JavacElements instance(Context context)
public void setContext(Context context)
public static <A extends java.lang.annotation.Annotation> A getAnnotation(Symbol annotated,
java.lang.Class<A> annoType)
public static <A extends java.lang.annotation.Annotation> A getAnnotation(Symbol.ClassSymbol annotated,
java.lang.Class<A> annoType)
public Symbol.PackageSymbol getPackageElement(java.lang.CharSequence name)
Elements
getPackageElement in interface Elementsname - fully qualified package name, or "" for an unnamed package
null if it cannot be foundpublic Symbol.ClassSymbol getTypeElement(java.lang.CharSequence name)
Elements
getTypeElement in interface Elementsname - the canonical name
null if it cannot be found
private <S extends Symbol> S nameToSymbol(java.lang.String nameStr,
java.lang.Class<S> clazz)
public JavacSourcePosition getSourcePosition(Element e)
public JavacSourcePosition getSourcePosition(Element e,
AnnotationMirror a)
public JavacSourcePosition getSourcePosition(Element e,
AnnotationMirror a,
AnnotationValue v)
private JCTree matchAnnoToTree(AnnotationMirror findme,
Element e,
JCTree tree)
private JCTree matchAnnoToTree(Attribute.Compound findme,
List<Attribute.Compound> annos,
List<JCTree.JCAnnotation> trees)
private JCTree matchAnnoToTree(Attribute.Compound findme,
Attribute attr,
JCTree tree)
private JCTree.JCExpression scanForAssign(Symbol.MethodSymbol sym,
JCTree tree)
public JCTree getTree(Element e)
public java.lang.String getDocComment(Element e)
Elements
getDocComment in interface Elementse - the element being examined
null
if there is nonepublic PackageElement getPackageOf(Element e)
Elements
getPackageOf in interface Elementse - the element being examined
public boolean isDeprecated(Element e)
Elementstrue if the element is deprecated, false otherwise.
isDeprecated in interface Elementse - the element being examined
true if the element is deprecated, false otherwisepublic Name getBinaryName(TypeElement type)
Elements
getBinaryName in interface Elementstype - the type element being examined
TypeElement.getQualifiedName()public java.util.Map<Symbol.MethodSymbol,Attribute> getElementValuesWithDefaults(AnnotationMirror a)
Elements
getElementValuesWithDefaults in interface Elementsa - annotation to examine
AnnotationMirror.getElementValues()public FilteredMemberList getAllMembers(TypeElement element)
Note that elements of certain kinds can be isolated using
methods in ElementFilter.
getAllMembers in interface Elementselement - the type being examined
Element.getEnclosedElements()
private void addMembers(Scope scope,
Type type)
public List<Attribute.Compound> getAllAnnotationMirrors(Element e)
getAllAnnotationMirrors in interface Elementse - the element being examined
Element.getAnnotationMirrors()private boolean isInherited(Type annotype)
private static boolean containsAnnoOfType(List<Attribute.Compound> annos,
Type type)
public boolean hides(Element hiderEl,
Element hideeEl)
Elements
hides in interface ElementshiderEl - the first elementhideeEl - the second element
true if and only if the first element hides
the second
public boolean overrides(ExecutableElement riderEl,
ExecutableElement rideeEl,
TypeElement typeEl)
Elements In the simplest and most typical usage, the value of the
type parameter will simply be the class or interface
directly enclosing overrider (the possibly-overriding
method). For example, suppose m1 represents the method
String.hashCode and m2 represents Object.hashCode. We can then ask whether m1 overrides
m2 within the class String (it does):
assert elements.overrides(m1, m2,
elements.getTypeElement("java.lang.String"));
A more interesting case can be illustrated by the following example
in which a method in type A does not override a
like-named method in type B:
When viewed as a member of a third typeclass A { public void m() {} }
interface B { void m(); }
...
m1 = ...; // A.m
m2 = ...; // B.m
assert ! elements.overrides(m1, m2, elements.getTypeElement("A"));
C, however,
the method in A does override the one in B:
class C extends A implements B {}
...
assert elements.overrides(m1, m2, elements.getTypeElement("C"));
overrides in interface ElementsriderEl - the first method, possible overriderrideeEl - the second method, possibly being overriddentypeEl - the type of which the first method is a member
true if and only if the first method overrides
the secondpublic java.lang.String getConstantExpression(java.lang.Object value)
Elements
getConstantExpression in interface Elementsvalue - a primitive value or string
VariableElement.getConstantValue()
public void printElements(java.io.Writer w,
Element... elements)
printElements in interface Elementsw - the writer to print the output toelements - the elements to printpublic Name getName(java.lang.CharSequence cs)
Elements
getName in interface Elementscs - the character sequence to return as a nameprivate Pair<JCTree,JCTree.JCCompilationUnit> getTreeAndTopLevel(Element e)
public Pair<JCTree,JCTree.JCCompilationUnit> getTreeAndTopLevel(Element e,
AnnotationMirror a,
AnnotationValue v)
private Env<AttrContext> getEnterEnv(Symbol sym)
private static <T> T cast(java.lang.Class<T> clazz,
java.lang.Object o)
java.lang.NullPointerException - if the object is null
java.lang.IllegalArgumentException - if the object is of the wrong type
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||