Interface AnnotationTarget
-
- All Known Subinterfaces:
Declaration
- All Known Implementing Classes:
ClassExtendsTypeTarget
,ClassInfo
,EmptyTypeTarget
,FieldInfo
,MethodInfo
,MethodParameterInfo
,MethodParameterTypeTarget
,PositionBasedTypeTarget
,RecordComponentInfo
,ThrowsTypeTarget
,TypeParameterBoundTypeTarget
,TypeParameterTypeTarget
,TypeTarget
public interface AnnotationTarget
Represents an object that can be a target of an annotation.Overall, two distinct kinds of annotation targets exist: declarations and types. To refer to declarations only, the
Declaration
interface may be used.- See Also:
Declaration
,TypeTarget
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
AnnotationTarget.Kind
Specifies the kind of object a target represents.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default AnnotationInstance
annotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instance of given type declared on this annotation target or any of its nested annotation targets.default AnnotationInstance
annotation(java.lang.String name)
Returns the annotation instance with given name declared on this annotation target or any of its nested annotation targets.AnnotationInstance
annotation(DotName name)
Returns the annotation instance with given name declared on this annotation target or any of its nested annotation targets.java.util.Collection<AnnotationInstance>
annotations()
Returns the annotation instances declared on this annotation target and nested annotation targets.default java.util.Collection<AnnotationInstance>
annotations(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instances of given type declared on this annotation target and nested annotation targets.default java.util.Collection<AnnotationInstance>
annotations(java.lang.String name)
Returns the annotation instances with given name declared on this annotation target and nested annotation targets.java.util.Collection<AnnotationInstance>
annotations(DotName name)
Returns the annotation instances with given name declared on this annotation target and nested annotation targets.default java.util.Collection<AnnotationInstance>
annotationsWithRepeatable(java.lang.Class<? extends java.lang.annotation.Annotation> clazz, IndexView index)
Returns the annotation instances of given type declared on this annotation target and nested annotation targets.default java.util.Collection<AnnotationInstance>
annotationsWithRepeatable(java.lang.String name, IndexView index)
Returns the annotation instances with given name declared on this annotation target and nested annotation targets.java.util.Collection<AnnotationInstance>
annotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this annotation target and nested annotation targets.ClassInfo
asClass()
Casts and returns this target as aClassInfo
if it is of kindCLASS
Declaration
asDeclaration()
Casts and returns this annotation target as aDeclaration
if it is a declaration.FieldInfo
asField()
Casts and returns this target as aFieldInfo
if it is of kindFIELD
MethodInfo
asMethod()
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
MethodParameterInfo
asMethodParameter()
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
RecordComponentInfo
asRecordComponent()
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
TypeTarget
asType()
Casts and returns this target as aTypeTarget
if it is of kindTYPE
default AnnotationInstance
declaredAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instance of given type declared on this annotation target.default AnnotationInstance
declaredAnnotation(java.lang.String name)
Returns the annotation instance with given name declared on this annotation target.AnnotationInstance
declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this annotation target.java.util.Collection<AnnotationInstance>
declaredAnnotations()
Returns the annotation instances declared on this annotation target.default java.util.Collection<AnnotationInstance>
declaredAnnotationsWithRepeatable(java.lang.Class<? extends java.lang.annotation.Annotation> clazz, IndexView index)
Returns the annotation instances of given type declared on this annotation target.default java.util.Collection<AnnotationInstance>
declaredAnnotationsWithRepeatable(java.lang.String name, IndexView index)
Returns the annotation instances with given name declared on this annotation target.java.util.Collection<AnnotationInstance>
declaredAnnotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this annotation target.default boolean
hasAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns whether an annotation instance of given type is declared on this annotation target or any of its nested annotation targets.default boolean
hasAnnotation(java.lang.String name)
Returns whether an annotation instance with given name is declared on this annotation target or any of its nested annotation targets.boolean
hasAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this annotation target or any of its nested annotation targets.default boolean
hasDeclaredAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns whether an annotation instance of given type is declared on this annotation target.default boolean
hasDeclaredAnnotation(java.lang.String name)
Returns whether an annotation instance with given name is declared on this annotation target.boolean
hasDeclaredAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this annotation target.boolean
isDeclaration()
Returns whether this annotation target is a declaration.AnnotationTarget.Kind
kind()
Returns the kind of object this target represents.
-
-
-
Method Detail
-
kind
AnnotationTarget.Kind kind()
Returns the kind of object this target represents.- Returns:
- the target kind.
- Since:
- 2.0
-
isDeclaration
boolean isDeclaration()
Returns whether this annotation target is a declaration.- Returns:
- whether this annotation target is a declaration
- Since:
- 3.1.0
-
asDeclaration
Declaration asDeclaration()
Casts and returns this annotation target as aDeclaration
if it is a declaration.- Returns:
- this instance cast to a declaration
- Since:
- 3.1.0
-
asClass
ClassInfo asClass()
Casts and returns this target as aClassInfo
if it is of kindCLASS
- Returns:
- this instance cast to a class
- Since:
- 2.0
-
asField
FieldInfo asField()
Casts and returns this target as aFieldInfo
if it is of kindFIELD
- Returns:
- this instance cast to a field
- Since:
- 2.0
-
asMethod
MethodInfo asMethod()
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
- Returns:
- this instance cast to a method
- Since:
- 2.0
-
asMethodParameter
MethodParameterInfo asMethodParameter()
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
- Returns:
- this instance cast to a method parameter
- Since:
- 2.0
-
asType
TypeTarget asType()
Casts and returns this target as aTypeTarget
if it is of kindTYPE
- Returns:
- this instance cast to a type target
- Since:
- 2.0
-
asRecordComponent
RecordComponentInfo asRecordComponent()
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
- Returns:
- this instance cast to a record component
- Since:
- 2.4
-
hasAnnotation
boolean hasAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this annotation target or any of its nested annotation targets.- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
annotation(DotName)
-
hasAnnotation
default boolean hasAnnotation(java.lang.String name)
Returns whether an annotation instance with given name is declared on this annotation target or any of its nested annotation targets.- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
annotation(DotName)
-
hasAnnotation
default boolean hasAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns whether an annotation instance of given type is declared on this annotation target or any of its nested annotation targets.- Parameters:
clazz
- the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
annotation(DotName)
-
annotation
AnnotationInstance annotation(DotName name)
Returns the annotation instance with given name declared on this annotation target or any of its nested annotation targets. Thetarget()
method of the returned annotation instance may be used to determine the exact location of the annotation instance.In case an annotation with given name occurs more than once, the result of this method is not deterministic. For such situations,
annotations(DotName)
is preferable.- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
annotations(DotName)
-
annotation
default AnnotationInstance annotation(java.lang.String name)
Returns the annotation instance with given name declared on this annotation target or any of its nested annotation targets. Thetarget()
method of the returned annotation instance may be used to determine the exact location of the annotation instance.In case an annotation with given name occurs more than once, the result of this method is not deterministic. For such situations,
annotations(DotName)
is preferable.- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
annotations(DotName)
-
annotation
default AnnotationInstance annotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instance of given type declared on this annotation target or any of its nested annotation targets. Thetarget()
method of the returned annotation instance may be used to determine the exact location of the annotation instance.In case an annotation with given name occurs more than once, the result of this method is not deterministic. For such situations,
annotations(DotName)
is preferable.- Parameters:
clazz
- the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
annotations(DotName)
-
annotations
java.util.Collection<AnnotationInstance> annotations(DotName name)
Returns the annotation instances with given name declared on this annotation target and nested annotation targets. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.- Parameters:
name
- name of the annotation type, must not benull
- Returns:
- immutable collection of annotation instances, never
null
- Since:
- 3.0
- See Also:
annotationsWithRepeatable(DotName, IndexView)
,annotations()
-
annotations
default java.util.Collection<AnnotationInstance> annotations(java.lang.String name)
Returns the annotation instances with given name declared on this annotation target and nested annotation targets. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.- Parameters:
name
- name of the annotation type, must not benull
- Returns:
- immutable collection of annotation instances, never
null
- Since:
- 3.0
- See Also:
annotationsWithRepeatable(DotName, IndexView)
,annotations()
-
annotations
default java.util.Collection<AnnotationInstance> annotations(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instances of given type declared on this annotation target and nested annotation targets. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.- Parameters:
clazz
- the annotation type, must not benull
- Returns:
- immutable collection of annotation instances, never
null
- Since:
- 3.0
- See Also:
annotationsWithRepeatable(DotName, IndexView)
,annotations()
-
annotationsWithRepeatable
java.util.Collection<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this annotation target and nested annotation targets. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable collection of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
annotations(DotName)
,annotations()
-
annotationsWithRepeatable
default java.util.Collection<AnnotationInstance> annotationsWithRepeatable(java.lang.String name, IndexView index)
Returns the annotation instances with given name declared on this annotation target and nested annotation targets. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable collection of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
annotations(DotName)
,annotations()
-
annotationsWithRepeatable
default java.util.Collection<AnnotationInstance> annotationsWithRepeatable(java.lang.Class<? extends java.lang.annotation.Annotation> clazz, IndexView index)
Returns the annotation instances of given type declared on this annotation target and nested annotation targets. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.- Parameters:
clazz
- the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable collection of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
annotations(DotName)
,annotations()
-
annotations
java.util.Collection<AnnotationInstance> annotations()
Returns the annotation instances declared on this annotation target and nested annotation targets. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.- Returns:
- immutable collection of annotation instances, never
null
- Since:
- 3.0
-
hasDeclaredAnnotation
boolean hasDeclaredAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this annotation target.Unlike
hasAnnotation(DotName)
, this method ignores annotations declared on nested annotation targets.- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
hasAnnotation(DotName)
-
hasDeclaredAnnotation
default boolean hasDeclaredAnnotation(java.lang.String name)
Returns whether an annotation instance with given name is declared on this annotation target.Unlike
hasAnnotation(DotName)
, this method ignores annotations declared on nested annotation targets.- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
hasAnnotation(DotName)
-
hasDeclaredAnnotation
default boolean hasDeclaredAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns whether an annotation instance of given type is declared on this annotation target.Unlike
hasAnnotation(DotName)
, this method ignores annotations declared on nested annotation targets.- Parameters:
clazz
- the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
hasAnnotation(DotName)
-
declaredAnnotation
AnnotationInstance declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this annotation target.Unlike
annotation(DotName)
, this method doesn't return annotations declared on nested annotation targets.- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
annotation(DotName)
-
declaredAnnotation
default AnnotationInstance declaredAnnotation(java.lang.String name)
Returns the annotation instance with given name declared on this annotation target.Unlike
annotation(DotName)
, this method doesn't return annotations declared on nested annotation targets.- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
annotation(DotName)
-
declaredAnnotation
default AnnotationInstance declaredAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instance of given type declared on this annotation target.Unlike
annotation(DotName)
, this method doesn't return annotations declared on nested annotation targets.- Parameters:
clazz
- the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
annotation(DotName)
-
declaredAnnotationsWithRepeatable
java.util.Collection<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this annotation target.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.Unlike
annotationsWithRepeatable(DotName, IndexView)
, this method doesn't return annotations declared on nested annotation targets.- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable collection of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
annotationsWithRepeatable(DotName, IndexView)
-
declaredAnnotationsWithRepeatable
default java.util.Collection<AnnotationInstance> declaredAnnotationsWithRepeatable(java.lang.String name, IndexView index)
Returns the annotation instances with given name declared on this annotation target.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.Unlike
annotationsWithRepeatable(DotName, IndexView)
, this method doesn't return annotations declared on nested annotation targets.- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable collection of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
annotationsWithRepeatable(DotName, IndexView)
-
declaredAnnotationsWithRepeatable
default java.util.Collection<AnnotationInstance> declaredAnnotationsWithRepeatable(java.lang.Class<? extends java.lang.annotation.Annotation> clazz, IndexView index)
Returns the annotation instances of given type declared on this annotation target.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.Unlike
annotationsWithRepeatable(DotName, IndexView)
, this method doesn't return annotations declared on nested annotation targets.- Parameters:
clazz
- the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable collection of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
annotationsWithRepeatable(DotName, IndexView)
-
declaredAnnotations
java.util.Collection<AnnotationInstance> declaredAnnotations()
Returns the annotation instances declared on this annotation target.Unlike
annotations()
, this method doesn't return annotations declared on nested annotation targets.- Returns:
- immutable collection of annotation instances, never
null
- Since:
- 3.0
- See Also:
annotations()
-
-