Package org.jboss.jandex
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 classTypeTarget.UsageSpecifies 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 AnnotationTargetenclosingTargetprivate Typetarget
-
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 ClassInfoasClass()Casts and returns this target as aClassInfoif it is of kindCLASSClassExtendsTypeTargetasClassExtends()Casts and returns this type target as aClassExtendsTypeTarget.EmptyTypeTargetasEmpty()FieldInfoasField()Casts and returns this target as aFieldInfoif it is of kindFIELDMethodInfoasMethod()Casts and returns this target as aMethodInfoif it is of kindMETHODMethodParameterInfoasMethodParameter()Casts and returns this target as aMethodParameterInfoif it is of kindMETHOD_PARAMETERMethodParameterTypeTargetasMethodParameterType()Casts and returns this type target as aMethodParameterTypeTarget.RecordComponentInfoasRecordComponent()Casts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENTThrowsTypeTargetasThrows()Casts and returns this type target as aThrowsTypeTarget.TypeTargetasType()Casts and returns this target as aTypeTargetif it is of kindTYPETypeParameterTypeTargetasTypeParameter()Casts and returns this type target as aTypeParameterTypeTarget.TypeParameterBoundTypeTargetasTypeParameterBound()Casts and returns this type target as aTypeParameterBoundTypeTarget.AnnotationTargetenclosingTarget()Returns the enclosing target that contains the type referred to by thetarget()method.AnnotationTarget.Kindkind()Returns the kind of object this target represents.(package private) voidsetTarget(Type target)Typetarget()Returns the type which contains the respective annotation.abstract TypeTarget.Usageusage()Returns the kind of usage of this type target.
-
-
-
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:AnnotationTargetReturns the kind of object this target represents.- Specified by:
kindin interfaceAnnotationTarget- Returns:
- the target kind.
-
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:AnnotationTargetCasts and returns this target as aClassInfoif it is of kindCLASS- Specified by:
asClassin interfaceAnnotationTarget- Returns:
- this instance cast to a class
-
asField
public final FieldInfo 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
public final MethodInfo 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
public final MethodParameterInfo 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
public final TypeTarget 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
public RecordComponentInfo 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
-
-