Class ThrowsTypeTarget

All Implemented Interfaces:
AnnotationTarget

public class ThrowsTypeTarget extends PositionBasedTypeTarget
Represents a type annotation target which occurs within a throwable type on a method. This class conveys the enclosing method and the zero-based position of the throwable that is thrown. Since type targets can appear at any depth of the type tree at this location, the corresponding type reference is also included.

Consider the following example involving a type target using the "Bar" annotation:

 public void foo(List<T>) throws FooException<@Bar T> { ... }
 

This example would be represented as a ThrowsTypeTarget with an enclosing target of foo's MethodInfo, and position() would return 0, indicating the first entry of the list returned by exceptions(). The "Bar" annotation would appear on the type variable T.

Since:
2.0
  • Constructor Details

    • ThrowsTypeTarget

      ThrowsTypeTarget(MethodInfo enclosingTarget, int position)
    • ThrowsTypeTarget

      ThrowsTypeTarget(AnnotationTarget enclosingTarget, Type target, int position)
  • Method Details

    • usage

      public TypeTarget.Usage usage()
      Description copied from class: TypeTarget
      Returns the kind of usage of this type target. This allows a caller to use a switch statement as opposed to getClass() comparisons.
      Specified by:
      usage in class TypeTarget
      Returns:
      the kind of usage of this type target
    • enclosingTarget

      public MethodInfo enclosingTarget()
      Description copied from class: TypeTarget
      Returns the enclosing target that contains the type referred to by the TypeTarget.target() method.
      Overrides:
      enclosingTarget in class TypeTarget
      Returns:
      the enclosing target
    • asThrows

      public ThrowsTypeTarget asThrows()
      Description copied from class: TypeTarget
      Casts and returns this type target as a ThrowsTypeTarget. If this type target is not a ThrowsTypeTarget, then an exception will be thrown.
      Overrides:
      asThrows in class TypeTarget
      Returns:
      an instance of ThrowsTypeTarget