This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.lang.model.util
interface Elements


Most common way to construct:

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

          Returns all members of a type element, whether inherited or declared directly.
 Name

          Returns the binary name of a type element.
 String

          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

          Return a name with the same sequence of characters as the argument.
 PackageElement

          Returns a package given its fully qualified name.
 PackageElement

          Returns the package of an element.
 TypeElement

          Returns a type element given its canonical name.
 boolean
hides(Element hider, Element hidden)

          Tests whether one type, method, or field hides another.
 boolean

          Returns if the element is deprecated, otherwise.
 boolean

          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

getAllAnnotationMirrors

public List getAllAnnotationMirrors(Element e)
Returns all annotations of an element, whether inherited or directly present.

Parameters:
e - the element being examined
Returns:
all annotations of the element

getAllMembers

public List 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 {@link ElementFilter}.

Parameters:
type - the type being examined
Returns:
all members of the type

getBinaryName

public Name getBinaryName(TypeElement type)
Returns the binary name of a type element.

Parameters:
type - the type element being examined
Returns:
the binary name

getConstantExpression

public String 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.

Parameters:
value - a primitive value or string
Returns:
the text of a constant expression

getDocComment

public String getDocComment(Element e)
Returns the text of the documentation ("Javadoc") comment of an element.

Parameters:
e - the element being examined
Returns:
the documentation comment of the element, or {@code null} if there is none

getElementValuesWithDefaults

public Map getElementValuesWithDefaults(AnnotationMirror a)
Returns the values of an annotation's elements, including defaults.

Parameters:
a - annotation to examine
Returns:
the values of the annotation's elements, including defaults

getName

public Name getName(CharSequence cs)
Return a name with the same sequence of characters as the argument.

Parameters:
cs - the character sequence to return as a name

getPackageElement

public PackageElement getPackageElement(CharSequence name)
Returns a package given its fully qualified name.

Parameters:
name - fully qualified package name, or "" for an unnamed package
Returns:
the named package, or {@code null} if it cannot be found

getPackageOf

public PackageElement getPackageOf(Element type)
Returns the package of an element. The package of a package is itself.

Parameters:
type - the element being examined
Returns:
the package of an element

getTypeElement

public TypeElement getTypeElement(CharSequence name)
Returns a type element given its canonical name.

Parameters:
name - the canonical name
Returns:
the named type element, or {@code null} if it cannot be found

hides

public boolean hides(Element hider,
                     Element hidden)
Tests whether one type, method, or field hides another.

Parameters:
hider - the first element
hidden - the second element
Returns:
{@code true} if and only if the first element hides the second

isDeprecated

public boolean isDeprecated(Element e)
Returns {@code true} if the element is deprecated, {@code false} otherwise.

Parameters:
e - the element being examined
Returns:
{@code true} if the element is deprecated, {@code false} otherwise

overrides

public boolean 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 {@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")); }

Parameters:
overrider - the first method, possible overrider
overridden - the second method, possibly being overridden
type - the type of which the first method is a member
Returns:
{@code true} if and only if the first method overrides the second

printElements

public 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.

Parameters:
w - the writer to print the output to
elements - the elements to print


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.