- Package javax.lang.model.element
- Package javax.lang.model.element
- Package javax.lang.model.element Description
- Interface Element
- Method Summary
- Method Details
- asType
- getKind
- getModifiers
- getSimpleName
- getEnclosingElement
- getEnclosedElements
- equals
- hashCode
- getAnnotationMirrors
- getAnnotation
- getAnnotationsByType
- accept
Package javax.lang.model.element
Interfaces used to model elements of the Java programming language. The term «element» in this package is used to refer to program elements, the declared entities that make up a program. Elements include classes, interfaces, methods, constructors, and fields. The interfaces in this package do not model the structure of a program inside a method body; for example there is no representation of a for loop or try — finally block. However, the interfaces can model some structures only appearing inside method bodies, such as local variables and anonymous classes.
- 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 types, a model may or may not be provided as a quality of implementation issue. If a program 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 type Xyz, the returned model must contain no less information than if the declaration of type Xyz were assumed to be «class Xyz <>» , «interface Xyz <>» , «enum Xyz <>» , or «@interface Xyz <>» . If a program refers to a missing type Xyz , the returned model must contain no less information than if the declaration of Xyz were assumed to be «class Xyz <>» or «interface Xyz <>«
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.
Represents a method, constructor, or initializer (static or instance) of a class or interface, including annotation type elements.
Represents a field, enum constant, method or constructor parameter, local variable, resource variable, or exception parameter.
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
Package javax.lang.model.element
Represents a method, constructor, or initializer (static or instance) of a class or interface, including annotation type elements.
Represents a field, enum constant, method or constructor parameter, local variable, resource variable, or exception parameter.
Package javax.lang.model.element Description
Interfaces used to model elements of the Java programming language. The term «element» in this package is used to refer to program elements, the declared entities that make up a program. Elements include classes, interfaces, methods, constructors, and fields. The interfaces in this package do not model the structure of a program inside a method body; for example there is no representation of a for loop or try — finally block. However, the interfaces can model some structures only appearing inside method bodies, such as local variables and anonymous classes.
- strictfp on a class or interface
- final on a parameter
- protected , private , and static on classes and interfaces
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Interface Element
Represents a program element such as a module, package, class, or method. Each element represents a compile-time language-level construct (and not, for example, a runtime construct of the virtual machine).
Elements should be compared using the equals(Object) method. There is no guarantee that any particular element will always be represented by the same object.
To implement operations based on the class of an Element object, either use a visitor or use the result of the getKind() method. Using instanceof is not necessarily a reliable idiom for determining the effective class of an object in this modeling hierarchy since an implementation may choose to have a single object implement multiple Element subinterfaces.
Method Summary
Returns this construct’s annotation of the specified type if such an annotation is present, else null .
Method Details
asType
getKind
- The kind of a package is PACKAGE .
- The kind of a module is MODULE .
- The kind of a type element is one of ANNOTATION_TYPE , CLASS , ENUM , INTERFACE , or RECORD .
- The kind of a variable is one of ENUM_CONSTANT , EXCEPTION_PARAMETER , FIELD , LOCAL_VARIABLE , PARAMETER , RESOURCE_VARIABLE , or BINDING_VARIABLE .
- The kind of an executable is one of CONSTRUCTOR , INSTANCE_INIT , METHOD , or STATIC_INIT .
- The kind of a type parameter is TYPE_PARAMETER .
- The kind of a record component is RECORD_COMPONENT .
getModifiers
Returns the modifiers of this element, excluding annotations. Implicit modifiers, such as the public and static modifiers of interface members (JLS section 9.3), are included.
getSimpleName
Returns the simple (unqualified) name of this element. The name of a generic class or interface does not include any reference to its formal type parameters. For example, the simple name of the type element representing java.util.Set
getEnclosingElement
- If this element is one whose declaration is lexically enclosed immediately within the declaration of another element, that other element is returned.
- If this is a top-level class or interface, its package is returned.
- If this is a package, its module is returned if such a module exists. Otherwise, null is returned.
- If this is a type parameter, the generic element of the type parameter is returned.
- If this is a method or constructor parameter, the executable element which declares the parameter is returned.
- If this is a record component, the record class which declares the record component is returned.
- If this is a module, null is returned.
getEnclosedElements
Returns the elements that are, loosely speaking, directly enclosed by this element. A class or interface is considered to enclose the fields, methods, constructors, record components, and member classes and interfaces that it directly declares. A package encloses the top-level classes and interfaces within it, but is not considered to enclose subpackages. A module encloses packages within it. Enclosed elements may include implicitly declared mandated elements. Other kinds of elements are not currently considered to enclose any elements; however, that may change as this API or the programming language evolves.
equals
hashCode
getAnnotationMirrors
Returns the annotations that are directly present on this construct. To get inherited annotations as well, use getAllAnnotationMirrors . Note that any annotations returned by this method are declaration annotations.
getAnnotation
Returns this construct’s annotation of the specified type if such an annotation is present, else null . The annotation returned by this method could contain an element whose value is of type Class . This value cannot be returned directly: information necessary to locate and load a class (such as the class loader to use) is not available, and the class might not be loadable at all. Attempting to read a Class object by invoking the relevant method on the returned annotation will result in a MirroredTypeException , from which the corresponding TypeMirror may be extracted. Similarly, attempting to read a Class[] -valued element will result in a MirroredTypesException .
Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation interfaces currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation interfaces.
getAnnotationsByType
Returns annotations that are associated with this construct. If there are no annotations associated with this construct, the return value is an array of length 0. The order of annotations which are directly or indirectly present on a construct C is computed as if indirectly present annotations on C are directly present on C in place of their container annotation, in the order in which they appear in the value element of the container annotation. The difference between this method and AnnotatedConstruct.getAnnotation(Class) is that this method detects if its argument is a repeatable annotation interface, and if so, attempts to find one or more annotations of that type by «looking through» a container annotation. The annotations returned by this method could contain an element whose value is of type Class . This value cannot be returned directly: information necessary to locate and load a class (such as the class loader to use) is not available, and the class might not be loadable at all. Attempting to read a Class object by invoking the relevant method on the returned annotation will result in a MirroredTypeException , from which the corresponding TypeMirror may be extracted. Similarly, attempting to read a Class[] -valued element will result in a MirroredTypesException .
Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation interfaces currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation interfaces.
accept
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.