FileDocCategorySizeDatePackage
Elements.javaAPI DocJava SE 6 API7321Tue Jun 10 00:26:12 BST 2008javax.lang.model.util

Elements

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.

author
Joseph D. Darcy
author
Scott Seligman
author
Peter von der Ahé
version
1.11 06/08/16
see
javax.annotation.processing.ProcessingEnvironment#getElementUtils
since
1.6

Fields Summary
Constructors Summary
Methods Summary
public java.util.ListgetAllAnnotationMirrors(javax.lang.model.element.Element e)
Returns all annotations of an element, whether inherited or directly present.

param
e the element being examined
return
all annotations of the element
see
Element#getAnnotationMirrors

public java.util.ListgetAllMembers(javax.lang.model.element.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 {@link ElementFilter}.

param
type the type being examined
return
all members of the type
see
Element#getEnclosedElements

public javax.lang.model.element.NamegetBinaryName(javax.lang.model.element.TypeElement type)
Returns the binary name of a type element.

param
type the type element being examined
return
the binary name
see
TypeElement#getQualifiedName
jls3
13.1 The Form of a Binary

public java.lang.StringgetConstantExpression(java.lang.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.

param
value a primitive value or string
return
the text of a constant expression
throws
IllegalArgumentException if the argument is not a primitive value or string
see
VariableElement#getConstantValue()

public java.lang.StringgetDocComment(javax.lang.model.element.Element e)
Returns the text of the documentation ("Javadoc") comment of an element.

param
e the element being examined
return
the documentation comment of the element, or {@code null} if there is none

public java.util.MapgetElementValuesWithDefaults(javax.lang.model.element.AnnotationMirror a)
Returns the values of an annotation's elements, including defaults.

see
AnnotationMirror#getElementValues()
param
a annotation to examine
return
the values of the annotation's elements, including defaults

public javax.lang.model.element.NamegetName(java.lang.CharSequence cs)
Return a name with the same sequence of characters as the argument.

param
cs the character sequence to return as a name

public javax.lang.model.element.PackageElementgetPackageElement(java.lang.CharSequence name)
Returns a package given its fully qualified name.

param
name fully qualified package name, or "" for an unnamed package
return
the named package, or {@code null} if it cannot be found

public javax.lang.model.element.PackageElementgetPackageOf(javax.lang.model.element.Element type)
Returns the package of an element. The package of a package is itself.

param
type the element being examined
return
the package of an element

public javax.lang.model.element.TypeElementgetTypeElement(java.lang.CharSequence name)
Returns a type element given its canonical name.

param
name the canonical name
return
the named type element, or {@code null} if it cannot be found

public booleanhides(javax.lang.model.element.Element hider, javax.lang.model.element.Element hidden)
Tests whether one type, method, or field hides another.

param
hider the first element
param
hidden the second element
return
{@code true} if and only if the first element hides the second

public booleanisDeprecated(javax.lang.model.element.Element e)
Returns {@code true} if the element is deprecated, {@code false} otherwise.

param
e the element being examined
return
{@code true} if the element is deprecated, {@code false} otherwise

public booleanoverrides(javax.lang.model.element.ExecutableElement overrider, javax.lang.model.element.ExecutableElement overridden, javax.lang.model.element.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 {@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() {} } }
{@code interface B { void m(); } }
...
{@code m1 = ...; // A.m }
{@code m2 = ...; // B.m }
{@code assert ! elements.overrides(m1, m2, elements.getTypeElement("A")); }
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 class C extends A implements B {} }
...
{@code assert elements.overrides(m1, m2, elements.getTypeElement("C")); }

param
overrider the first method, possible overrider
param
overridden the second method, possibly being overridden
param
type the type of which the first method is a member
return
{@code true} if and only if the first method overrides the second
jls3
8.4.8 Inheritance, Overriding, and Hiding
jls3
9.4.1 Inheritance and Overriding

public voidprintElements(java.io.Writer w, javax.lang.model.element.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.

param
w the writer to print the output to
param
elements the elements to print