- All Superinterfaces:
AnnotatedConstruct
- All Known Subinterfaces:
ExecutableElement
,ModuleElement
,PackageElement
,Parameterizable
,QualifiedNameable
,TypeElement
,TypeParameterElement
,VariableElement
public interface Element extends AnnotatedConstruct
Represents a program element such as a module, package, class, or method.
Each element represents a static, 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.
- Since:
- 1.6
- See Also:
Elements
,TypeMirror
-
Method Summary
Modifier and Type Method Description <R, P> R
accept(ElementVisitor<R,P> v, P p)
Applies a visitor to this element.TypeMirror
asType()
Returns the type defined by this element.boolean
equals(Object obj)
Returnstrue
if the argument represents the same element asthis
, orfalse
otherwise.<A extends Annotation>
AgetAnnotation(Class<A> annotationType)
Returns this construct's annotation of the specified type if such an annotation is present, elsenull
.List<? extends AnnotationMirror>
getAnnotationMirrors()
Returns the annotations that are directly present on this construct.List<? extends Element>
getEnclosedElements()
Returns the elements that are, loosely speaking, directly enclosed by this element.Element
getEnclosingElement()
Returns the innermost element within which this element is, loosely speaking, enclosed.ElementKind
getKind()
Returns thekind
of this element.Set<Modifier>
getModifiers()
Returns the modifiers of this element, excluding annotations.Name
getSimpleName()
Returns the simple (unqualified) name of this element.int
hashCode()
Obeys the general contract ofObject.hashCode
.
-
Method Details
-
asType
TypeMirror asType()Returns the type defined by this element.- Returns:
- the type defined by this element
- See Also:
Types
,ExecutableElement.asType()
,ModuleElement.asType()
,PackageElement.asType()
,TypeElement.asType()
,TypeParameterElement.asType()
,VariableElement.asType()
-
getKind
ElementKind getKind()Returns thekind
of this element.- Returns:
- the kind of this element
-
getModifiers
Returns the modifiers of this element, excluding annotations. Implicit modifiers, such as thepublic
andstatic
modifiers of interface members, are included.- Returns:
- the modifiers of this element, or an empty set if there are none
-
getSimpleName
Name getSimpleName()Returns the simple (unqualified) name of this element. The name of a generic type does not include any reference to its formal type parameters. For example, the simple name of the type elementjava.util.Set<E>
is"Set"
. If this element represents an unnamed package or unnamed module, an empty name is returned. If it represents a constructor, the name "<init>
" is returned. If it represents a static initializer, the name "<clinit>
" is returned. If it represents an anonymous class or instance initializer, an empty name is returned.- Returns:
- the simple name of this element
- See Also:
PackageElement.getSimpleName()
,ExecutableElement.getSimpleName()
,TypeElement.getSimpleName()
,VariableElement.getSimpleName()
,ModuleElement.getSimpleName()
-
getEnclosingElement
Element getEnclosingElement()Returns the innermost element within which this element is, loosely speaking, enclosed.- 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 type, 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
-