AnnotatedConstruct
, Element
, Parameterizable
, QualifiedNameable
public interface TypeElement extends Element, Parameterizable, QualifiedNameable
While a TypeElement
represents a class or interface element, a DeclaredType
represents a class or interface type, the latter being a use (or invocation) of the former. The distinction is most apparent with generic types, for which a single element can define a whole family of types. For example, the element java.util.Set
corresponds to the parameterized types java.util.Set<String>
and java.util.Set<Number>
(and many others), and to the raw type java.util.Set
.
Each method of this interface that returns a list of elements will return them in the order that is natural for the underlying source of program information. For example, if the underlying source of information is Java source code, then the elements will be returned in source code order.
In the context of annotation processing, a type element can be:
Modifier and Type | Method | Description |
---|---|---|
TypeMirror |
asType() |
Returns the type defined by this class or interface element, returning the prototypical type for an element representing a generic type. |
List |
getEnclosedElements() |
Returns the fields, methods, constructors, record components, and member classes and interfaces that are directly declared in this class or interface. |
Element |
getEnclosingElement() |
Returns the package of a top-level class or interface and returns the immediately lexically enclosing element for a nested class or interface. |
List |
getInterfaces() |
Returns the interface types directly implemented by this class or extended by this interface. |
NestingKind |
getNestingKind() |
Returns the nesting kind of this class or interface element. |
default List |
getPermittedSubclasses() |
Returns the permitted classes of this class or interface element in declaration order. |
Name |
getQualifiedName() |
Returns the fully qualified name of this class or interface element. |
default List |
getRecordComponents() |
Returns the record components of this class or interface element in declaration order. |
Name |
getSimpleName() |
Returns the simple name of this class or interface element. |
TypeMirror |
getSuperclass() |
Returns the direct superclass of this class or interface element. |
List |
getTypeParameters() |
Returns the formal type parameters of this class or interface element in declaration order. |
default boolean |
isUnnamed() |
Preview. Returns true if this is an unnamed class and
false otherwise. |
accept, equals, getAnnotation, getAnnotationMirrors, getAnnotationsByType, getKind, getModifiers, hashCode
TypeMirror asType()
A generic element defines a family of types, not just one. If this is a generic element, a prototypical type is returned which has the element's invocation on the type variables corresponding to its own formal type parameters. For example, for the generic class element C<N extends Number>
, the parameterized type C<N>
is returned. The Types
utility interface has more general methods for obtaining the full range of types defined by an element.
List<? extends Element> getEnclosedElements()
values
and valueOf
methods of an enum class.getEnclosedElements
in interface Element
NestingKind getNestingKind()
Name getQualifiedName()
The name of a generic class or interface does not include any reference to its formal type parameters. For example, the fully qualified name of the interface java.util.Set<E>
is "java.util.Set
". Nested classes and interfaces use ".
" as a separator, as in "java.util.Map.Entry
".
getQualifiedName
in interface QualifiedNameable
Name getSimpleName()
getSimpleName
in interface Element
default boolean isUnnamed()
isUnnamed
is a reflective preview API of the Java platform. true
if this is an unnamed class and
false
otherwise.false
.true
if this is an unnamed class and
false
otherwiseTypeMirror getSuperclass()
java.lang.Object
, then a NoType
with kind NONE
is returned.NoType
if there is noneList<? extends TypeMirror> getInterfaces()
List<? extends TypeParameterElement> getTypeParameters()
getTypeParameters
in interface Parameterizable
default List<? extends RecordComponentElement> getRecordComponents()
default List<? extends TypeMirror> getPermittedSubclasses()
Element getEnclosingElement()
getEnclosingElement
in interface Element
© 1993, 2023, 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.
https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/lang/model/element/TypeElement.html