Top Description Methods
jakarta.enterprise.lang.model

public Interface AnnotationTarget

Known Direct Subinterfaces
jakarta.enterprise.lang.model.declarations.DeclarationInfo, jakarta.enterprise.lang.model.types.Type
Imports
jakarta.enterprise.lang.model.declarations.DeclarationInfo, jakarta.enterprise.lang.model.types.Type, java.lang.annotation.Annotation, java.util.Collection, java.util.function.Predicate

An annotation target is anything that can be annotated. That is: The hasAnnotation, annotation, repeatableAnnotation and annotations methods may be used to obtain information about annotations present on this annotation target. The phrase "present on this annotation target" means: either the annotation is declared or implicitly declared directly on this annotation target, or this annotation target is a class declaration and the annotation is inherited from a superclass.

Note that if more than one annotation of a repeatable annotation type is declared on an annotation target, only an implicitly declared container annotation is present on the annotation target; the originally declared annotations are not. If exactly one annotation of a repeatable annotation type is declared on an annotation target, that annotation is present.

Annotations are represented as AnnotationInfo, so that implementations of this interface are not required to instantiate the annotation type.

Implementations of this interface are required to define the equals and hashCode methods. Implementations of this interface are encouraged to define the toString method such that it returns a text resembling the corresponding Java™ syntax.

There is no guarantee that any particular construct, represented by an implementation of this interface, will always be represented by the same object. That includes natural singletons such as the java.lang.Object class declaration, or the void pseudo-type. Instances should always be compared using equals.

Since
4.0

Method Summary

Modifier and TypeMethod and Description
public <
the annotation generic type
T extends Annotation
>
AnnotationInfo

Returns:

the AnnotationInfo or null if no such annotation is present
annotation
(Class<T>
the annotation type, must not be null
annotationType
)

Returns an annotation of given type, if it is present on this annotation target.

public Collection<AnnotationInfo>

Returns:

immutable collection of AnnotationInfo, never null
annotations
(Predicate<AnnotationInfo>
annotation predicate, must not be null
predicate
)

Returns a collection of all annotations present on this annotation target that match given predicate.

public Collection<AnnotationInfo>

Returns:

immutable collection of AnnotationInfo, never null
annotations
()

Returns a collection of all annotations present on this annotation target.

public DeclarationInfo

Returns:

this declaration, never null
asDeclaration
()

Returns this annotation target as a declaration.

public Type

Returns:

this type, never null
asType
()

Returns this annotation target as a type.

public boolean

Returns:

true if given annotation type is present on this annotation target, false otherwise
hasAnnotation
(Class<? extends Annotation>
the annotation type, must not be null
annotationType
)

Returns whether an annotation of given type is present on this annotation target.

public boolean

Returns:

true if given predicate matches any annotation present on this annotation target, false otherwise.
hasAnnotation
(Predicate<AnnotationInfo>
annotation predicate, must not be null
predicate
)

Returns whether given predicate matches any annotation present on this annotation target.

public boolean

Returns:

true if this is a declaration, false otherwise
isDeclaration
()

Returns whether this annotation target is a declaration.

public boolean

Returns:

true if this is a type, false otherwise
isType
()

Returns whether this annotation target is a type.

public <
the annotation generic type
T extends Annotation
>
Collection<AnnotationInfo>

Returns:

immutable collection of AnnotationInfo, never null
repeatableAnnotation
(Class<T>
the @Repeatable annotation type, must not be null
annotationType
)

Returns a collection of annotations of given repeatable annotationType that are present on this annotation target.

Method Detail

annotationback to summary
public <T extends Annotation> AnnotationInfo annotation(Class<T> annotationType)

Returns an annotation of given type, if it is present on this annotation target. Returns null if no such annotation is present.

Parameters
<T>
the annotation generic type
annotationType:Class<T>

the annotation type, must not be null

Returns:AnnotationInfo

the AnnotationInfo or null if no such annotation is present

annotationsback to summary
public Collection<AnnotationInfo> annotations(Predicate<AnnotationInfo> predicate)

Returns a collection of all annotations present on this annotation target that match given predicate. Returns an empty collection if no such annotation is present.

Parameters
predicate:Predicate<AnnotationInfo>

annotation predicate, must not be null

Returns:Collection<AnnotationInfo>

immutable collection of AnnotationInfo, never null

annotationsback to summary
public Collection<AnnotationInfo> annotations()

Returns a collection of all annotations present on this annotation target. Returns an empty collection if no annotation is present.

Returns:Collection<AnnotationInfo>

immutable collection of AnnotationInfo, never null

asDeclarationback to summary
public DeclarationInfo asDeclaration()

Returns this annotation target as a declaration.

Returns:DeclarationInfo

this declaration, never null

Exceptions
IllegalStateException:
if isDeclaration() returns false
asTypeback to summary
public Type asType()

Returns this annotation target as a type.

Returns:Type

this type, never null

Exceptions
IllegalStateException:
if isType() returns false
hasAnnotationback to summary
public boolean hasAnnotation(Class<? extends Annotation> annotationType)

Returns whether an annotation of given type is present on this annotation target.

Parameters
annotationType:Class<? extends Annotation>

the annotation type, must not be null

Returns:boolean

true if given annotation type is present on this annotation target, false otherwise

hasAnnotationback to summary
public boolean hasAnnotation(Predicate<AnnotationInfo> predicate)

Returns whether given predicate matches any annotation present on this annotation target.

Parameters
predicate:Predicate<AnnotationInfo>

annotation predicate, must not be null

Returns:boolean

true if given predicate matches any annotation present on this annotation target, false otherwise.

isDeclarationback to summary
public boolean isDeclaration()

Returns whether this annotation target is a declaration.

Returns:boolean

true if this is a declaration, false otherwise

isTypeback to summary
public boolean isType()

Returns whether this annotation target is a type.

Returns:boolean

true if this is a type, false otherwise

repeatableAnnotationback to summary
public <T extends Annotation> Collection<AnnotationInfo> repeatableAnnotation(Class<T> annotationType)

Returns a collection of annotations of given repeatable annotationType that are present on this annotation target. Returns an empty collection if no such annotation is present.

For the purpose of this method, annotations in the value member of a container annotation, as defined using @Repeatable, are considered to be present on the annotation target on which the container annotation is present.

Parameters
<T>
the annotation generic type
annotationType:Class<T>

the @Repeatable annotation type, must not be null

Returns:Collection<AnnotationInfo>

immutable collection of AnnotationInfo, never null