Class TypeTarget
- All Implemented Interfaces:
AnnotationTarget
- Direct Known Subclasses:
EmptyTypeTarget,PositionBasedTypeTarget
It is expected that callers will traverse the full tree from the specified starting point, since this context is important in interpreting the meaning of the type annotation
- Author:
- Jason T. Greene
- Since:
- 2.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSpecifies a form of usage of a type annotationNested classes/interfaces inherited from interface org.jboss.jandex.AnnotationTarget
AnnotationTarget.Kind -
Method Summary
Modifier and TypeMethodDescriptionannotation(DotName name) Returns the annotation instance with given name declared on this type usage.Returns the annotation instances declared on this type usage.annotations(DotName name) Returns the annotation instances with given name declared on this type usage.annotationsWithRepeatable(DotName name, IndexView index) Returns the annotation instances with given name declared on this type usage.final ClassInfoasClass()Casts and returns this target as aClassInfoif it is of kindCLASSCasts and returns this type target as aClassExtendsTypeTarget.asEmpty()final FieldInfoasField()Casts and returns this target as aFieldInfoif it is of kindFIELDfinal MethodInfoasMethod()Casts and returns this target as aMethodInfoif it is of kindMETHODfinal MethodParameterInfoCasts and returns this target as aMethodParameterInfoif it is of kindMETHOD_PARAMETERCasts and returns this type target as aMethodParameterTypeTarget.final RecordComponentInfoCasts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENTasThrows()Casts and returns this type target as aThrowsTypeTarget.final TypeTargetasType()Casts and returns this target as aTypeTargetif it is of kindTYPECasts and returns this type target as aTypeParameterTypeTarget.Casts and returns this type target as aTypeParameterBoundTypeTarget.declaredAnnotation(DotName name) Returns the annotation instance with given name declared on this type usage.Returns the annotation instances declared on this type usage.declaredAnnotationsWithRepeatable(DotName name, IndexView index) Returns the annotation instances with given name declared on this type usage.Returns the enclosing target that contains the type referred to by thetarget()method.booleanhasAnnotation(DotName name) Returns whether an annotation instance with given name is declared on this type usage.booleanhasDeclaredAnnotation(DotName name) Returns whether an annotation instance with given name is declared on this type usage.final AnnotationTarget.Kindkind()Returns the kind of object this target represents.target()Returns the type which contains the respective annotation.abstract TypeTarget.Usageusage()Returns the kind of usage of this type target.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jboss.jandex.AnnotationTarget
annotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation
-
Method Details
-
kind
Description copied from interface:AnnotationTargetReturns the kind of object this target represents.- Specified by:
kindin interfaceAnnotationTarget- Returns:
- the target kind.
-
enclosingTarget
Returns the enclosing target that contains the type referred to by thetarget()method.- Returns:
- the enclosing target
-
target
Returns the type which contains the respective annotation. In some cases this may be null (e.g. in the case of a bridge method, which erases type information so there is no target to map to)- Returns:
- the type containing the respective annotation
-
usage
Returns the kind of usage of this type target. This allows a caller to use a switch statement as opposed togetClass()comparisons.- Returns:
- the kind of usage of this type target
-
asEmpty
-
asClassExtends
Casts and returns this type target as aClassExtendsTypeTarget. If this type target is not aClassExtendsTypeTarget, then an exception will be thrown.- Returns:
- an instance of
ClassExtendsTypeTarget - Throws:
IllegalArgumentException- if this is not aClassExtendsTypeTarget
-
asMethodParameterType
Casts and returns this type target as aMethodParameterTypeTarget. If this type target is not aMethodParameterTypeTarget, then an exception will be thrown.- Returns:
- an instance of
MethodParameterTypeTarget - Throws:
IllegalArgumentException- if this is not aMethodParameterTypeTarget
-
asTypeParameter
Casts and returns this type target as aTypeParameterTypeTarget. If this type target is not aTypeParameterTypeTarget, then an exception will be thrown.- Returns:
- an instance of
TypeParameterTypeTarget - Throws:
IllegalArgumentException- if this is not aTypeParameterTypeTarget
-
asTypeParameterBound
Casts and returns this type target as aTypeParameterBoundTypeTarget. If this type target is not aTypeParameterBoundTypeTarget, then an exception will be thrown.- Returns:
- an instance of
TypeParameterBoundTypeTarget - Throws:
IllegalArgumentException- if this is not aTypeParameterBoundTypeTarget
-
asThrows
Casts and returns this type target as aThrowsTypeTarget. If this type target is not aThrowsTypeTarget, then an exception will be thrown.- Returns:
- an instance of
ThrowsTypeTarget - Throws:
IllegalArgumentException- if this is not aTypeParameterBoundTypeTarget
-
asClass
Description copied from interface:AnnotationTargetCasts and returns this target as aClassInfoif it is of kindCLASS- Specified by:
asClassin interfaceAnnotationTarget- Returns:
- this instance cast to a class
-
asField
Description copied from interface:AnnotationTargetCasts and returns this target as aFieldInfoif it is of kindFIELD- Specified by:
asFieldin interfaceAnnotationTarget- Returns:
- this instance cast to a field
-
asMethod
Description copied from interface:AnnotationTargetCasts and returns this target as aMethodInfoif it is of kindMETHOD- Specified by:
asMethodin interfaceAnnotationTarget- Returns:
- this instance cast to a method
-
asMethodParameter
Description copied from interface:AnnotationTargetCasts and returns this target as aMethodParameterInfoif it is of kindMETHOD_PARAMETER- Specified by:
asMethodParameterin interfaceAnnotationTarget- Returns:
- this instance cast to a method parameter
-
asType
Description copied from interface:AnnotationTargetCasts and returns this target as aTypeTargetif it is of kindTYPE- Specified by:
asTypein interfaceAnnotationTarget- Returns:
- this instance cast to a type target
-
asRecordComponent
Description copied from interface:AnnotationTargetCasts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENT- Specified by:
asRecordComponentin interfaceAnnotationTarget- Returns:
- this instance cast to a record component
-
hasAnnotation
Returns whether an annotation instance with given name is declared on this type usage.Note that unlike other
AnnotationTargets, this method doesn't inspect nested annotation targets, even though array types, parameterized types, type variables and wildcard types may contain other types inside them. In other words, this method is equivalent tohasDeclaredAnnotation(DotName).- Specified by:
hasAnnotationin interfaceAnnotationTarget- 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:
-
annotation
Returns the annotation instance with given name declared on this type usage.Note that unlike other
AnnotationTargets, this method doesn't inspect nested annotation targets, even though array types, parameterized types, type variables and wildcard types may contain other types inside them. In other words, this method is equivalent todeclaredAnnotation(DotName).- Specified by:
annotationin interfaceAnnotationTarget- 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:
-
annotations
Returns the annotation instances with given name declared on this type usage.Note that unlike other
AnnotationTargets, this method doesn't inspect nested annotation targets, even though array types, parameterized types, type variables and wildcard types may contain other types inside them. In other words, this method is equivalent toannotation(DotName)anddeclaredAnnotation(DotName), except it returns a list.- Specified by:
annotationsin interfaceAnnotationTarget- Parameters:
name- name of the annotation type, must not benull- Returns:
- immutable list of annotation instances, never
null - Since:
- 3.0
- See Also:
-
annotationsWithRepeatable
Returns the annotation instances with given name declared on this type usage.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.Note that unlike other
AnnotationTargets, this method doesn't inspect nested annotation targets, even though array types, parameterized types, type variables and wildcard types may contain other types inside them. In other words, this method is equivalent todeclaredAnnotationsWithRepeatable(DotName, IndexView).- Specified by:
annotationsWithRepeatablein interfaceAnnotationTarget- Parameters:
name- name of the annotation type, must not benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable list 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
Returns the annotation instances declared on this type usage.Note that unlike other
AnnotationTargets, this method doesn't inspect nested annotation targets, even though array types, parameterized types, type variables and wildcard types may contain other types inside them. In other words, this method is equivalent todeclaredAnnotations().- Specified by:
annotationsin interfaceAnnotationTarget- Returns:
- immutable list of annotation instances, never
null - Since:
- 3.0
-
hasDeclaredAnnotation
Returns whether an annotation instance with given name is declared on this type usage.- Specified by:
hasDeclaredAnnotationin interfaceAnnotationTarget- 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:
-
declaredAnnotation
Returns the annotation instance with given name declared on this type usage.- Specified by:
declaredAnnotationin interfaceAnnotationTarget- 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:
-
declaredAnnotationsWithRepeatable
Returns the annotation instances with given name declared on this type usage.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.- Specified by:
declaredAnnotationsWithRepeatablein interfaceAnnotationTarget- Parameters:
name- name of the annotation type, must not benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable list 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
Returns the annotation instances declared on this type usage.- Specified by:
declaredAnnotationsin interfaceAnnotationTarget- Returns:
- immutable list of annotation instances, never
null - Since:
- 3.0
- See Also:
-