类 ClassReader
java.lang.Object
com.alibaba.nacos.common.packagescan.classreading.ClassReader
Copy from ASM, with less modifications
A parser to make a 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
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明final byte[]已过时。static final intA flag to expand the stack map frames.final intThe offset in bytes of the ClassFile's access_flags field.static final intA flag to skip the Code attributes.static final intA flag to skip the SourceFile.static final intA flag to skip the StackMap and StackMapTable attributes.static final int -
构造器概要
构造器构造器说明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. -
方法概要
修饰符和类型方法说明intReturns the class's access flags .the internal class name.String[]the internal names of the directly implemented interfaces.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.intreadByte(int offset) Reads a byte value in thisClassReader.readClass(int offset, char[] charBuffer) Reads a CONSTANT_Class constant pool entry in thisClassReader.intreadInt(int offset) Reads a signed int value in thisClassReader.longreadLong(int offset) Reads a signed long value in thisClassReader.readModule(int offset, char[] charBuffer) Reads a CONSTANT_Module constant pool entry in thisClassReader.readPackage(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.readUtf8(int offset, char[] charBuffer) Reads a CONSTANT_Utf8 constant pool entry in thisClassReader.
-
字段详细资料
-
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.- 另请参阅:
-
V19
public static final int V19- 另请参阅:
-
SKIP_DEBUG
public static final int SKIP_DEBUGA flag to skip the SourceFile.- 另请参阅:
-
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 is not called). This flag is useful when the option 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).- 另请参阅:
-
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 headerThe 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
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.
-
-
方法详细资料
-
getAccess
public int getAccess()Returns the class's access flags . 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
the internal class name. -
getSuperName
-
getInterfaces
the internal names of the directly implemented interfaces. Inherited implemented interfaces are not returned. -
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 for Attribute sub 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 for Attribute sub 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 for Attribute sub 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 for Attribute sub 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 for Attribute sub 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 for Attribute sub 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 for Attribute sub 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
Reads a CONSTANT_Class constant pool entry in thisClassReader. This method is intended for Attribute sub 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 for Attribute sub 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 for Attribute sub 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.
-
readByte(int)and the other read methods instead.