APIdia Launch Partner
Top Description Methods
javax.lang.model.element

public Interface TypeElement

extends Element, Parameterizable, QualifiedNameable
Imports
java.util.List, javax.lang.model.type.*, javax.lang.model.util.*

Represents a class or interface program element. Provides access to information about the class or interface and its members. Note that an enum class and a record class are specialized kinds of classes and an annotation interface is a specialized kind of interface.

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.

API Note

The represented class or interface may have a reference representation (either source code or executable output). Multiple classes and interfaces can share the same reference representation backing construct. For example, multiple classes and interfaces can be declared in the same source file, including, but not limited to:

In the context of annotation processing, a type element can be:

Since
1.6
Java Language Specification
8.1 Class Declarations, 8.5 Member Class and Interface Declarations, 8.9 Enum Classes, 8.10 Record Classes, 9.1 Interface Declarations, 9.5 Member Class and Interface Declarations, 9.6 Annotation Interfaces
See Also
DeclaredType

Method Summary

Modifier and TypeMethod and Description
public TypeMirror

Returns:

the type defined by this type element
asType
()

Redeclares javax.lang.model.element.Element.asType.

Returns the type defined by this class or interface element, returning the prototypical type for an element representing a generic type.

public List<? extends Element>

Returns:

the enclosed elements in proper order, or an empty list if none
getEnclosedElements
()

Redeclares javax.lang.model.element.Element.getEnclosedElements.

Returns the fields, methods, constructors, record components, and member classes and interfaces that are directly declared in this class or interface.

public Element

Returns:

the package of a top-level class or interface, the immediately lexically enclosing element for a nested class or interface
getEnclosingElement
()

Redeclares javax.lang.model.element.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.

public List<? extends TypeMirror>

Returns:

the interface types directly implemented by this class or extended by this interface, or an empty list if there are none
getInterfaces
()

Returns the interface types directly implemented by this class or extended by this interface.

public NestingKind

Returns:

the nesting kind of this class or interface element
getNestingKind
()

Returns the nesting kind of this class or interface element.

public default List<? extends TypeMirror>

Returns:

the permitted classes, or an empty list if there are none
getPermittedSubclasses
()

Returns the permitted classes of this class or interface element in declaration order.

public Name

Returns:

the fully qualified name of this class or interface, or an empty name if none
getQualifiedName
()

Redeclares javax.lang.model.element.QualifiedNameable.getQualifiedName.

Returns the fully qualified name of this class or interface element.

public default List<? extends RecordComponentElement>

Returns:

the record components, or an empty list if there are none
getRecordComponents
()

Returns the record components of this class or interface element in declaration order.

public Name

Returns:

the simple name of this class or interface, an empty name for an anonymous class
getSimpleName
()

Redeclares javax.lang.model.element.Element.getSimpleName.

Returns the simple name of this class or interface element.

public TypeMirror

Returns:

the direct superclass, or a NoType if there is none
getSuperclass
()

Returns the direct superclass of this class or interface element.

public List<? extends TypeParameterElement>

Returns:

the formal type parameters, or an empty list if there are none
getTypeParameters
()

Redeclares javax.lang.model.element.Parameterizable.getTypeParameters.

Returns the formal type parameters of this class or interface element in declaration order.

Inherited from javax.lang.model.element.Element:
acceptequalsgetAnnotationgetAnnotationMirrorsgetAnnotationsByTypegetKindgetModifiershashCode

Method Detail

asTypeback to summary
public TypeMirror asType()

Redeclares javax.lang.model.element.Element.asType.

Returns the type defined by this class or interface element, returning the prototypical type for an element representing a generic type.

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. Otherwise, for a non-generic class or interface, the prototypical type mirror corresponds to a use of the type. None of the components of the prototypical type are annotated, including the prototypical type itself.

API Note

The Types utility interface has more general methods for obtaining the full range of types defined by an element.

Returns:TypeMirror

the type defined by this type element

Annotations
@Override
See Also
Types#asMemberOf(DeclaredType, Element), Types#getDeclaredType(TypeElement, TypeMirror...)
getEnclosedElementsback to summary
public List<? extends Element> getEnclosedElements()

Redeclares javax.lang.model.element.Element.getEnclosedElements.

Returns the fields, methods, constructors, record components, and member classes and interfaces that are directly declared in this class or interface. This includes any mandated elements such as the (implicit) default constructor and the implicit values and valueOf methods of an enum class.

API Note

As a particular instance of the general accuracy requirements and the ordering behavior required of this interface, the list of enclosed elements will be returned in the natural order for the originating source of information about the class or interface. For example, if the information about the class or interface is originating from a source file, the elements will be returned in source code order. (However, in that case the ordering of implicitly declared elements, such as default constructors, is not specified.)

Returns:List<? extends Element>

the enclosed elements in proper order, or an empty list if none

Annotations
@Override
Java Language Specification
8.8.9 Default Constructor, 8.9.3 Enum Members, 8.10.3 Record Members
getEnclosingElementback to summary
public Element getEnclosingElement()

Redeclares javax.lang.model.element.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.

Returns:Element

the package of a top-level class or interface, the immediately lexically enclosing element for a nested class or interface

Annotations
@Override
getInterfacesback to summary
public List<? extends TypeMirror> getInterfaces()

Returns the interface types directly implemented by this class or extended by this interface.

Returns:List<? extends TypeMirror>

the interface types directly implemented by this class or extended by this interface, or an empty list if there are none

getNestingKindback to summary
public NestingKind getNestingKind()

Returns the nesting kind of this class or interface element.

Returns:NestingKind

the nesting kind of this class or interface element

getPermittedSubclassesback to summary
public default List<? extends TypeMirror> getPermittedSubclasses()

Returns the permitted classes of this class or interface element in declaration order. Note that for an interface, permitted subclasses and subinterfaces can be returned.

Implementation Specification

The default implementations of this method returns an empty and unmodifiable list.

Returns:List<? extends TypeMirror>

the permitted classes, or an empty list if there are none

Since
17
Java Language Specification
8.1.6 Permitted Direct Subclasses, 9.1.4 Permitted Direct Subclasses and Subinterfaces
getQualifiedNameback to summary
public Name getQualifiedName()

Redeclares javax.lang.model.element.QualifiedNameable.getQualifiedName.

Returns the fully qualified name of this class or interface element. More precisely, it returns the canonical name. For local, and anonymous classes, which do not have canonical names, an empty name is returned.

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

Returns:Name

the fully qualified name of this class or interface, or an empty name if none

Java Language Specification
6.7 Fully Qualified Names and Canonical Names
See Also
Elements#getBinaryName
getRecordComponentsback to summary
public default List<? extends RecordComponentElement> getRecordComponents()

Returns the record components of this class or interface element in declaration order.

Implementation Specification

The default implementations of this method returns an empty and unmodifiable list.

Returns:List<? extends RecordComponentElement>

the record components, or an empty list if there are none

Since
16
getSimpleNameback to summary
public Name getSimpleName()

Redeclares javax.lang.model.element.Element.getSimpleName.

Returns the simple name of this class or interface element. For an anonymous class, an empty name is returned.

Returns:Name

the simple name of this class or interface, an empty name for an anonymous class

Annotations
@Override
getSuperclassback to summary
public TypeMirror getSuperclass()

Returns the direct superclass of this class or interface element. If this class or interface element represents an interface or the class java.lang.Object, then a NoType with kind NONE is returned.

Returns:TypeMirror

the direct superclass, or a NoType if there is none

getTypeParametersback to summary
public List<? extends TypeParameterElement> getTypeParameters()

Redeclares javax.lang.model.element.Parameterizable.getTypeParameters.

Returns the formal type parameters of this class or interface element in declaration order.

Returns:List<? extends TypeParameterElement>

the formal type parameters, or an empty list if there are none