for loop or try-finally
block. Concretely, there is no model of any abstract syntax tree
(AST) structure of a Java program. However, the interfaces can
model some structures only appearing inside method bodies, such as
local variables,
anonymous classes, and
exception parameters.
Therefore, these interfaces can be used by an AST API to model the
declarations found in the method bodies of Java compilation units
(JLS 7.3).
When used in the context of annotation processing, an accurate model of the element being represented must be returned. As this is a language model, the source code provides the fiducial (reference) representation of the construct in question rather than a representation in an executable output like a class file. Executable output may serve as the basis for creating a modeling element. However, the process of translating source code to executable output may not permit recovering some aspects of the source code representation. For example, annotations with source retention cannot be recovered from class files and class files might not be able to provide source position information. Names of parameters may not be recoverable from class files. The modifiers on an element created from a class file may differ in some cases from an element for the same declaration created from a source file including:
strictfp on a class or interface
final on a parameter
protected, private, and static on
classes and interfaces
During annotation processing, operating on incomplete or
erroneous programs is necessary; however, there are fewer
guarantees about the nature of the resulting model. If the source
code is not syntactically well-formed or has some other
irrecoverable error that could not be removed by the generation of
new classes or interfaces, a model may or may not be provided as a
quality of implementation issue. If a program for a class or
interface is syntactically valid but erroneous in some other
fashion, any returned model must have no less information than if
all the method bodies in the program were replaced by "throw
new RuntimeException();". If a program refers to a missing class
or interface Xyz, the returned model must contain no less
information than if the declaration of class or interface Xyz were
assumed to be "class Xyz {}", "interface Xyz {}",
"enum Xyz {}", "@interface Xyz {}", or "record Xyz {}". If a program refers to a missing class or
interface Xyz<K1, ... ,Kn>, the returned model must contain
no less information than if the declaration of Xyz were assumed to
be "class Xyz<T1, ... ,Tn> {}" or "interface Xyz<T1,
... ,Tn> {}"
Unless otherwise specified in a particular implementation, the collections returned by methods in this package should be expected to be unmodifiable by the caller and unsafe for concurrent access.
Unless otherwise specified, methods in this package will throw
a NullPointerException if given a null argument.
javax.lang.model.util.Elements , Elements and Types, JSR 269: Pluggable Annotation Processing API
| Modifier and Type | Interface and Description |
|---|---|
| public interface | AnnotationMirror
Represents an annotation. |
| public interface | AnnotationValue
Represents a value of an annotation interface element. |
| public interface | AnnotationValueVisitor<
the return type of this visitor's methods R, the type of the additional parameter to this visitor's methods. P>A visitor of the values of annotation interface elements, using a variant of the visitor design pattern. |
| public interface | Element
Represents a program element such as a module, package, class, or method. |
| public interface | ElementVisitor<
the return type of this visitor's methods. Use R, Void for visitors that do not need to return results.the type of the additional parameter to this visitor's
methods. Use P>Void for visitors that do not need an
additional parameter.A visitor of program elements, in the style of the visitor design pattern. |
| public interface | ExecutableElement
Represents a method, constructor, or initializer (static or instance) of a class or interface, including annotation interface elements. |
| public interface | ModuleElement
Represents a module program element. |
| public interface | Name
An immutable sequence of characters. |
| public interface | PackageElement
Represents a package program element. |
| public interface | Parameterizable
A mixin interface for an element that has type parameters. |
| public interface | QualifiedNameable
A mixin interface for an element that has a qualified name. |
| public interface | RecordComponentElement
Represents a record component. |
| public interface | TypeElement
Represents a class or interface program element. |
| public interface | TypeParameterElement
Represents a formal type parameter of a generic class, interface, method, or constructor element. |
| public interface | VariableElement
Represents a field, |
| Modifier and Type | Class and Description |
|---|---|
| public class | UnknownAnnotationValueException
Indicates that an unknown kind of annotation value was encountered. |
| public class | UnknownDirectiveException
Indicates that an unknown kind of module directive was encountered. |
| public class | UnknownElementException
Indicates that an unknown kind of element was encountered. |
| Modifier and Type | Enum and Description |
|---|---|
| public enum | ElementKind
The |
| public enum | Modifier
Represents a modifier on a program element such as a class, method, or field. |
| public enum | NestingKind
The nesting kind of a type element. |