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()
PackageElement getPackageElement(CharSequence name)
Returns a package given its fully qualified name.
name
- fully qualified package name, or "" for an unnamed packagenull
if it cannot be foundTypeElement getTypeElement(CharSequence name)
Returns a type element given its canonical name.
name
- the canonical namenull
if it cannot be foundMap<? extends ExecutableElement,? extends AnnotationValue> getElementValuesWithDefaults(AnnotationMirror a)
Returns the values of an annotation's elements, including defaults.
a
- annotation to examineAnnotationMirror.getElementValues()
String getDocComment(Element e)
Returns the text of the documentation ("Javadoc") comment of an element.
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.
e
- the element being examinednull
if there is noneboolean isDeprecated(Element e)
Returns true
if the element is deprecated, false
otherwise.
e
- the element being examinedtrue
if the element is deprecated, false
otherwiseName getBinaryName(TypeElement type)
Returns the binary name of a type element.
type
- the type element being examinedTypeElement.getQualifiedName()
PackageElement getPackageOf(Element type)
Returns the package of an element. The package of a package is itself.
type
- the element being examinedList<? extends Element> getAllMembers(TypeElement type)
Returns all members of a type element, whether inherited or declared directly. For a class the result also includes its constructors, but not local or anonymous classes.
Note that elements of certain kinds can be isolated using methods in ElementFilter
.
type
- the type being examinedElement.getEnclosedElements()
List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e)
Returns all annotations present on an element, whether directly present or present via inheritance.
e
- the element being examinedElement.getAnnotationMirrors()
, AnnotatedConstruct
boolean hides(Element hider, Element hidden)
Tests whether one type, method, or field hides another.
hider
- the first elementhidden
- the second elementtrue
if and only if the first element hides the secondboolean overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement type)
Tests whether one method, as a member of a given type, overrides another method. When a non-abstract method overrides an abstract one, the former is also said to implement the latter.
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
: class A { public void m() {} } interface B { void m(); } ... m1 = ...; // A.m m2 = ...; // B.m assert ! elements.overrides(m1, m2, elements.getTypeElement("A"));When viewed as a member of a third type
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 membertrue
if and only if the first method overrides the secondString getConstantExpression(Object value)
Returns the text of a constant expression representing a primitive value or a string. The text returned is in a form suitable for representing the value in source code.
value
- a primitive value or stringIllegalArgumentException
- if the argument is not a primitive value or stringVariableElement.getConstantValue()
void printElements(Writer w, Element... elements)
Prints a representation of the elements to the given writer in the specified order. The main purpose of this method is for diagnostics. The exact format of the output is not specified and is subject to change.
w
- the writer to print the output toelements
- the elements to printName getName(CharSequence cs)
Return a name with the same sequence of characters as the argument.
cs
- the character sequence to return as a nameboolean isFunctionalInterface(TypeElement type)
Returns true
if the type element is a functional interface, false
otherwise.
type
- the type element being examinedtrue
if the element is a functional interface, false
otherwise
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.