public class JavacElements extends Object implements Elements
This is NOT part of any supported API. 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.
Modifier | Constructor and Description |
---|---|
protected |
JavacElements(Context context)
Public for use only by JavacProcessingEnvironment
|
Modifier and Type | Method and Description |
---|---|
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.
|
Name |
getBinaryName(TypeElement type)
Returns the binary name of a type element.
|
String |
getConstantExpression(Object value)
Returns the text of a constant expression representing a
primitive value or a string.
|
String |
getDocComment(Element e)
Returns the text of the documentation ("Javadoc")
comment of an element.
|
Map<Symbol.MethodSymbol,Attribute> |
getElementValuesWithDefaults(AnnotationMirror a)
Returns the values of an annotation's elements, including defaults.
|
Name |
getName(CharSequence cs)
Return a name with the same sequence of characters as the
argument.
|
Symbol.PackageSymbol |
getPackageElement(CharSequence name)
Returns a package given its fully qualified name.
|
PackageElement |
getPackageOf(Element e)
Returns the package of an element.
|
com.sun.tools.javac.model.JavacSourcePosition |
getSourcePosition(Element e) |
com.sun.tools.javac.model.JavacSourcePosition |
getSourcePosition(Element e,
AnnotationMirror a) |
com.sun.tools.javac.model.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.
|
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(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. |
boolean |
isFunctionalInterface(TypeElement element)
Returns
true if the type element is a functional interface, false otherwise. |
boolean |
overrides(ExecutableElement riderEl,
ExecutableElement rideeEl,
TypeElement typeEl)
Tests whether one method, as a member of a given type,
overrides another method.
|
void |
printElements(Writer w,
Element... elements)
Print a representation of the elements to the given writer in
the specified order.
|
void |
setContext(Context context)
Use a new context.
|
protected JavacElements(Context context)
public static JavacElements instance(Context context)
public void setContext(Context context)
public Symbol.PackageSymbol getPackageElement(CharSequence name)
Elements
getPackageElement
in interface Elements
name
- fully qualified package name, or "" for an unnamed packagenull
if it cannot be foundpublic Symbol.ClassSymbol getTypeElement(CharSequence name)
Elements
getTypeElement
in interface Elements
name
- the canonical namenull
if it cannot be foundpublic com.sun.tools.javac.model.JavacSourcePosition getSourcePosition(Element e)
public com.sun.tools.javac.model.JavacSourcePosition getSourcePosition(Element e, AnnotationMirror a)
public com.sun.tools.javac.model.JavacSourcePosition getSourcePosition(Element e, AnnotationMirror a, AnnotationValue v)
public JCTree getTree(Element e)
public String getDocComment(Element e)
Elements
A documentation comment of an element is a comment that
begins with "/**
" , ends with a separate
"*/
", and immediately precedes the element,
ignoring white space. Therefore, a documentation comment
contains at least three"*
" characters. The text
returned for the documentation comment is a processed form of
the comment as it appears in source code. The leading "/**
" and trailing "*/
" are removed. For lines
of the comment starting after the initial "/**
",
leading white space characters are discarded as are any
consecutive "*
" characters appearing after the white
space or starting the line. The processed lines are then
concatenated together (including line terminators) and
returned.
getDocComment
in interface Elements
e
- the element being examinednull
if there is nonepublic PackageElement getPackageOf(Element e)
Elements
getPackageOf
in interface Elements
e
- the element being examinedpublic boolean isDeprecated(Element e)
Elements
true
if the element is deprecated, false
otherwise.isDeprecated
in interface Elements
e
- the element being examinedtrue
if the element is deprecated, false
otherwisepublic Name getBinaryName(TypeElement type)
Elements
getBinaryName
in interface Elements
type
- the type element being examinedTypeElement.getQualifiedName()
public Map<Symbol.MethodSymbol,Attribute> getElementValuesWithDefaults(AnnotationMirror a)
Elements
getElementValuesWithDefaults
in interface Elements
a
- annotation to examineAnnotationMirror.getElementValues()
public FilteredMemberList getAllMembers(TypeElement element)
Note that elements of certain kinds can be isolated using
methods in ElementFilter
.
getAllMembers
in interface Elements
element
- the type being examinedElement.getEnclosedElements()
public List<Attribute.Compound> getAllAnnotationMirrors(Element e)
getAllAnnotationMirrors
in interface Elements
e
- the element being examinedElement.getAnnotationMirrors()
,
AnnotatedConstruct
public boolean hides(Element hiderEl, Element hideeEl)
Elements
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"));
public String getConstantExpression(Object value)
Elements
getConstantExpression
in interface Elements
value
- a primitive value or stringVariableElement.getConstantValue()
public void printElements(Writer w, Element... elements)
printElements
in interface Elements
w
- the writer to print the output toelements
- the elements to printpublic Name getName(CharSequence cs)
Elements
public boolean isFunctionalInterface(TypeElement element)
Elements
true
if the type element is a functional interface, false
otherwise.isFunctionalInterface
in interface Elements
element
- the type element being examinedtrue
if the element is a functional interface, false
otherwisepublic Pair<JCTree,JCTree.JCCompilationUnit> getTreeAndTopLevel(Element e, AnnotationMirror a, AnnotationValue v)
Copyright © 2015. All rights reserved.