public class ClassReader
extends java.lang.Object
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.| 限定符和类型 | 字段和说明 |
|---|---|
byte[] |
b
已过时。
Use
readByte(int) and the other read methods
instead. This field will eventually be deleted. |
static int |
EXPAND_FRAMES
A flag to expand the stack map frames.
|
int |
header
The offset in bytes of the ClassFile's access_flags field.
|
static int |
SKIP_CODE
A flag to skip the Code attributes.
|
static int |
SKIP_DEBUG
A flag to skip the SourceFile, SourceDebugExtension, LocalVariableTable,
LocalVariableTypeTable and LineNumberTable attributes.
|
static int |
SKIP_FRAMES
A flag to skip the StackMap and StackMapTable attributes.
|
| 构造器和说明 |
|---|
ClassReader(byte[] classFile)
Constructs a new
ClassReader object. |
ClassReader(byte[] classFileBuffer,
int classFileOffset,
int classFileLength)
Constructs a new
ClassReader object. |
ClassReader(java.io.InputStream inputStream)
Constructs a new
ClassReader object. |
ClassReader(java.lang.String className)
Constructs a new
ClassReader object. |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
accept(ClassVisitor classVisitor,
Attribute[] attributePrototypes,
int parsingOptions)
Makes the given visitor visit the JVMS ClassFile structure passed to the
constructor of this
ClassReader. |
void |
accept(ClassVisitor classVisitor,
int parsingOptions)
Makes the given visitor visit the JVMS ClassFile structure passed to the
constructor of this
ClassReader. |
int |
getAccess()
Returns the class's access flags (see
Opcodes). |
java.lang.String |
getClassName()
Returns the internal name of the class (see
Type.getInternalName()). |
java.lang.String[] |
getInterfaces()
Returns the internal names of the implemented interfaces (see
Type.getInternalName()). |
int |
getItem(int constantPoolEntryIndex)
Returns the start offset in this
ClassReader of a JVMS 'cp_info'
structure (i.e. a constant pool entry), plus one. |
int |
getItemCount()
Returns the number of entries in the class's constant pool table.
|
int |
getMaxStringLength()
Returns a conservative estimate of the maximum length of the strings
contained in the class's constant pool table.
|
java.lang.String |
getSuperName()
Returns the internal of name of the super class (see
Type.getInternalName()). |
int |
readByte(int offset)
Reads a byte value in this
ClassReader. |
java.lang.String |
readClass(int offset,
char[] charBuffer)
Reads a CONSTANT_Class constant pool entry in this
ClassReader. |
java.lang.Object |
readConst(int constantPoolEntryIndex,
char[] charBuffer)
Reads a numeric or string constant pool entry in this
ClassReader. |
int |
readInt(int offset)
Reads a signed int value in this
ClassReader. |
protected Label |
readLabel(int bytecodeOffset,
Label[] labels)
Returns the label corresponding to the given bytecode offset.
|
long |
readLong(int offset)
Reads a signed long value in this
ClassReader. |
java.lang.String |
readModule(int offset,
char[] charBuffer)
Reads a CONSTANT_Module constant pool entry in this
ClassReader. |
java.lang.String |
readPackage(int offset,
char[] charBuffer)
Reads a CONSTANT_Package constant pool entry in this
ClassReader. |
short |
readShort(int offset)
Reads a signed short value in this
ClassReader. |
int |
readUnsignedShort(int offset)
Reads an unsigned short value in this
ClassReader. |
java.lang.String |
readUTF8(int offset,
char[] charBuffer)
Reads a CONSTANT_Utf8 constant pool entry in this
ClassReader. |
public static final int SKIP_CODE
public static final int SKIP_DEBUG
ClassVisitor.visitSource(java.lang.String, java.lang.String),
MethodVisitor.visitLocalVariable(java.lang.String, java.lang.String, java.lang.String, xyz.noark.asm.Label, xyz.noark.asm.Label, int) and
MethodVisitor.visitLineNumber(int, xyz.noark.asm.Label) are not called).public static final int SKIP_FRAMES
MethodVisitor.visitFrame(int, int, java.lang.Object[], int, java.lang.Object[]) is not called). This flag is useful when
the ClassWriter.COMPUTE_FRAMES option is used: it avoids visiting
frames that will be ignored and recomputed from scratch.public static final int EXPAND_FRAMES
@Deprecated public final byte[] b
readByte(int) and the other read methods
instead. This field will eventually be deleted.public final int header
public ClassReader(byte[] classFile)
ClassReader object.classFile - the JVMS ClassFile structure to be read.public ClassReader(byte[] classFileBuffer,
int classFileOffset,
int classFileLength)
ClassReader object.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.public ClassReader(java.io.InputStream inputStream)
throws java.io.IOException
ClassReader object.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.java.io.IOException - if a problem occurs during reading.public ClassReader(java.lang.String className)
throws java.io.IOException
ClassReader object.className - the fully qualified name of the class to be read. The
ClassFile structure is retrieved with the current class
loader's ClassLoader.getSystemResourceAsStream(java.lang.String).java.io.IOException - if an exception occurs during reading.public int getAccess()
Opcodes). This value may
not reflect Deprecated and Synthetic flags when bytecode is before 1.5
and those flags are represented by attributes.ClassVisitor.visit(int, int, String, String, String, String[])public java.lang.String getClassName()
Type.getInternalName()).ClassVisitor.visit(int, int, String, String, String, String[])public java.lang.String getSuperName()
Type.getInternalName()). For interfaces, the super class is
Object.Object class.ClassVisitor.visit(int, int, String, String, String, String[])public java.lang.String[] getInterfaces()
Type.getInternalName()).ClassVisitor.visit(int, int, String, String, String, String[])public void accept(ClassVisitor classVisitor, int parsingOptions)
ClassReader.classVisitor - the visitor that must visit this class.parsingOptions - the options to use to parse this class. One or more
of SKIP_CODE, SKIP_DEBUG,
SKIP_FRAMES or EXPAND_FRAMES.public void accept(ClassVisitor classVisitor, Attribute[] attributePrototypes, int parsingOptions)
ClassReader.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
of SKIP_CODE, SKIP_DEBUG,
SKIP_FRAMES or EXPAND_FRAMES.protected Label readLabel(int bytecodeOffset, Label[] labels)
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.public int getItemCount()
public int getItem(int constantPoolEntryIndex)
ClassReader of 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.ClassReader of the corresponding
JVMS 'cp_info' structure, plus one.public int getMaxStringLength()
public int readByte(int offset)
ClassReader. 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 this
ClassReader.public int readUnsignedShort(int offset)
ClassReader. 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 this
ClassReader.public short readShort(int offset)
ClassReader. 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 this
ClassReader.public int readInt(int offset)
ClassReader. 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 this
ClassReader.public long readLong(int offset)
ClassReader. 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 this
ClassReader.public java.lang.String readUTF8(int offset,
char[] charBuffer)
ClassReader.
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 this
ClassReader, 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.public java.lang.String readClass(int offset,
char[] charBuffer)
ClassReader.
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 this
ClassReader, 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.public java.lang.String readModule(int offset,
char[] charBuffer)
ClassReader.
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 this
ClassReader, 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.public java.lang.String readPackage(int offset,
char[] charBuffer)
ClassReader.
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 this
ClassReader, 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.public java.lang.Object readConst(int constantPoolEntryIndex,
char[] charBuffer)
ClassReader. This method is intended for Attribute sub
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.Integer, Float, Long, Double,
String, Type, Handle or
ConstantDynamic corresponding to the specified constant
pool entry.