public interface AnnotationTarget
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
.
Modifier and Type | Method and Description |
---|---|
<T extends java.lang.annotation.Annotation> |
annotation(java.lang.Class<T> annotationType)
Returns an annotation of given type, if it is present on this annotation target.
|
java.util.Collection<AnnotationInfo> |
annotations()
Returns a collection of all annotations present on this annotation target.
|
java.util.Collection<AnnotationInfo> |
annotations(java.util.function.Predicate<AnnotationInfo> predicate)
Returns a collection of all annotations present on this annotation target that match given predicate.
|
DeclarationInfo |
asDeclaration()
Returns this annotation target as a declaration.
|
Type |
asType()
Returns this annotation target as a type.
|
boolean |
hasAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns whether an annotation of given type is present on this annotation target.
|
boolean |
hasAnnotation(java.util.function.Predicate<AnnotationInfo> predicate)
Returns whether given predicate matches any annotation present on this annotation target.
|
boolean |
isDeclaration()
Returns whether this annotation target is a declaration.
|
boolean |
isType()
Returns whether this annotation target is a type.
|
<T extends java.lang.annotation.Annotation> |
repeatableAnnotation(java.lang.Class<T> annotationType)
Returns a collection of annotations of given repeatable
annotationType that are present on this annotation target. |
boolean isDeclaration()
true
if this is a declaration, false
otherwiseboolean isType()
true
if this is a type, false
otherwiseDeclarationInfo asDeclaration()
null
java.lang.IllegalStateException
- if isDeclaration()
returns false
Type asType()
null
java.lang.IllegalStateException
- if isType()
returns false
boolean hasAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
annotationType
- the annotation type, must not be null
true
if given annotation type is present on this annotation target, false
otherwiseboolean hasAnnotation(java.util.function.Predicate<AnnotationInfo> predicate)
predicate
- annotation predicate, must not be null
true
if given predicate matches any annotation present on this annotation target, false
otherwise.<T extends java.lang.annotation.Annotation> AnnotationInfo annotation(java.lang.Class<T> annotationType)
null
if no such annotation is present.T
- the annotation generic typeannotationType
- the annotation type, must not be null
AnnotationInfo
or null
if no such annotation is present<T extends java.lang.annotation.Annotation> java.util.Collection<AnnotationInfo> repeatableAnnotation(java.lang.Class<T> annotationType)
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.
T
- the annotation generic typeannotationType
- the @Repeatable
annotation type, must not be null
AnnotationInfo
, never null
java.util.Collection<AnnotationInfo> annotations(java.util.function.Predicate<AnnotationInfo> predicate)
predicate
- annotation predicate, must not be null
AnnotationInfo
, never null
java.util.Collection<AnnotationInfo> annotations()
AnnotationInfo
, never null