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 TypeFieldDescriptionstatic final TypeAnnotationEntry[]Empty array of TypeAnnotationEntry objects.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. -
Constructor Summary
ConstructorsConstructorDescriptionTypeAnnotationEntry(int targetType, byte[] targetInfo, byte[] typePath, AnnotationEntry annotationEntry) Constructs a TypeAnnotationEntry. -
Method Summary
Modifier and TypeMethodDescriptioncopy(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.toString()
-
Field Details
-
TARGET_CLASS_TYPE_PARAMETER
Target type: type parameter declaration of a generic class or interface.- See Also:
-
TARGET_METHOD_TYPE_PARAMETER
Target type: type parameter declaration of a generic method or constructor.- See Also:
-
TARGET_CLASS_EXTENDS
Target type: type in an extends or implements clause of a class or interface declaration.- See Also:
-
TARGET_CLASS_TYPE_PARAMETER_BOUND
Target type: bound of a type parameter of a generic class or interface.- See Also:
-
TARGET_METHOD_TYPE_PARAMETER_BOUND
Target type: bound of a type parameter of a generic method or constructor.- See Also:
-
TARGET_FIELD
Target type: type in a field or record component declaration.- See Also:
-
TARGET_METHOD_RETURN
Target type: return type of a method, or type of a newly constructed object.- See Also:
-
TARGET_METHOD_RECEIVER
Target type: receiver type of a method or constructor.- See Also:
-
TARGET_METHOD_FORMAL_PARAMETER
Target type: type in a formal parameter declaration of a method, constructor, or lambda expression.- See Also:
-
TARGET_THROWS
Target type: type in a throws clause of a method or constructor.- See Also:
-
TARGET_LOCAL_VARIABLE
Target type: type in a local variable declaration.- See Also:
-
TARGET_RESOURCE_VARIABLE
Target type: type in a resource variable declaration.- See Also:
-
TARGET_EXCEPTION_PARAMETER
Target type: type in an exception parameter declaration.- See Also:
-
TARGET_INSTANCEOF
-
TARGET_NEW
-
TARGET_CONSTRUCTOR_REFERENCE
Target type: type in a method reference expression using ::new.- See Also:
-
TARGET_METHOD_REFERENCE
Target type: type in a method reference expression using ::Identifier.- See Also:
-
TARGET_CAST
-
TARGET_CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT
Target type: type argument for a generic constructor in a new expression or an explicit constructor invocation.- See Also:
-
TARGET_METHOD_INVOCATION_TYPE_ARGUMENT
Target type: type argument for a generic method in a method invocation expression.- See Also:
-
TARGET_CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT
Target type: type argument for a generic constructor in a method reference expression using ::new.- See Also:
-
TARGET_METHOD_REFERENCE_TYPE_ARGUMENT
Target type: type argument for a generic method in a method reference expression using ::Identifier.- See Also:
-
EMPTY_ARRAY
Empty array of TypeAnnotationEntry objects.
-
-
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
-
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.
-
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
-
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
Gets the kind of program element the annotation applies to.- Returns:
- One of the
TARGET_*constants.
-
getTypePathArgumentIndex
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
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
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
-