Package org.apache.bcel.classfile
Class TypeAnnotationEntry
java.lang.Object
org.apache.bcel.classfile.TypeAnnotationEntry
Represents one type annotation of a
TypeAnnotations attribute (JVMS 4.7.20): an annotation, the kind of program element it applies to
(the target type and its target info), and the path to the annotated type inside that element.- Since:
- 6.14.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AnnotationEntrystatic final TypeAnnotationEntry[]Empty array of TypeAnnotationEntry objects.private static final intNumber of bytes of alocalvar_targetentry: start_pc, length and index.private static final intMaximum number of steps of a type path, which its length of one byte limits.static final intTarget type: type in a cast expression.static final intTarget type: type in an extends or implements clause of a class or interface declaration.static final intTarget type: type parameter declaration of a generic class or interface.static final intTarget type: bound of a type parameter of a generic class or interface.static final intTarget type: type argument for a generic constructor in a new expression or an explicit constructor invocation.static final intTarget type: type in a method reference expression using ::new.static final intTarget type: type argument for a generic constructor in a method reference expression using ::new.static final intTarget type: type in an exception parameter declaration.static final intTarget type: type in a field or record component declaration.static final intTarget type: type in an instanceof expression.static final intTarget type: type in a local variable declaration.static final intTarget type: type in a formal parameter declaration of a method, constructor, or lambda expression.static final intTarget type: type argument for a generic method in a method invocation expression.static final intTarget type: receiver type of a method or constructor.static final intTarget type: type in a method reference expression using ::Identifier.static final intTarget type: type argument for a generic method in a method reference expression using ::Identifier.static final intTarget type: return type of a method, or type of a newly constructed object.static final intTarget type: type parameter declaration of a generic method or constructor.static final intTarget type: bound of a type parameter of a generic method or constructor.static final intTarget type: type in a new expression.static final intTarget type: type in a resource variable declaration.static final intTarget type: type in a throws clause of a method or constructor.private final byte[]private final intprivate final byte[] -
Constructor Summary
ConstructorsConstructorDescriptionTypeAnnotationEntry(int targetType, byte[] targetInfo, byte[] typePath, AnnotationEntry annotationEntry) Constructs a TypeAnnotationEntry. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcheckTargetInfo(int targetType, byte[] targetInfo) copy(ConstantPool constantPool) Creates a deep copy of this entry, whose annotation is independent of this one and refers to the given constant pool.voiddump(DataOutputStream dos) Writes this entry to a DataOutputStream.Gets the annotation.byte[]Gets the target info, which depends on the target type (JVMS table 4.7.20-A): for instance the index of the type parameter forTARGET_CLASS_TYPE_PARAMETER, the index of the type parameter then the index of the bound forTARGET_CLASS_TYPE_PARAMETER_BOUND, or the index of the parameter forTARGET_METHOD_FORMAL_PARAMETER.intGets the kind of program element the annotation applies to.intgetTypePathArgumentIndex(int step) Gets the index of the type argument for a step of the type path of kind 3, else 0.intgetTypePathKind(int step) Gets the kind of a step of the type path: 0 deeper in an array type, 1 deeper in a nested type, 2 on the bound of a wildcard type argument, 3 on a type argument of a parameterized type.intGets the number of steps in the type path.static TypeAnnotationEntryread(DataInput input, ConstantPool constantPool, boolean isRuntimeVisible) Factory method to create a TypeAnnotationEntry from a DataInput.private static inttargetInfoSize(int targetType) Gets the number of bytes of the target info that follows a target type.toString()
-
Field Details
-
TARGET_CLASS_TYPE_PARAMETER
public static final int TARGET_CLASS_TYPE_PARAMETERTarget type: type parameter declaration of a generic class or interface.- See Also:
-
TARGET_METHOD_TYPE_PARAMETER
public static final int TARGET_METHOD_TYPE_PARAMETERTarget type: type parameter declaration of a generic method or constructor.- See Also:
-
TARGET_CLASS_EXTENDS
public static final int TARGET_CLASS_EXTENDSTarget type: type in an extends or implements clause of a class or interface declaration.- See Also:
-
TARGET_CLASS_TYPE_PARAMETER_BOUND
public static final int TARGET_CLASS_TYPE_PARAMETER_BOUNDTarget type: bound of a type parameter of a generic class or interface.- See Also:
-
TARGET_METHOD_TYPE_PARAMETER_BOUND
public static final int TARGET_METHOD_TYPE_PARAMETER_BOUNDTarget type: bound of a type parameter of a generic method or constructor.- See Also:
-
TARGET_FIELD
public static final int TARGET_FIELDTarget type: type in a field or record component declaration.- See Also:
-
TARGET_METHOD_RETURN
public static final int TARGET_METHOD_RETURNTarget type: return type of a method, or type of a newly constructed object.- See Also:
-
TARGET_METHOD_RECEIVER
public static final int TARGET_METHOD_RECEIVERTarget type: receiver type of a method or constructor.- See Also:
-
TARGET_METHOD_FORMAL_PARAMETER
public static final int TARGET_METHOD_FORMAL_PARAMETERTarget type: type in a formal parameter declaration of a method, constructor, or lambda expression.- See Also:
-
TARGET_THROWS
public static final int TARGET_THROWSTarget type: type in a throws clause of a method or constructor.- See Also:
-
TARGET_LOCAL_VARIABLE
public static final int TARGET_LOCAL_VARIABLETarget type: type in a local variable declaration.- See Also:
-
TARGET_RESOURCE_VARIABLE
public static final int TARGET_RESOURCE_VARIABLETarget type: type in a resource variable declaration.- See Also:
-
TARGET_EXCEPTION_PARAMETER
public static final int TARGET_EXCEPTION_PARAMETERTarget type: type in an exception parameter declaration.- See Also:
-
TARGET_INSTANCEOF
public static final int TARGET_INSTANCEOFTarget type: type in an instanceof expression.- See Also:
-
TARGET_NEW
public static final int TARGET_NEWTarget type: type in a new expression.- See Also:
-
TARGET_CONSTRUCTOR_REFERENCE
public static final int TARGET_CONSTRUCTOR_REFERENCETarget type: type in a method reference expression using ::new.- See Also:
-
TARGET_METHOD_REFERENCE
public static final int TARGET_METHOD_REFERENCETarget type: type in a method reference expression using ::Identifier.- See Also:
-
TARGET_CAST
public static final int TARGET_CASTTarget type: type in a cast expression.- See Also:
-
TARGET_CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT
public static final int TARGET_CONSTRUCTOR_INVOCATION_TYPE_ARGUMENTTarget type: type argument for a generic constructor in a new expression or an explicit constructor invocation.- See Also:
-
TARGET_METHOD_INVOCATION_TYPE_ARGUMENT
public static final int TARGET_METHOD_INVOCATION_TYPE_ARGUMENTTarget type: type argument for a generic method in a method invocation expression.- See Also:
-
TARGET_CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT
public static final int TARGET_CONSTRUCTOR_REFERENCE_TYPE_ARGUMENTTarget type: type argument for a generic constructor in a method reference expression using ::new.- See Also:
-
TARGET_METHOD_REFERENCE_TYPE_ARGUMENT
public static final int TARGET_METHOD_REFERENCE_TYPE_ARGUMENTTarget type: type argument for a generic method in a method reference expression using ::Identifier.- See Also:
-
EMPTY_ARRAY
Empty array of TypeAnnotationEntry objects. -
MAX_TYPE_PATH_LENGTH
private static final int MAX_TYPE_PATH_LENGTHMaximum number of steps of a type path, which its length of one byte limits.- See Also:
-
LOCAL_VARIABLE_RANGE_SIZE
private static final int LOCAL_VARIABLE_RANGE_SIZENumber of bytes of alocalvar_targetentry: start_pc, length and index.- See Also:
-
targetType
private final int targetType -
targetInfo
private final byte[] targetInfo -
typePath
private final byte[] typePath -
annotationEntry
-
-
Constructor Details
-
TypeAnnotationEntry
public TypeAnnotationEntry(int targetType, byte[] targetInfo, byte[] typePath, AnnotationEntry annotationEntry) Constructs a TypeAnnotationEntry.- Parameters:
targetType- The target type, one of theTARGET_*constants.targetInfo- The target info, as it is stored in the class file.typePath- The type path, as it is stored in the class file without its length: a pair of bytes (path kind, type argument index) per step.annotationEntry- The annotation.- Throws:
ClassFormatException- Thrown if the target type is not defined.IllegalArgumentException- Thrown if the target info does not have the size its target type requires, or if the type path is not a sequence of pairs of bytes of at most 255 steps.
-
-
Method Details
-
checkTargetInfo
private static void checkTargetInfo(int targetType, byte[] targetInfo) -
read
public static TypeAnnotationEntry read(DataInput input, ConstantPool constantPool, boolean isRuntimeVisible) throws IOException Factory method to create a TypeAnnotationEntry from a DataInput.- Parameters:
input- The input stream.constantPool- The constant pool.isRuntimeVisible- whether the annotation is runtime visible.- Returns:
- The entry.
- Throws:
IOException- Thrown if an I/O error occurs.
-
targetInfoSize
private static int targetInfoSize(int targetType) Gets the number of bytes of the target info that follows a target type.- Parameters:
targetType- The target type.- Returns:
- the size of the target info, or -1 if it depends on its content (the table of a
localvar_target). - Throws:
ClassFormatException- Thrown if the target type is not defined.
-
copy
Creates a deep copy of this entry, whose annotation is independent of this one and refers to the given constant pool. The indexes it holds are kept, as they are inAttribute.copy(ConstantPool): the constant pool must have the same constants as the one of this entry at these indexes.- Parameters:
constantPool- The constant pool of the copy.- Returns:
- A deep copy of this entry.
-
dump
Writes this entry to a DataOutputStream.- Parameters:
dos- The data output stream.- Throws:
IOException- Thrown if an I/O error occurs.
-
getAnnotationEntry
Gets the annotation.- Returns:
- The annotation.
-
getTargetInfo
public byte[] getTargetInfo()Gets the target info, which depends on the target type (JVMS table 4.7.20-A): for instance the index of the type parameter forTARGET_CLASS_TYPE_PARAMETER, the index of the type parameter then the index of the bound forTARGET_CLASS_TYPE_PARAMETER_BOUND, or the index of the parameter forTARGET_METHOD_FORMAL_PARAMETER.- Returns:
- A copy of the target info, as it is stored in the class file.
-
getTargetType
public int getTargetType()Gets the kind of program element the annotation applies to.- Returns:
- One of the
TARGET_*constants.
-
getTypePathArgumentIndex
public int getTypePathArgumentIndex(int step) Gets the index of the type argument for a step of the type path of kind 3, else 0.- Parameters:
step- Index of the step, from 0 togetTypePathLength()excluded.- Returns:
- The index of the type argument.
-
getTypePathKind
public int getTypePathKind(int step) Gets the kind of a step of the type path: 0 deeper in an array type, 1 deeper in a nested type, 2 on the bound of a wildcard type argument, 3 on a type argument of a parameterized type.- Parameters:
step- Index of the step, from 0 togetTypePathLength()excluded.- Returns:
- The kind of the step.
-
getTypePathLength
public int getTypePathLength()Gets the number of steps in the type path.The path leads from the type of the target to the part of it that is annotated. An empty path identifies the outermost part of the type where an annotation is allowed. For a non-static inner class,
@A Outer.Innerhas an empty path, whileOuter.@A Innerrequires one step. For a static nested class,Outer.@A Nestedhas an empty path.- Returns:
- The number of steps of the type path.
-
toString
-