|
Java™ Platform Standard Ed. 6 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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.
ProcessingEnvironment.getElementUtils()
Method Summary | |
---|---|
List<? extends AnnotationMirror> |
getAllAnnotationMirrors(Element e)
Returns all annotations of an element, whether inherited or directly present. |
List<? extends Element> |
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 |
getDocComment(Element e)
Returns the text of the documentation ("Javadoc") comment of an element. |
Map<? extends ExecutableElement,? extends AnnotationValue> |
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. |
PackageElement |
getPackageElement(CharSequence name)
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 |
hides(Element hider,
Element hidden)
Tests whether one type, method, or field hides another. |
boolean |
isDeprecated(Element e)
Returns true if the element is deprecated, false 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 |
---|
PackageElement getPackageElement(CharSequence name)
name
- fully qualified package name, or "" for an unnamed package
null
if it cannot be foundTypeElement getTypeElement(CharSequence name)
name
- the canonical name
null
if it cannot be foundMap<? extends ExecutableElement,? extends AnnotationValue> getElementValuesWithDefaults(AnnotationMirror a)
a
- annotation to examine
AnnotationMirror.getElementValues()
String getDocComment(Element e)
e
- the element being examined
null
if there is noneboolean isDeprecated(Element e)
true
if the element is deprecated, false
otherwise.
e
- the element being examined
true
if the element is deprecated, false
otherwiseName getBinaryName(TypeElement type)
type
- the type element being examined
TypeElement.getQualifiedName()
PackageElement getPackageOf(Element type)
type
- the element being examined
List<? extends Element> getAllMembers(TypeElement type)
Note that elements of certain kinds can be isolated using
methods in ElementFilter
.
type
- the type being examined
Element.getEnclosedElements()
List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e)
e
- the element being examined
Element.getAnnotationMirrors()
boolean hides(Element hider, Element hidden)
hider
- the first elementhidden
- the second element
true
if and only if the first element hides
the secondboolean overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement type)
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"));
overrider
- the first method, possible overrideroverridden
- the second method, possibly being overriddentype
- the type of which the first method is a member
true
if and only if the first method overrides
the secondString getConstantExpression(Object value)
value
- a primitive value or string
IllegalArgumentException
- if the argument is not a primitive
value or stringVariableElement.getConstantValue()
void printElements(Writer w, Element... elements)
w
- the writer to print the output toelements
- the elements to printName getName(CharSequence cs)
cs
- the character sequence to return as a name
|
Java™ Platform Standard Ed. 6 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.