Class TypeTarget
- java.lang.Object
-
- org.jboss.jandex.TypeTarget
-
- All Implemented Interfaces:
AnnotationTarget
- Direct Known Subclasses:
EmptyTypeTarget
,PositionBasedTypeTarget
public abstract class TypeTarget extends java.lang.Object implements AnnotationTarget
Represents a type that is the target of a type annotation. Type annotations can occur at any nesting level on any type declaration. For this reason, an enclosing target is provided, as well as other usage specific information to determine the starting point for locating the type.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TypeTarget.Usage
Specifies a form of usage of a type annotation-
Nested classes/interfaces inherited from interface org.jboss.jandex.AnnotationTarget
AnnotationTarget.Kind
-
-
Field Summary
Fields Modifier and Type Field Description private AnnotationTarget
enclosingTarget
private Type
target
-
Constructor Summary
Constructors Constructor Description TypeTarget(AnnotationTarget enclosingTarget)
TypeTarget(AnnotationTarget enclosingTarget, Type target)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description AnnotationInstance
annotation(DotName name)
Returns the annotation instance with given name declared on this type usage.java.util.List<AnnotationInstance>
annotations()
Returns the annotation instances declared on this type usage.java.util.List<AnnotationInstance>
annotations(DotName name)
Returns the annotation instances with given name declared on this type usage.java.util.List<AnnotationInstance>
annotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this type usage.ClassInfo
asClass()
Casts and returns this target as aClassInfo
if it is of kindCLASS
ClassExtendsTypeTarget
asClassExtends()
Casts and returns this type target as aClassExtendsTypeTarget
.Declaration
asDeclaration()
Casts and returns this annotation target as aDeclaration
if it is a declaration.EmptyTypeTarget
asEmpty()
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
MethodParameterTypeTarget
asMethodParameterType()
Casts and returns this type target as aMethodParameterTypeTarget
.RecordComponentInfo
asRecordComponent()
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
ThrowsTypeTarget
asThrows()
Casts and returns this type target as aThrowsTypeTarget
.TypeTarget
asType()
Casts and returns this target as aTypeTarget
if it is of kindTYPE
TypeParameterTypeTarget
asTypeParameter()
Casts and returns this type target as aTypeParameterTypeTarget
.TypeParameterBoundTypeTarget
asTypeParameterBound()
Casts and returns this type target as aTypeParameterBoundTypeTarget
.AnnotationInstance
declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this type usage.java.util.List<AnnotationInstance>
declaredAnnotations()
Returns the annotation instances declared on this type usage.java.util.List<AnnotationInstance>
declaredAnnotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this type usage.AnnotationTarget
enclosingTarget()
Returns the enclosing target that contains the type referred to by thetarget()
method.boolean
hasAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this type usage.boolean
hasDeclaredAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this type usage.boolean
isDeclaration()
Returns whether this annotation target is a declaration.AnnotationTarget.Kind
kind()
Returns the kind of object this target represents.(package private) void
setTarget(Type target)
Type
target()
Returns the type which contains the respective annotation.abstract TypeTarget.Usage
usage()
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, wait
-
Methods inherited from interface org.jboss.jandex.AnnotationTarget
annotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation
-
-
-
-
Field Detail
-
enclosingTarget
private final AnnotationTarget enclosingTarget
-
target
private Type target
-
-
Constructor Detail
-
TypeTarget
TypeTarget(AnnotationTarget enclosingTarget, Type target)
-
TypeTarget
TypeTarget(AnnotationTarget enclosingTarget)
-
-
Method Detail
-
setTarget
void setTarget(Type target)
-
kind
public final AnnotationTarget.Kind kind()
Description copied from interface:AnnotationTarget
Returns the kind of object this target represents.- Specified by:
kind
in interfaceAnnotationTarget
- Returns:
- the target kind.
-
isDeclaration
public boolean isDeclaration()
Description copied from interface:AnnotationTarget
Returns whether this annotation target is a declaration.- Specified by:
isDeclaration
in interfaceAnnotationTarget
- Returns:
- whether this annotation target is a declaration
-
asDeclaration
public Declaration asDeclaration()
Description copied from interface:AnnotationTarget
Casts and returns this annotation target as aDeclaration
if it is a declaration.- Specified by:
asDeclaration
in interfaceAnnotationTarget
- Returns:
- this instance cast to a declaration
-
enclosingTarget
public AnnotationTarget enclosingTarget()
Returns the enclosing target that contains the type referred to by thetarget()
method.- Returns:
- the enclosing target
-
target
public Type 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
public abstract TypeTarget.Usage 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
public EmptyTypeTarget asEmpty()
-
asClassExtends
public ClassExtendsTypeTarget 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:
java.lang.IllegalArgumentException
- if this is not aClassExtendsTypeTarget
-
asMethodParameterType
public MethodParameterTypeTarget 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:
java.lang.IllegalArgumentException
- if this is not aMethodParameterTypeTarget
-
asTypeParameter
public TypeParameterTypeTarget 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:
java.lang.IllegalArgumentException
- if this is not aTypeParameterTypeTarget
-
asTypeParameterBound
public TypeParameterBoundTypeTarget 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:
java.lang.IllegalArgumentException
- if this is not aTypeParameterBoundTypeTarget
-
asThrows
public ThrowsTypeTarget 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:
java.lang.IllegalArgumentException
- if this is not aTypeParameterBoundTypeTarget
-
asClass
public final ClassInfo asClass()
Description copied from interface:AnnotationTarget
Casts and returns this target as aClassInfo
if it is of kindCLASS
- Specified by:
asClass
in interfaceAnnotationTarget
- Returns:
- this instance cast to a class
-
asField
public final FieldInfo asField()
Description copied from interface:AnnotationTarget
Casts and returns this target as aFieldInfo
if it is of kindFIELD
- Specified by:
asField
in interfaceAnnotationTarget
- Returns:
- this instance cast to a field
-
asMethod
public final MethodInfo asMethod()
Description copied from interface:AnnotationTarget
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
- Specified by:
asMethod
in interfaceAnnotationTarget
- Returns:
- this instance cast to a method
-
asMethodParameter
public final MethodParameterInfo asMethodParameter()
Description copied from interface:AnnotationTarget
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
- Specified by:
asMethodParameter
in interfaceAnnotationTarget
- Returns:
- this instance cast to a method parameter
-
asType
public final TypeTarget asType()
Description copied from interface:AnnotationTarget
Casts and returns this target as aTypeTarget
if it is of kindTYPE
- Specified by:
asType
in interfaceAnnotationTarget
- Returns:
- this instance cast to a type target
-
asRecordComponent
public final RecordComponentInfo asRecordComponent()
Description copied from interface:AnnotationTarget
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
- Specified by:
asRecordComponent
in interfaceAnnotationTarget
- Returns:
- this instance cast to a record component
-
hasAnnotation
public boolean hasAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this type usage.Note that unlike other
AnnotationTarget
s, 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:
hasAnnotation
in interfaceAnnotationTarget
- 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)
-
annotation
public AnnotationInstance annotation(DotName name)
Returns the annotation instance with given name declared on this type usage.Note that unlike other
AnnotationTarget
s, 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:
annotation
in interfaceAnnotationTarget
- 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)
-
annotations
public java.util.List<AnnotationInstance> annotations(DotName name)
Returns the annotation instances with given name declared on this type usage.Note that unlike other
AnnotationTarget
s, 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:
annotations
in 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(DotName, IndexView)
,annotations()
-
annotationsWithRepeatable
public java.util.List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
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
AnnotationTarget
s, 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:
annotationsWithRepeatable
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable list 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
public java.util.List<AnnotationInstance> annotations()
Returns the annotation instances declared on this type usage.Note that unlike other
AnnotationTarget
s, 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:
annotations
in interfaceAnnotationTarget
- Returns:
- immutable list of annotation instances, never
null
- Since:
- 3.0
-
hasDeclaredAnnotation
public boolean hasDeclaredAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this type usage.- Specified by:
hasDeclaredAnnotation
in interfaceAnnotationTarget
- 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)
-
declaredAnnotation
public AnnotationInstance declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this type usage.- Specified by:
declaredAnnotation
in interfaceAnnotationTarget
- 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)
-
declaredAnnotationsWithRepeatable
public java.util.List<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName name, IndexView index)
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:
declaredAnnotationsWithRepeatable
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable list 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
public java.util.List<AnnotationInstance> declaredAnnotations()
Returns the annotation instances declared on this type usage.- Specified by:
declaredAnnotations
in interfaceAnnotationTarget
- Returns:
- immutable list of annotation instances, never
null
- Since:
- 3.0
- See Also:
annotations()
-
-