Interface AnnotationTarget
- All Known Subinterfaces:
Declaration
- All Known Implementing Classes:
ClassExtendsTypeTarget,ClassInfo,EmptyTypeTarget,FieldInfo,MethodInfo,MethodParameterInfo,MethodParameterTypeTarget,PositionBasedTypeTarget,RecordComponentInfo,ThrowsTypeTarget,TypeParameterBoundTypeTarget,TypeParameterTypeTarget,TypeTarget
Overall, two distinct kinds of annotation targets exist: declarations and types.
To refer to declarations only, the Declaration interface may be used.
- Author:
- Jason T. Greene
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumSpecifies the kind of object a target represents. -
Method Summary
Modifier and TypeMethodDescriptiondefault AnnotationInstanceannotation(Class<? extends Annotation> clazz) Returns the annotation instance of given type declared on this annotation target or any of its nested annotation targets.default AnnotationInstanceannotation(String name) Returns the annotation instance with given name declared on this annotation target or any of its nested annotation targets.annotation(DotName name) Returns the annotation instance with given name declared on this annotation target or any of its nested annotation targets.Returns the annotation instances declared on this annotation target and nested annotation targets.default Collection<AnnotationInstance>annotations(Class<? extends Annotation> clazz) Returns the annotation instances of given type declared on this annotation target and nested annotation targets.default Collection<AnnotationInstance>annotations(String name) Returns the annotation instances with given name declared on this annotation target and nested annotation targets.annotations(DotName name) Returns the annotation instances with given name declared on this annotation target and nested annotation targets.default Collection<AnnotationInstance>annotationsWithRepeatable(Class<? extends Annotation> clazz, IndexView index) Returns the annotation instances of given type declared on this annotation target and nested annotation targets.default Collection<AnnotationInstance>annotationsWithRepeatable(String name, IndexView index) Returns the annotation instances with given name declared on this annotation target and nested annotation targets.annotationsWithRepeatable(DotName name, IndexView index) Returns the annotation instances with given name declared on this annotation target and nested annotation targets.asClass()Casts and returns this target as aClassInfoif it is of kindCLASSCasts and returns this annotation target as aDeclarationif it is a declaration.asField()Casts and returns this target as aFieldInfoif it is of kindFIELDasMethod()Casts and returns this target as aMethodInfoif it is of kindMETHODCasts and returns this target as aMethodParameterInfoif it is of kindMETHOD_PARAMETERCasts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENTasType()Casts and returns this target as aTypeTargetif it is of kindTYPEdefault AnnotationInstancedeclaredAnnotation(Class<? extends Annotation> clazz) Returns the annotation instance of given type declared on this annotation target.default AnnotationInstancedeclaredAnnotation(String name) Returns the annotation instance with given name declared on this annotation target.declaredAnnotation(DotName name) Returns the annotation instance with given name declared on this annotation target.Returns the annotation instances declared on this annotation target.default Collection<AnnotationInstance>declaredAnnotationsWithRepeatable(Class<? extends Annotation> clazz, IndexView index) Returns the annotation instances of given type declared on this annotation target.default Collection<AnnotationInstance>declaredAnnotationsWithRepeatable(String name, IndexView index) Returns the annotation instances with given name declared on this annotation target.declaredAnnotationsWithRepeatable(DotName name, IndexView index) Returns the annotation instances with given name declared on this annotation target.default booleanhasAnnotation(Class<? extends Annotation> clazz) Returns whether an annotation instance of given type is declared on this annotation target or any of its nested annotation targets.default booleanhasAnnotation(String name) Returns whether an annotation instance with given name is declared on this annotation target or any of its nested annotation targets.booleanhasAnnotation(DotName name) Returns whether an annotation instance with given name is declared on this annotation target or any of its nested annotation targets.default booleanhasDeclaredAnnotation(Class<? extends Annotation> clazz) Returns whether an annotation instance of given type is declared on this annotation target.default booleanhasDeclaredAnnotation(String name) Returns whether an annotation instance with given name is declared on this annotation target.booleanhasDeclaredAnnotation(DotName name) Returns whether an annotation instance with given name is declared on this annotation target.booleanReturns whether this annotation target is a declaration.kind()Returns the kind of object this target represents.
-
Method Details
-
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 aDeclarationif it is a declaration.- Returns:
- this instance cast to a declaration
- Since:
- 3.1.0
-
asClass
ClassInfo asClass()Casts and returns this target as aClassInfoif it is of kindCLASS- Returns:
- this instance cast to a class
- Since:
- 2.0
-
asField
FieldInfo asField()Casts and returns this target as aFieldInfoif it is of kindFIELD- Returns:
- this instance cast to a field
- Since:
- 2.0
-
asMethod
MethodInfo asMethod()Casts and returns this target as aMethodInfoif it is of kindMETHOD- Returns:
- this instance cast to a method
- Since:
- 2.0
-
asMethodParameter
MethodParameterInfo asMethodParameter()Casts and returns this target as aMethodParameterInfoif 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 aTypeTargetif it is of kindTYPE- Returns:
- this instance cast to a type target
- Since:
- 2.0
-
asRecordComponent
RecordComponentInfo asRecordComponent()Casts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENT- Returns:
- this instance cast to a record component
- Since:
- 2.4
-
hasAnnotation
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:
trueif the annotation is present,falseotherwise- Since:
- 3.0
- See Also:
-
hasAnnotation
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:
trueif the annotation is present,falseotherwise- Since:
- 3.0
- See Also:
-
hasAnnotation
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:
trueif the annotation is present,falseotherwise- Since:
- 3.0
- See Also:
-
annotation
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
nullif not found - Since:
- 3.0
- See Also:
-
annotation
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
nullif not found - Since:
- 3.0
- See Also:
-
annotation
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
nullif not found - Since:
- 3.0
- See Also:
-
annotations
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:
-
annotations
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:
-
annotations
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
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 benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable collection of annotation instances, never
null - Throws:
IllegalArgumentException- if the index isnull, if the index does not contain the annotation type or ifnamedoes not identify an annotation type- Since:
- 3.0
- See Also:
-
annotationsWithRepeatable
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 benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable collection of annotation instances, never
null - Throws:
IllegalArgumentException- if the index isnull, if the index does not contain the annotation type or ifnamedoes not identify an annotation type- Since:
- 3.0
- See Also:
-
annotationsWithRepeatable
default Collection<AnnotationInstance> annotationsWithRepeatable(Class<? extends 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 benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable collection of annotation instances, never
null - Throws:
IllegalArgumentException- if the index isnull, if the index does not contain the annotation type or ifnamedoes not identify an annotation type- Since:
- 3.0
- See Also:
-
annotations
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
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:
trueif the annotation is present,falseotherwise- Since:
- 3.0
- See Also:
-
hasDeclaredAnnotation
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:
trueif the annotation is present,falseotherwise- Since:
- 3.0
- See Also:
-
hasDeclaredAnnotation
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:
trueif the annotation is present,falseotherwise- Since:
- 3.0
- See Also:
-
declaredAnnotation
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
nullif not found - Since:
- 3.0
- See Also:
-
declaredAnnotation
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
nullif not found - Since:
- 3.0
- See Also:
-
declaredAnnotation
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
nullif not found - Since:
- 3.0
- See Also:
-
declaredAnnotationsWithRepeatable
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 benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable collection of annotation instances, never
null - Throws:
IllegalArgumentException- if the index isnull, if the index does not contain the annotation type or ifnamedoes not identify an annotation type- Since:
- 3.0
- See Also:
-
declaredAnnotationsWithRepeatable
default Collection<AnnotationInstance> declaredAnnotationsWithRepeatable(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 benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable collection of annotation instances, never
null - Throws:
IllegalArgumentException- if the index isnull, if the index does not contain the annotation type or ifnamedoes not identify an annotation type- Since:
- 3.0
- See Also:
-
declaredAnnotationsWithRepeatable
default Collection<AnnotationInstance> declaredAnnotationsWithRepeatable(Class<? extends 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 benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable collection of annotation instances, never
null - Throws:
IllegalArgumentException- if the index isnull, if the index does not contain the annotation type or ifnamedoes not identify an annotation type- Since:
- 3.0
- See Also:
-
declaredAnnotations
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:
-