Class TypeTarget

java.lang.Object
org.jboss.jandex.TypeTarget
All Implemented Interfaces:
AnnotationTarget
Direct Known Subclasses:
EmptyTypeTarget, PositionBasedTypeTarget

public abstract class TypeTarget extends 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

Since:
2.0
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • 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 interface AnnotationTarget
      Returns:
      the target kind.
    • enclosingTarget

      public AnnotationTarget enclosingTarget()
      Returns the enclosing target that contains the type referred to by the target() 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 to getClass() 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 a ClassExtendsTypeTarget. If this type target is not a ClassExtendsTypeTarget, then an exception will be thrown.
      Returns:
      an instance of ClassExtendsTypeTarget
      Throws:
      IllegalArgumentException - if this is not a ClassExtendsTypeTarget
    • asMethodParameterType

      public MethodParameterTypeTarget asMethodParameterType()
      Casts and returns this type target as a MethodParameterTypeTarget. If this type target is not a MethodParameterTypeTarget, then an exception will be thrown.
      Returns:
      an instance of MethodParameterTypeTarget
      Throws:
      IllegalArgumentException - if this is not a MethodParameterTypeTarget
    • asTypeParameter

      public TypeParameterTypeTarget asTypeParameter()
      Casts and returns this type target as a TypeParameterTypeTarget. If this type target is not a TypeParameterTypeTarget, then an exception will be thrown.
      Returns:
      an instance of TypeParameterTypeTarget
      Throws:
      IllegalArgumentException - if this is not a TypeParameterTypeTarget
    • asTypeParameterBound

      public TypeParameterBoundTypeTarget asTypeParameterBound()
      Casts and returns this type target as a TypeParameterBoundTypeTarget. If this type target is not a TypeParameterBoundTypeTarget, then an exception will be thrown.
      Returns:
      an instance of TypeParameterBoundTypeTarget
      Throws:
      IllegalArgumentException - if this is not a TypeParameterBoundTypeTarget
    • asThrows

      public ThrowsTypeTarget asThrows()
      Casts and returns this type target as a ThrowsTypeTarget. If this type target is not a ThrowsTypeTarget, then an exception will be thrown.
      Returns:
      an instance of ThrowsTypeTarget
      Throws:
      IllegalArgumentException - if this is not a TypeParameterBoundTypeTarget
    • asClass

      public final ClassInfo asClass()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a ClassInfo if it is of kind CLASS
      Specified by:
      asClass in interface AnnotationTarget
      Returns:
      this instance cast to a class
    • asField

      public final FieldInfo asField()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a FieldInfo if it is of kind FIELD
      Specified by:
      asField in interface AnnotationTarget
      Returns:
      this instance cast to a field
    • asMethod

      public final MethodInfo asMethod()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a MethodInfo if it is of kind METHOD
      Specified by:
      asMethod in interface AnnotationTarget
      Returns:
      this instance cast to a method
    • asMethodParameter

      public final MethodParameterInfo asMethodParameter()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a MethodParameterInfo if it is of kind METHOD_PARAMETER
      Specified by:
      asMethodParameter in interface AnnotationTarget
      Returns:
      this instance cast to a method parameter
    • asType

      public final TypeTarget asType()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a TypeTarget if it is of kind TYPE
      Specified by:
      asType in interface AnnotationTarget
      Returns:
      this instance cast to a type target
    • asRecordComponent

      public RecordComponentInfo asRecordComponent()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a RecordComponentInfo if it is of kind RECORD_COMPONENT
      Specified by:
      asRecordComponent in interface AnnotationTarget
      Returns:
      this instance cast to a record component