类 ClassReader
- java.lang.Object
- org.springframework.asm.ClassReader
public class ClassReader extends Object
A parser to make aClassVisitorvisit 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 givenClassVisitorfor each field, method and bytecode instruction encountered.- 作者:
- Eric Bruneton, Eugene Kuleshov
- 另请参阅:
- JVMS 4
字段概要
字段 修饰符和类型 字段 说明 byte[]b已过时。UsereadByte(int)and the other read methods instead.static intEXPAND_FRAMESA flag to expand the stack map frames.intheaderThe offset in bytes of the ClassFile's access_flags field.static intSKIP_CODEA flag to skip the Code attributes.static intSKIP_DEBUGA flag to skip the SourceFile, SourceDebugExtension, LocalVariableTable, LocalVariableTypeTable, LineNumberTable and MethodParameters attributes.static intSKIP_FRAMESA flag to skip the StackMap and StackMapTable attributes.
构造器概要
构造器 构造器 说明 ClassReader(byte[] classFile)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.intgetAccess()Returns the class's access flags (seeOpcodes).StringgetClassName()Returns the internal name of the class (seeType.getInternalName()).String[]getInterfaces()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.intgetItemCount()Returns the number of entries in the class's constant pool table.intgetMaxStringLength()Returns a conservative estimate of the maximum length of the strings contained in the class's constant pool table.StringgetSuperName()Returns the internal of name of the super class (seeType.getInternalName()).intreadByte(int offset)Reads a byte value in thisClassReader.StringreadClass(int offset, char[] charBuffer)Reads a CONSTANT_Class constant pool entry in thisClassReader.ObjectreadConst(int constantPoolEntryIndex, char[] charBuffer)Reads a numeric or string constant pool entry in thisClassReader.intreadInt(int offset)Reads a signed int value in thisClassReader.protected LabelreadLabel(int bytecodeOffset, Label[] labels)Returns the label corresponding to the given bytecode offset.longreadLong(int offset)Reads a signed long value in thisClassReader.StringreadModule(int offset, char[] charBuffer)Reads a CONSTANT_Module constant pool entry in thisClassReader.StringreadPackage(int offset, char[] charBuffer)Reads a CONSTANT_Package constant pool entry in thisClassReader.shortreadShort(int offset)Reads a signed short value in thisClassReader.intreadUnsignedShort(int offset)Reads an unsigned short value in thisClassReader.StringreadUTF8(int offset, char[] charBuffer)Reads a CONSTANT_Utf8 constant pool entry in thisClassReader.
字段详细资料
SKIP_CODE
public static final int SKIP_CODE
A 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_DEBUG
A 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, org.springframework.asm.Label, org.springframework.asm.Label, int),MethodVisitor.visitLineNumber(int, org.springframework.asm.Label)andMethodVisitor.visitParameter(java.lang.String, int)are not called).- 另请参阅:
- 常量字段值
SKIP_FRAMES
public static final int SKIP_FRAMES
A 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_FRAMES
A 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).- 另请参阅:
- 常量字段值
b
@Deprecated public final byte[] b
已过时。UsereadByte(int)and the other read methods instead. This field will eventually be deleted.A byte array containing the JVMS ClassFile structure to be parsed.
header
public final int header
The offset in bytes of the ClassFile's access_flags field.
构造器详细资料
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
public ClassReader(InputStream inputStream) throws IOException
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
public ClassReader(String className) throws IOException
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.
方法详细资料
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.
- 另请参阅:
ClassVisitor.visit(int, int, String, String, String, String[])
getClassName
public String getClassName()
Returns the internal name of the class (seeType.getInternalName()).- 返回:
- the internal class name.
- 另请参阅:
ClassVisitor.visit(int, int, String, String, String, String[])
getSuperName
public String 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. - 另请参阅:
ClassVisitor.visit(int, int, String, String, String, String[])
getInterfaces
public String[] 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.
- 另请参阅:
ClassVisitor.visit(int, int, String, String, String, String[])
accept
public void accept(ClassVisitor classVisitor, int parsingOptions)
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
public void accept(ClassVisitor classVisitor, Attribute[] attributePrototypes, int parsingOptions)
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.
readLabel
protected Label readLabel(int bytecodeOffset, Label[] labels)
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].
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
public String readUTF8(int offset, char[] charBuffer)
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.
readClass
public String readClass(int offset, char[] charBuffer)
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
public String readModule(int offset, char[] charBuffer)
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
public String readPackage(int offset, char[] charBuffer)
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.
readConst
public Object readConst(int constantPoolEntryIndex, char[] charBuffer)
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.