ClassVisitor
visit a ClassFile structure, as defined in the Java
Virtual Machine Specification (JVMS). This class parses the ClassFile content and calls the
appropriate visit methods of a given ClassVisitor
for each field, method and bytecode
instruction encountered.
Modifier and Type | Field and Description |
---|---|
public final byte[] | b
A byte array containing the JVMS ClassFile structure to be parsed. |
private final int[] | bootstrapMethodOffsets
The start offsets in |
pack-priv final byte[] | classFileBuffer
A byte array containing the JVMS ClassFile structure to be parsed. |
private final ConstantDynamic[] | constantDynamicValues
The ConstantDynamic objects corresponding to the CONSTANT_Dynamic constant pool items. |
private final String[] | constantUtf8Values
The String objects corresponding to the CONSTANT_Utf8 constant pool items. |
private final int[] | cpInfoOffsets
The offset in bytes, in |
pack-priv static final int | EXPAND_ASM_INSNS
A flag to expand the ASM specific instructions into an equivalent sequence of standard bytecode instructions. |
public static final int | EXPAND_FRAMES
A flag to expand the stack map frames. |
public final int | header
The offset in bytes of the ClassFile's access_flags field. |
private static final int | INPUT_STREAM_DATA_CHUNK_SIZE
The size of the temporary byte array used to read class input streams chunk by chunk. |
private static final int | MAX_BUFFER_SIZE
The maximum size of array to allocate. |
private final int | maxStringLength
A conservative estimate of the maximum length of the strings contained in the constant pool of the class. |
public static final int | SKIP_CODE
A flag to skip the Code attributes. |
public static final int | SKIP_DEBUG
A flag to skip the SourceFile, SourceDebugExtension, LocalVariableTable, LocalVariableTypeTable, LineNumberTable and MethodParameters attributes. |
public static final int | SKIP_FRAMES
A flag to skip the StackMap and StackMapTable attributes. |
Access | Constructor and Description |
---|---|
public | ClassReader(final byte[]
the JVMS ClassFile structure to be read. classFile)Constructs a new |
public | ClassReader(final byte[]
a byte array containing the JVMS ClassFile structure to be read. classFileBuffer, final int the offset in byteBuffer of the first byte of the ClassFile to be read. classFileOffset, final int the length in bytes of the ClassFile to be read. classFileLength)Constructs a new |
pack-priv | ClassReader(final byte[]
a byte array containing the JVMS ClassFile structure to be read. classFileBuffer, final int the offset in byteBuffer of the first byte of the ClassFile to be read. classFileOffset, final boolean whether to check the class version or not. checkClassVersion)Constructs a new |
public | ClassReader(final InputStream
an input stream of the JVMS ClassFile structure to be read. This input
stream must contain nothing more than the ClassFile structure itself. It is read from its
current position to its end. inputStream)Constructs a new |
public | ClassReader(final String
the fully qualified name of the class to be read. The ClassFile structure is
retrieved with the current class loader's className)ClassLoader#getSystemResourceAsStream .Constructs a new |
Modifier and Type | Method and Description |
---|---|
public void | accept(final ClassVisitor
the visitor that must visit this class. classVisitor, final int the options to use to parse this class. One or more of parsingOptions)SKIP_CODE , SKIP_DEBUG , SKIP_FRAMES or EXPAND_FRAMES .Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this
|
public void | accept(final ClassVisitor
the visitor that must visit this class. classVisitor, final Attribute[] prototypes of the attributes that must be parsed during the visit of
the class. Any attribute whose type is not equal to the type of one the prototypes will not
be parsed: its byte array value will be passed unchanged to the ClassWriter. This may
corrupt it if this value contains references to the constant pool, or has syntactic or
semantic links with a class element that has been transformed by a class adapter between
the reader and the writer. attributePrototypes, final int the options to use to parse this class. One or more of parsingOptions)SKIP_CODE , SKIP_DEBUG , SKIP_FRAMES or EXPAND_FRAMES .Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this
|
private static int | |
private void | computeImplicitFrame(final Context
information about the class being parsed. context)Computes the implicit frame of the method currently being parsed (as defined in the given
|
private void | createDebugLabel(final int
a bytecode offset in a method. bytecodeOffset, final Label[] the already created labels, indexed by their offset. labels)Creates a label with the |
private Label | Returns: a Label without theLabel#FLAG_DEBUG_ONLY flag set.a bytecode offset in a method. bytecodeOffset, final Label[] the already created labels, indexed by their offset. labels)Creates a label without the |
public int | |
public String | Returns: the internal class name.Returns the internal name of the class (see |
pack-priv final int | Returns: the offset inclassFileBuffer of the first ClassFile's 'attributes' array
field entry.Returns the offset in |
public String[] | Returns: the internal names of the directly implemented interfaces. Inherited implemented interfaces are not returned.Returns the internal names of the implemented interfaces (see |
public int | Returns: the start offset in thisClassReader of the corresponding JVMS 'cp_info'
structure, plus one.the index a constant pool entry in the class's constant pool
table. constantPoolEntryIndex)Returns the start offset in this |
public int | Returns: the number of entries in the class's constant pool table.Returns the number of entries in the class's constant pool table. |
public int | Returns: a conservative estimate of the maximum length of the strings contained in the class's constant pool table.Returns a conservative estimate of the maximum length of the strings contained in the class's constant pool table. |
public String | Returns: the internal name of the super class, or null forObject class.Returns the internal name of the super class (see |
private int | Returns: bytecode offset corresponding to the specified JVMS 'type_annotation' structure, or -1 if there is no such type_annotation of if it does not have a bytecode offset.the offset of each 'type_annotation' entry in a
Runtime[In]VisibleTypeAnnotations attribute, or null. typeAnnotationOffsets, final int the index a 'type_annotation' entry in typeAnnotationOffsets. typeAnnotationIndex)Returns the bytecode offset corresponding to the specified JVMS 'type_annotation' structure, or -1 if there is no such type_annotation of if it does not have a bytecode offset. |
private Attribute | Returns: the attribute that has been read.prototypes of the attributes that must be parsed during the visit of
the class. Any attribute whose type is not equal to the type of one the prototypes will not
be parsed: its byte array value will be passed unchanged to the ClassWriter. attributePrototypes, final String the type of the attribute. type, final int the start offset of the JVMS 'attribute' structure in offset, final int classFileBuffer .
The 6 attribute header bytes (attribute_name_index and attribute_length) are not taken into
account here.the length of the attribute's content (excluding the 6 attribute header bytes). length, final char[] the buffer to be used to read strings in the constant pool. charBuffer, final int the start offset of the enclosing Code attribute in codeAttributeOffset, final Label[] classFileBuffer , or -1 if the attribute to be read is not a code attribute. The 6
attribute header bytes (attribute_name_index and attribute_length) are not taken into
account here.the labels of the method's code, or null if the attribute to be read
is not a code attribute. labels)Reads a non standard JVMS 'attribute' structure in |
private int[] | Returns: the offsets of the bootstrap methods.a conservative estimate of the maximum length of the strings contained
in the constant pool of the class. maxStringLength)Reads the BootstrapMethods attribute to compute the offset of each bootstrap method. |
public int | Returns: the read value.the start offset of the value to be read in this offset)ClassReader .Reads a byte value in this |
protected void | readBytecodeInstructionOffset(final int
the bytecode offset of the next instruction to be visited. bytecodeOffset)Handles the bytecode offset of the next instruction to be visited in |
public String | Returns: the String corresponding to the specified CONSTANT_Class entry.the start offset of an unsigned short value in this offset, final char[] ClassReader , whose
value is the index of a CONSTANT_Class entry in class's constant pool table.the buffer to be used to read the item. This buffer must be sufficiently
large. It is not automatically resized. charBuffer)Reads a CONSTANT_Class constant pool entry in this |
private void | readCode(final MethodVisitor
the visitor that must visit the Code attribute. methodVisitor, final Context information about the class being parsed. context, final int the start offset in codeOffset)classFileBuffer of the Code attribute, excluding
its attribute_name_index and attribute_length fields.Reads a JVMS 'Code' attribute and makes the given visitor visit it. |
public Object | readConst(final int
the index of a CONSTANT_Integer, CONSTANT_Float, CONSTANT_Long,
CONSTANT_Double, CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType,
CONSTANT_MethodHandle or CONSTANT_Dynamic entry in the class's constant pool. constantPoolEntryIndex, final char[] the buffer to be used to read strings. This buffer must be sufficiently
large. It is not automatically resized. charBuffer)Reads a numeric or string constant pool entry in this |
private ConstantDynamic | Returns: the ConstantDynamic corresponding to the specified CONSTANT_Dynamic entry.the index of a CONSTANT_Dynamic entry in the class's constant
pool table. constantPoolEntryIndex, final char[] the buffer to be used to read the string. This buffer must be sufficiently
large. It is not automatically resized. charBuffer)Reads a CONSTANT_Dynamic constant pool entry in |
private int | Returns: the end offset of the JVMS 'element_value' structure.the visitor that must visit the element_value structure. annotationVisitor, final int the start offset in elementValueOffset, final String classFileBuffer of the element_value
structure to be read.the name of the element_value structure to be read, or null. elementName, final char[] the buffer used to read strings in the constant pool. charBuffer)Reads a JVMS 'element_value' structure and makes the given visitor visit it. |
private int | Returns: the end offset of the JVMS 'annotation' or 'array_value' structure.the visitor that must visit the values. annotationVisitor, final int the start offset of an 'annotation' structure (excluding its type_index
field) or of an 'array_value' structure. annotationOffset, final boolean if the annotation values are named or not. This should be true to parse the values
of a JVMS 'annotation' structure, and false to parse the JVMS 'array_value' of an
annotation's element_value. named, final char[] the buffer used to read strings in the constant pool. charBuffer)Reads the element values of a JVMS 'annotation' structure and makes the given visitor visit them. |
private int | Returns: the offset of the first byte following the field_info structure.the visitor that must visit the field. classVisitor, final Context information about the class being parsed. context, final int the start offset of the field_info structure. fieldInfoOffset)Reads a JVMS field_info structure and makes the given visitor visit it. |
public int | Returns: the read value.the start offset of the value to be read in this offset)ClassReader .Reads a signed int value in this |
protected Label | Returns: a non null Label, which must be equal to labels[bytecodeOffset].a bytecode offset in a method. bytecodeOffset, final Label[] the already created labels, indexed by their offset. If a label already exists
for bytecodeOffset this method must not create a new one. Otherwise it must store the new
label in this array. labels)Returns the label corresponding to the given bytecode offset. |
public long | Returns: the read value.the start offset of the value to be read in this offset)ClassReader .Reads a signed long value in this |
private int | Returns: the offset of the first byte following the method_info structure.the visitor that must visit the method. classVisitor, final Context information about the class being parsed. context, final int the start offset of the method_info structure. methodInfoOffset)Reads a JVMS method_info structure and makes the given visitor visit it. |
public String | Returns: the String corresponding to the specified CONSTANT_Module entry.the start offset of an unsigned short value in this offset, final char[] ClassReader , whose
value is the index of a CONSTANT_Module entry in class's constant pool table.the buffer to be used to read the item. This buffer must be sufficiently
large. It is not automatically resized. charBuffer)Reads a CONSTANT_Module constant pool entry in this |
private void | readModuleAttributes(final ClassVisitor
the current class visitor classVisitor, final Context information about the class being parsed. context, final int the offset of the Module attribute (excluding the attribute_info's
attribute_name_index and attribute_length fields). moduleOffset, final int the offset of the ModulePackages attribute (excluding the
attribute_info's attribute_name_index and attribute_length fields), or 0. modulePackagesOffset, final String the string corresponding to the ModuleMainClass attribute, or null. moduleMainClass)Reads the Module, ModulePackages and ModuleMainClass attributes and visit them. |
public String | Returns: the String corresponding to the specified CONSTANT_Package entry.the start offset of an unsigned short value in this offset, final char[] ClassReader , whose
value is the index of a CONSTANT_Package entry in class's constant pool table.the buffer to be used to read the item. This buffer must be sufficiently
large. It is not automatically resized. charBuffer)Reads a CONSTANT_Package constant pool entry in this |
private void | readParameterAnnotations(final MethodVisitor
the visitor that must visit the parameter annotations. methodVisitor, final Context information about the class being parsed. context, final int the start offset of a
Runtime[In]VisibleParameterAnnotations attribute, excluding the attribute_info's
attribute_name_index and attribute_length fields. runtimeParameterAnnotationsOffset, final boolean true if the attribute to parse is a RuntimeVisibleParameterAnnotations
attribute, false it is a RuntimeInvisibleParameterAnnotations attribute. visible)Reads a Runtime[In]VisibleParameterAnnotations attribute and makes the given visitor visit it. |
private int | Returns: the offset of the first byte following the record component.the current class visitor classVisitor, final Context information about the class being parsed. context, final int the offset of the current record component. recordComponentOffset)Reads a record component and visit it. |
public short | Returns: the read value.the start offset of the value to be read in this offset)ClassReader .Reads a signed short value in this |
private int | Returns: the end offset of the JVMS 'stack_map_frame' or 'full_frame' structure.the start offset in stackMapFrameOffset, final boolean classFileBuffer of the
stack_map_frame_value structure to be read, or the start offset of a full_frame structure
(excluding its frame_type field).true to read a 'stack_map_frame' structure, false to read a 'full_frame'
structure without its frame_type field. compressed, final boolean if the stack map frame must be expanded. See expand, final Context EXPAND_FRAMES .where the parsed stack map frame must be stored. context)Reads a JVMS 'stack_map_frame' structure and stores the result in the given |
private static byte[] | Returns: the content of the given input stream.an input stream. inputStream, final boolean true to close the input stream after reading. close)Reads the given input stream and returns its content as a byte array. |
private String | Returns: the String corresponding to the specified constant pool entry.the start offset of an unsigned short value in offset, final char[] classFileBuffer , whose
value is the index of a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType,
CONSTANT_Module or CONSTANT_Package entry in class's constant pool table.the buffer to be used to read the item. This buffer must be sufficiently
large. It is not automatically resized. charBuffer)Reads a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_Module or
CONSTANT_Package constant pool entry in |
private int[] | Returns: the start offset of each entry of the Runtime[In]VisibleTypeAnnotations_attribute's 'annotations' array field.the method visitor to be used to visit the try catch block annotations. methodVisitor, final Context information about the class being parsed. context, final int the start offset of a Runtime[In]VisibleTypeAnnotations
attribute, excluding the attribute_info's attribute_name_index and attribute_length fields. runtimeTypeAnnotationsOffset, final boolean true if the attribute to parse is a RuntimeVisibleTypeAnnotations attribute,
false it is a RuntimeInvisibleTypeAnnotations attribute. visible)Parses a Runtime[In]VisibleTypeAnnotations attribute to find the offset of each type_annotation entry it contains, to find the corresponding labels, and to visit the try catch block annotations. |
private int | Returns: the start offset of the rest of the type_annotation structure.information about the class being parsed. This is where the extracted
target_type and target_path must be stored. context, final int the start offset of a type_annotation structure. typeAnnotationOffset)Parses the header of a JVMS type_annotation structure to extract its target_type, target_info and target_path (the result is stored in the given context), and returns the start offset of the rest of the type_annotation structure. |
public int | Returns: the read value.the start index of the value to be read in this offset)ClassReader .Reads an unsigned short value in this |
pack-priv final String | Returns: the String corresponding to the specified CONSTANT_Utf8 entry.the index of a CONSTANT_Utf8 entry in the class's constant pool
table. constantPoolEntryIndex, final char[] the buffer to be used to read the string. This buffer must be sufficiently
large. It is not automatically resized. charBuffer)Reads a CONSTANT_Utf8 constant pool entry in |
private String | Returns: the String corresponding to the specified UTF8 string.the start offset of the UTF8 string to be read. utfOffset, final int the length of the UTF8 string to be read. utfLength, final char[] the buffer to be used to read the string. This buffer must be sufficiently
large. It is not automatically resized. charBuffer)Reads an UTF8 string in |
public String | Returns: the String corresponding to the specified CONSTANT_Utf8 entry.the start offset of an unsigned short value in this offset, final char[] ClassReader , whose
value is the index of a CONSTANT_Utf8 entry in the class's constant pool table.the buffer to be used to read the string. This buffer must be sufficiently
large. It is not automatically resized. charBuffer)Reads a CONSTANT_Utf8 constant pool entry in this |
private int | Returns: the end offset of the JVMS 'verification_type_info' structure.the start offset of the 'verification_type_info' structure to
read. verificationTypeInfoOffset, final Object[] the array where the parsed type must be stored. frame, final int the index in 'frame' where the parsed type must be stored. index, final char[] the buffer used to read strings in the constant pool. charBuffer, final Label[] the labels of the method currently being parsed, indexed by their offset. If the
parsed type is an ITEM_Uninitialized, a new label for the corresponding NEW instruction is
stored in this array if it does not already exist. labels)Reads a JVMS 'verification_type_info' structure and stores it at the given index in the given array. |