| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ProcessingEnvironment processingEnv = …;
Elements eltUtils = processingEnv.getElementUtils();
Based on 7 examples
public interface Elements
Utility methods for operating on program elements.
Compatibility Note: Methods may be added to this interface in future releases of the platform.
Method Summary | |
---|---|
List |
Returns all annotations of an element, whether inherited or directly present. |
List |
getAllMembers(TypeElement type) 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 |
Returns the text of the documentation ("Javadoc") comment of an element. |
Map |
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. |
PackageElement |
Returns a package given its fully qualified name. |
PackageElement |
getPackageOf(Element type) Returns the package of an element. |
TypeElement |
getTypeElement(CharSequence name) Returns a type element given its canonical name. |
boolean |
Tests whether one type, method, or field hides another. |
boolean |
Returns if the element is deprecated, otherwise. |
boolean |
overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement type) Tests whether one method, as a member of a given type, overrides another method. |
void |
printElements(Writer w, Element[] elements) Prints a representation of the elements to the given writer in the specified order. |
Method Detail |
---|
public List getAllAnnotationMirrors(Element e)
e
- the element being examinedpublic List getAllMembers(TypeElement type)
Note that elements of certain kinds can be isolated using methods in {@link ElementFilter}.
type
- the type being examinedpublic Name getBinaryName(TypeElement type)
type
- the type element being examinedpublic String getConstantExpression(Object value)
value
- a primitive value or stringpublic String getDocComment(Element e)
e
- the element being examinedpublic Map getElementValuesWithDefaults(AnnotationMirror a)
a
- annotation to examinepublic Name getName(CharSequence cs)
cs
- the character sequence to return as a namepublic PackageElement getPackageElement(CharSequence name)
name
- fully qualified package name, or "" for an unnamed packagepublic PackageElement getPackageOf(Element type)
type
- the element being examinedpublic TypeElement getTypeElement(CharSequence name)
name
- the canonical namepublic boolean hides(Element hider, Element hidden)
hider
- the first elementhidden
- the second elementpublic boolean isDeprecated(Element e)
e
- the element being examinedpublic boolean overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement type)
In the simplest and most typical usage, the value of the {@code type} parameter will simply be the class or interface directly enclosing {@code overrider} (the possibly-overriding method). For example, suppose {@code m1} represents the method {@code String.hashCode} and {@code m2} represents {@code Object.hashCode}. We can then ask whether {@code m1} overrides {@code m2} within the class {@code String} (it does):
{@code 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 {@code A} does not override a like-named method in type {@code B}:
{@code class A { public void m() {} } }When viewed as a member of a third type {@code C}, however, the method in {@code A} does override the one in {@code B}:
{@code interface B { void m(); } }
...
{@code m1 = ...; // A.m }
{@code m2 = ...; // B.m }
{@code assert ! elements.overrides(m1, m2, elements.getTypeElement("A")); }
{@code class C extends A implements B {} }
...
{@code assert elements.overrides(m1, m2, elements.getTypeElement("C")); }
overrider
- the first method, possible overrideroverridden
- the second method, possibly being overriddentype
- the type of which the first method is a memberpublic void printElements(Writer w, Element[] elements)
w
- the writer to print the output toelements
- the elements to print
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |