类 ClassReader
java.lang.Object
cn.taketoday.bytecode.ClassReader
A parser to make a
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.- 作者:
- Eric Bruneton, Eugene Kuleshov
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private final int[]The start offsets inclassFileBufferof each element of the bootstrap_methods array (in the BootstrapMethods attribute).(专用程序包) final byte[]A byte array containing the JVMS ClassFile structure to be parsed.private final ConstantDynamic[]The ConstantDynamic objects corresponding to the CONSTANT_Dynamic constant pool items.private final String[]The String objects corresponding to the CONSTANT_Utf8 constant pool items.private final int[]The offset in bytes, inclassFileBuffer, of each cp_info entry of the ClassFile's constant_pool array, plus one.(专用程序包) static final intA flag to expand the ASM specific instructions into an equivalent sequence of standard bytecode instructions.static final intA flag to expand the stack map frames.final intThe offset in bytes of the ClassFile's access_flags field.private static final intThe size of the temporary byte array used to read class input streams chunk by chunk.private static final intThe maximum size of array to allocate.private final intA conservative estimate of the maximum length of the strings contained in the constant pool of the class.static final intA flag to skip the Code attributes.static final intA flag to skip the SourceFile, SourceDebugExtension, LocalVariableTable, LocalVariableTypeTable, LineNumberTable and MethodParameters attributes.static final intA flag to skip the StackMap and StackMapTable attributes. -
构造器概要
构造器构造器说明ClassReader(byte[] classFile) Constructs a newClassReaderobject.ClassReader(byte[] classFileBuffer, int classFileOffset, boolean checkClassVersion) Constructs a newClassReaderobject.ClassReader(byte[] classFileBuffer, int classFileOffset, int classFileLength) Constructs a newClassReaderobject.ClassReader(InputStream inputStream) Constructs a newClassReaderobject.ClassReader(String className) Constructs a newClassReaderobject. -
方法概要
修饰符和类型方法说明voidaccept(ClassVisitor classVisitor, int parsingOptions) Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of thisClassReader.voidaccept(ClassVisitor classVisitor, Attribute[] attributePrototypes, int parsingOptions) Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of thisClassReader.private static intcalculateBufferSize(InputStream inputStream) private voidcomputeImplicitFrame(Context context) Computes the implicit frame of the method currently being parsed (as defined in the givenContext) and stores it in the given context.private voidcreateDebugLabel(int bytecodeOffset, Label[] labels) Creates a label with theLabel.FLAG_DEBUG_ONLYflag set, if there is no already existing label for the given bytecode offset (otherwise does nothing).private LabelcreateLabel(int bytecodeOffset, Label[] labels) Creates a label without theLabel.FLAG_DEBUG_ONLYflag set, for the given bytecode offset.intReturns the class's access flags (seeOpcodes).Returns the internal name of the class (seeType.getInternalName()).(专用程序包) final intReturns the offset inclassFileBufferof the first ClassFile's 'attributes' array field entry.String[]Returns the internal names of the implemented interfaces (seeType.getInternalName()).intgetItem(int constantPoolEntryIndex) Returns the start offset in thisClassReaderof a JVMS 'cp_info' structure (i.e. a constant pool entry), plus one.intReturns the number of entries in the class's constant pool table.intReturns a conservative estimate of the maximum length of the strings contained in the class's constant pool table.Returns the internal of name of the super class (seeType.getInternalName()).private intgetTypeAnnotationBytecodeOffset(int[] typeAnnotationOffsets, int 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 AttributereadAttribute(Attribute[] attributePrototypes, String type, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) Reads a non standard JVMS 'attribute' structure inclassFileBuffer.private int[]readBootstrapMethodsAttribute(int maxStringLength) Reads the BootstrapMethods attribute to compute the offset of each bootstrap method.intreadByte(int offset) Reads a byte value in thisClassReader.readClass(int offset, char[] charBuffer) Reads a CONSTANT_Class constant pool entry in thisClassReader.private voidreadCode(MethodVisitor methodVisitor, Context context, int codeOffset) Reads a JVMS 'Code' attribute and makes the given visitor visit it.readConst(int constantPoolEntryIndex, char[] charBuffer) Reads a numeric or string constant pool entry in thisClassReader.private ConstantDynamicreadConstantDynamic(int constantPoolEntryIndex, char[] charBuffer) Reads a CONSTANT_Dynamic constant pool entry inclassFileBuffer.private intreadElementValue(AnnotationVisitor annotationVisitor, int elementValueOffset, String elementName, char[] charBuffer) Reads a JVMS 'element_value' structure and makes the given visitor visit it.private intreadElementValues(AnnotationVisitor annotationVisitor, int annotationOffset, boolean named, char[] charBuffer) Reads the element values of a JVMS 'annotation' structure and makes the given visitor visit them.private intreadField(ClassVisitor classVisitor, Context context, int fieldInfoOffset) Reads a JVMS field_info structure and makes the given visitor visit it.intreadInt(int offset) Reads a signed int value in thisClassReader.protected LabelReturns the label corresponding to the given bytecode offset.longreadLong(int offset) Reads a signed long value in thisClassReader.private intreadMethod(ClassVisitor classVisitor, Context context, int methodInfoOffset) Reads a JVMS method_info structure and makes the given visitor visit it.readModule(int offset, char[] charBuffer) Reads a CONSTANT_Module constant pool entry in thisClassReader.private voidreadModuleAttributes(ClassVisitor classVisitor, Context context, int moduleOffset, int modulePackagesOffset, String moduleMainClass) Reads the Module, ModulePackages and ModuleMainClass attributes and visit them.readPackage(int offset, char[] charBuffer) Reads a CONSTANT_Package constant pool entry in thisClassReader.private voidreadParameterAnnotations(MethodVisitor methodVisitor, Context context, int runtimeParameterAnnotationsOffset, boolean visible) Reads a Runtime[In]VisibleParameterAnnotations attribute and makes the given visitor visit it.private intreadRecordComponent(ClassVisitor classVisitor, Context context, int recordComponentOffset) Reads a record component and visit it.shortreadShort(int offset) Reads a signed short value in thisClassReader.private intreadStackMapFrame(int stackMapFrameOffset, boolean compressed, boolean expand, Context context) Reads a JVMS 'stack_map_frame' structure and stores the result in the givenContextobject.private static byte[]readStream(InputStream inputStream, boolean close) Reads the given input stream and returns its content as a byte array.private StringreadStringish(int offset, char[] charBuffer) Reads a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_Module or CONSTANT_Package constant pool entry inclassFileBuffer.private int[]readTypeAnnotations(MethodVisitor methodVisitor, Context context, int runtimeTypeAnnotationsOffset, boolean 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 intreadTypeAnnotationTarget(Context context, int 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.intreadUnsignedShort(int offset) Reads an unsigned short value in thisClassReader.(专用程序包) final StringreadUtf(int constantPoolEntryIndex, char[] charBuffer) Reads a CONSTANT_Utf8 constant pool entry inclassFileBuffer.private StringreadUtf(int utfOffset, int utfLength, char[] charBuffer) Reads an UTF8 string inclassFileBuffer.readUTF8(int offset, char[] charBuffer) Reads a CONSTANT_Utf8 constant pool entry in thisClassReader.private intreadVerificationTypeInfo(int verificationTypeInfoOffset, Object[] frame, int index, char[] charBuffer, Label[] labels) Reads a JVMS 'verification_type_info' structure and stores it at the given index in the given array.
-
字段详细资料
-
SKIP_CODE
public static final int SKIP_CODEA flag to skip the Code attributes. If this flag is set the Code attributes are neither parsed nor visited.- 另请参阅:
-
SKIP_DEBUG
public static final int SKIP_DEBUGA flag to skip the SourceFile, SourceDebugExtension, LocalVariableTable, LocalVariableTypeTable, LineNumberTable and MethodParameters attributes. If this flag is set these attributes are neither parsed nor visited (i.e.ClassVisitor.visitSource(java.lang.String, java.lang.String),MethodVisitor.visitLocalVariable(java.lang.String, java.lang.String, java.lang.String, cn.taketoday.bytecode.Label, cn.taketoday.bytecode.Label, int),MethodVisitor.visitLineNumber(int, cn.taketoday.bytecode.Label)andMethodVisitor.visitParameter(java.lang.String, int)are not called).- 另请参阅:
-
SKIP_FRAMES
public static final int SKIP_FRAMESA flag to skip the StackMap and StackMapTable attributes. If this flag is set these attributes are neither parsed nor visited (i.e.MethodVisitor.visitFrame(int, int, java.lang.Object[], int, java.lang.Object[])is not called). This flag is useful when theClassWriter.COMPUTE_FRAMESoption is used: it avoids visiting frames that will be ignored and recomputed from scratch.- 另请参阅:
-
EXPAND_FRAMES
public static final int EXPAND_FRAMESA flag to expand the stack map frames. By default stack map frames are visited in their original format (i.e. "expanded" for classes whose version is less than V1_6, and "compressed" for the other classes). If this flag is set, stack map frames are always visited in expanded format (this option adds a decompression/compression step in ClassReader and ClassWriter which degrades performance quite a lot).- 另请参阅:
-
EXPAND_ASM_INSNS
static final int EXPAND_ASM_INSNSA flag to expand the ASM specific instructions into an equivalent sequence of standard bytecode instructions. When resolving a forward jump it may happen that the signed 2 bytes offset reserved for it is not sufficient to store the bytecode offset. In this case the jump instruction is replaced with a temporary ASM specific instruction using an unsigned 2 bytes offset (seeLabel.resolve(byte[], int)). This internal flag is used to re-read classes containing such instructions, in order to replace them with standard instructions. In addition, when this flag is used, goto_w and jsr_w are not converted into goto and jsr, to make sure that infinite loops where a goto_w is replaced with a goto in ClassReader and converted back to a goto_w in ClassWriter cannot occur.- 另请参阅:
-
MAX_BUFFER_SIZE
private static final int MAX_BUFFER_SIZEThe maximum size of array to allocate.- 另请参阅:
-
INPUT_STREAM_DATA_CHUNK_SIZE
private static final int INPUT_STREAM_DATA_CHUNK_SIZEThe size of the temporary byte array used to read class input streams chunk by chunk.- 另请参阅:
-
header
public final int headerThe offset in bytes of the ClassFile's access_flags field. -
classFileBuffer
final byte[] classFileBufferA byte array containing the JVMS ClassFile structure to be parsed. The content of this array must not be modified. This field is intended forAttributesub classes, and is normally not needed by class visitors.NOTE: the ClassFile structure can start at any offset within this array, i.e. it does not necessarily start at offset 0. Use
getItem(int)andheaderto get correct ClassFile element offsets within this byte array. -
cpInfoOffsets
private final int[] cpInfoOffsetsThe offset in bytes, inclassFileBuffer, of each cp_info entry of the ClassFile's constant_pool array, plus one. In other words, the offset of constant pool entry i is given by cpInfoOffsets[i] - 1, i.e. its cp_info's tag field is given by b[cpInfoOffsets[i] - 1]. -
constantUtf8Values
The String objects corresponding to the CONSTANT_Utf8 constant pool items. This cache avoids multiple parsing of a given CONSTANT_Utf8 constant pool item. -
constantDynamicValues
The ConstantDynamic objects corresponding to the CONSTANT_Dynamic constant pool items. This cache avoids multiple parsing of a given CONSTANT_Dynamic constant pool item. -
bootstrapMethodOffsets
private final int[] bootstrapMethodOffsetsThe start offsets inclassFileBufferof each element of the bootstrap_methods array (in the BootstrapMethods attribute).- 另请参阅:
-
maxStringLength
private final int maxStringLengthA conservative estimate of the maximum length of the strings contained in the constant pool of the class.
-
-
构造器详细资料
-
ClassReader
public ClassReader(byte[] classFile) Constructs a newClassReaderobject.- 参数:
classFile- the JVMS ClassFile structure to be read.
-
ClassReader
public ClassReader(byte[] classFileBuffer, int classFileOffset, int classFileLength) Constructs a newClassReaderobject.- 参数:
classFileBuffer- a byte array containing the JVMS ClassFile structure to be read.classFileOffset- the offset in byteBuffer of the first byte of the ClassFile to be read.classFileLength- the length in bytes of the ClassFile to be read.
-
ClassReader
ClassReader(byte[] classFileBuffer, int classFileOffset, boolean checkClassVersion) Constructs a newClassReaderobject. This internal constructor must not be exposed as a public API.- 参数:
classFileBuffer- a byte array containing the JVMS ClassFile structure to be read.classFileOffset- the offset in byteBuffer of the first byte of the ClassFile to be read.checkClassVersion- whether to check the class version or not.
-
ClassReader
Constructs a newClassReaderobject.- 参数:
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.- 抛出:
IOException- if a problem occurs during reading.
-
ClassReader
Constructs a newClassReaderobject.- 参数:
className- the fully qualified name of the class to be read. The ClassFile structure is retrieved with the current class loader'sClassLoader.getSystemResourceAsStream(java.lang.String).- 抛出:
IOException- if an exception occurs during reading.
-
-
方法详细资料
-
readStream
Reads the given input stream and returns its content as a byte array.- 参数:
inputStream- an input stream.close- true to close the input stream after reading.- 返回:
- the content of the given input stream.
- 抛出:
IOException- if a problem occurs during reading.
-
calculateBufferSize
- 抛出:
IOException
-
getAccess
public int getAccess()Returns the class's access flags (seeOpcodes). This value may not reflect Deprecated and Synthetic flags when bytecode is before 1.5 and those flags are represented by attributes.- 返回:
- the class access flags.
- 另请参阅:
-
getClassName
Returns the internal name of the class (seeType.getInternalName()).- 返回:
- the internal class name.
- 另请参阅:
-
getSuperName
Returns the internal of name of the super class (seeType.getInternalName()). For interfaces, the super class isObject.- 返回:
- the internal name of the super class, or null for
Objectclass. - 另请参阅:
-
getInterfaces
Returns the internal names of the implemented interfaces (seeType.getInternalName()).- 返回:
- the internal names of the directly implemented interfaces. Inherited implemented interfaces are not returned.
- 另请参阅:
-
accept
Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of thisClassReader.- 参数:
classVisitor- the visitor that must visit this class.parsingOptions- the options to use to parse this class. One or more ofSKIP_CODE,SKIP_DEBUG,SKIP_FRAMESorEXPAND_FRAMES.
-
accept
Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of thisClassReader.- 参数:
classVisitor- the visitor that must visit this class.attributePrototypes- 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.parsingOptions- the options to use to parse this class. One or more ofSKIP_CODE,SKIP_DEBUG,SKIP_FRAMESorEXPAND_FRAMES.
-
readModuleAttributes
private void readModuleAttributes(ClassVisitor classVisitor, Context context, int moduleOffset, int modulePackagesOffset, String moduleMainClass) Reads the Module, ModulePackages and ModuleMainClass attributes and visit them.- 参数:
classVisitor- the current class visitorcontext- information about the class being parsed.moduleOffset- the offset of the Module attribute (excluding the attribute_info's attribute_name_index and attribute_length fields).modulePackagesOffset- the offset of the ModulePackages attribute (excluding the attribute_info's attribute_name_index and attribute_length fields), or 0.moduleMainClass- the string corresponding to the ModuleMainClass attribute, or null.
-
readRecordComponent
private int readRecordComponent(ClassVisitor classVisitor, Context context, int recordComponentOffset) Reads a record component and visit it.- 参数:
classVisitor- the current class visitorcontext- information about the class being parsed.recordComponentOffset- the offset of the current record component.- 返回:
- the offset of the first byte following the record component.
-
readField
Reads a JVMS field_info structure and makes the given visitor visit it.- 参数:
classVisitor- the visitor that must visit the field.context- information about the class being parsed.fieldInfoOffset- the start offset of the field_info structure.- 返回:
- the offset of the first byte following the field_info structure.
-
readMethod
Reads a JVMS method_info structure and makes the given visitor visit it.- 参数:
classVisitor- the visitor that must visit the method.context- information about the class being parsed.methodInfoOffset- the start offset of the method_info structure.- 返回:
- the offset of the first byte following the method_info structure.
-
readCode
Reads a JVMS 'Code' attribute and makes the given visitor visit it.- 参数:
methodVisitor- the visitor that must visit the Code attribute.context- information about the class being parsed.codeOffset- the start offset inclassFileBufferof the Code attribute, excluding its attribute_name_index and attribute_length fields.
-
readLabel
Returns the label corresponding to the given bytecode offset. The default implementation of this method creates a label for the given offset if it has not been already created.- 参数:
bytecodeOffset- a bytecode offset in a method.labels- 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.- 返回:
- a non null Label, which must be equal to labels[bytecodeOffset].
-
createLabel
Creates a label without theLabel.FLAG_DEBUG_ONLYflag set, for the given bytecode offset. The label is created with a call toreadLabel(int, cn.taketoday.bytecode.Label[])and itsLabel.FLAG_DEBUG_ONLYflag is cleared.- 参数:
bytecodeOffset- a bytecode offset in a method.labels- the already created labels, indexed by their offset.- 返回:
- a Label without the
Label.FLAG_DEBUG_ONLYflag set.
-
createDebugLabel
Creates a label with theLabel.FLAG_DEBUG_ONLYflag set, if there is no already existing label for the given bytecode offset (otherwise does nothing). The label is created with a call toreadLabel(int, cn.taketoday.bytecode.Label[]).- 参数:
bytecodeOffset- a bytecode offset in a method.labels- the already created labels, indexed by their offset.
-
readTypeAnnotations
private int[] readTypeAnnotations(MethodVisitor methodVisitor, Context context, int runtimeTypeAnnotationsOffset, boolean 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.- 参数:
methodVisitor- the method visitor to be used to visit the try catch block annotations.context- information about the class being parsed.runtimeTypeAnnotationsOffset- the start offset of a Runtime[In]VisibleTypeAnnotations attribute, excluding the attribute_info's attribute_name_index and attribute_length fields.visible- true if the attribute to parse is a RuntimeVisibleTypeAnnotations attribute, false it is a RuntimeInvisibleTypeAnnotations attribute.- 返回:
- the start offset of each entry of the Runtime[In]VisibleTypeAnnotations_attribute's 'annotations' array field.
-
getTypeAnnotationBytecodeOffset
private int getTypeAnnotationBytecodeOffset(int[] typeAnnotationOffsets, int 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.- 参数:
typeAnnotationOffsets- the offset of each 'type_annotation' entry in a Runtime[In]VisibleTypeAnnotations attribute, or null.typeAnnotationIndex- the index a 'type_annotation' entry in typeAnnotationOffsets.- 返回:
- 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.
-
readTypeAnnotationTarget
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.- 参数:
context- information about the class being parsed. This is where the extracted target_type and target_path must be stored.typeAnnotationOffset- the start offset of a type_annotation structure.- 返回:
- the start offset of the rest of the type_annotation structure.
-
readParameterAnnotations
private void readParameterAnnotations(MethodVisitor methodVisitor, Context context, int runtimeParameterAnnotationsOffset, boolean visible) Reads a Runtime[In]VisibleParameterAnnotations attribute and makes the given visitor visit it.- 参数:
methodVisitor- the visitor that must visit the parameter annotations.context- information about the class being parsed.runtimeParameterAnnotationsOffset- the start offset of a Runtime[In]VisibleParameterAnnotations attribute, excluding the attribute_info's attribute_name_index and attribute_length fields.visible- true if the attribute to parse is a RuntimeVisibleParameterAnnotations attribute, false it is a RuntimeInvisibleParameterAnnotations attribute.
-
readElementValues
private int readElementValues(AnnotationVisitor annotationVisitor, int annotationOffset, boolean named, char[] charBuffer) Reads the element values of a JVMS 'annotation' structure and makes the given visitor visit them. This method can also be used to read the values of the JVMS 'array_value' field of an annotation's 'element_value'.- 参数:
annotationVisitor- the visitor that must visit the values.annotationOffset- the start offset of an 'annotation' structure (excluding its type_index field) or of an 'array_value' structure.named- 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.charBuffer- the buffer used to read strings in the constant pool.- 返回:
- the end offset of the JVMS 'annotation' or 'array_value' structure.
-
readElementValue
private int readElementValue(AnnotationVisitor annotationVisitor, int elementValueOffset, String elementName, char[] charBuffer) Reads a JVMS 'element_value' structure and makes the given visitor visit it.- 参数:
annotationVisitor- the visitor that must visit the element_value structure.elementValueOffset- the start offset inclassFileBufferof the element_value structure to be read.elementName- the name of the element_value structure to be read, or null.charBuffer- the buffer used to read strings in the constant pool.- 返回:
- the end offset of the JVMS 'element_value' structure.
-
computeImplicitFrame
Computes the implicit frame of the method currently being parsed (as defined in the givenContext) and stores it in the given context.- 参数:
context- information about the class being parsed.
-
readStackMapFrame
private int readStackMapFrame(int stackMapFrameOffset, boolean compressed, boolean expand, Context context) Reads a JVMS 'stack_map_frame' structure and stores the result in the givenContextobject. This method can also be used to read a full_frame structure, excluding its frame_type field (this is used to parse the legacy StackMap attributes).- 参数:
stackMapFrameOffset- the start offset inclassFileBufferof the stack_map_frame_value structure to be read, or the start offset of a full_frame structure (excluding its frame_type field).compressed- true to read a 'stack_map_frame' structure, false to read a 'full_frame' structure without its frame_type field.expand- if the stack map frame must be expanded. SeeEXPAND_FRAMES.context- where the parsed stack map frame must be stored.- 返回:
- the end offset of the JVMS 'stack_map_frame' or 'full_frame' structure.
-
readVerificationTypeInfo
private int readVerificationTypeInfo(int verificationTypeInfoOffset, Object[] frame, int index, char[] charBuffer, Label[] labels) Reads a JVMS 'verification_type_info' structure and stores it at the given index in the given array.- 参数:
verificationTypeInfoOffset- the start offset of the 'verification_type_info' structure to read.frame- the array where the parsed type must be stored.index- the index in 'frame' where the parsed type must be stored.charBuffer- the buffer used to read strings in the constant pool.labels- 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.- 返回:
- the end offset of the JVMS 'verification_type_info' structure.
-
getFirstAttributeOffset
final int getFirstAttributeOffset()Returns the offset inclassFileBufferof the first ClassFile's 'attributes' array field entry.- 返回:
- the offset in
classFileBufferof the first ClassFile's 'attributes' array field entry.
-
readBootstrapMethodsAttribute
private int[] readBootstrapMethodsAttribute(int maxStringLength) Reads the BootstrapMethods attribute to compute the offset of each bootstrap method.- 参数:
maxStringLength- a conservative estimate of the maximum length of the strings contained in the constant pool of the class.- 返回:
- the offsets of the bootstrap methods.
-
readAttribute
private Attribute readAttribute(Attribute[] attributePrototypes, String type, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) Reads a non standard JVMS 'attribute' structure inclassFileBuffer.- 参数:
attributePrototypes- 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.type- the type of the attribute.offset- the start offset of the JVMS 'attribute' structure inclassFileBuffer. The 6 attribute header bytes (attribute_name_index and attribute_length) are not taken into account here.length- the length of the attribute's content (excluding the 6 attribute header bytes).charBuffer- the buffer to be used to read strings in the constant pool.codeAttributeOffset- the start offset of the enclosing Code attribute inclassFileBuffer, 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.labels- the labels of the method's code, or null if the attribute to be read is not a code attribute.- 返回:
- the attribute that has been read.
-
getItemCount
public int getItemCount()Returns the number of entries in the class's constant pool table.- 返回:
- the number of entries in the class's constant pool table.
-
getItem
public int getItem(int constantPoolEntryIndex) Returns the start offset in thisClassReaderof a JVMS 'cp_info' structure (i.e. a constant pool entry), plus one. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
constantPoolEntryIndex- the index a constant pool entry in the class's constant pool table.- 返回:
- the start offset in this
ClassReaderof the corresponding JVMS 'cp_info' structure, plus one.
-
getMaxStringLength
public int getMaxStringLength()Returns a conservative estimate of the maximum length of the strings contained in the class's constant pool table.- 返回:
- a conservative estimate of the maximum length of the strings contained in the class's constant pool table.
-
readByte
public int readByte(int offset) Reads a byte value in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of the value to be read in thisClassReader.- 返回:
- the read value.
-
readUnsignedShort
public int readUnsignedShort(int offset) Reads an unsigned short value in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start index of the value to be read in thisClassReader.- 返回:
- the read value.
-
readShort
public short readShort(int offset) Reads a signed short value in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of the value to be read in thisClassReader.- 返回:
- the read value.
-
readInt
public int readInt(int offset) Reads a signed int value in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of the value to be read in thisClassReader.- 返回:
- the read value.
-
readLong
public long readLong(int offset) Reads a signed long value in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of the value to be read in thisClassReader.- 返回:
- the read value.
-
readUTF8
Reads a CONSTANT_Utf8 constant pool entry in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value in thisClassReader, whose value is the index of a CONSTANT_Utf8 entry in the class's constant pool table.charBuffer- the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Utf8 entry.
-
readUtf
Reads a CONSTANT_Utf8 constant pool entry inclassFileBuffer.- 参数:
constantPoolEntryIndex- the index of a CONSTANT_Utf8 entry in the class's constant pool table.charBuffer- the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Utf8 entry.
-
readUtf
Reads an UTF8 string inclassFileBuffer.- 参数:
utfOffset- the start offset of the UTF8 string to be read.utfLength- the length of the UTF8 string to be read.charBuffer- the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified UTF8 string.
-
readStringish
Reads a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_Module or CONSTANT_Package constant pool entry inclassFileBuffer. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value inclassFileBuffer, 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.charBuffer- the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified constant pool entry.
-
readClass
Reads a CONSTANT_Class constant pool entry in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value in thisClassReader, whose value is the index of a CONSTANT_Class entry in class's constant pool table.charBuffer- the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Class entry.
-
readModule
Reads a CONSTANT_Module constant pool entry in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value in thisClassReader, whose value is the index of a CONSTANT_Module entry in class's constant pool table.charBuffer- the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Module entry.
-
readPackage
Reads a CONSTANT_Package constant pool entry in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value in thisClassReader, whose value is the index of a CONSTANT_Package entry in class's constant pool table.charBuffer- the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Package entry.
-
readConstantDynamic
Reads a CONSTANT_Dynamic constant pool entry inclassFileBuffer.- 参数:
constantPoolEntryIndex- the index of a CONSTANT_Dynamic entry in the class's constant pool table.charBuffer- the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the ConstantDynamic corresponding to the specified CONSTANT_Dynamic entry.
-
readConst
Reads a numeric or string constant pool entry in thisClassReader. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
constantPoolEntryIndex- 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.charBuffer- the buffer to be used to read strings. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the
Integer,Float,Long,Double,String,Type,HandleorConstantDynamiccorresponding to the specified constant pool entry.
-