类 ClassReader
java.lang.Object
org.beetl.ow2.asm.ClassReader
A Java class parser to make a
ClassVisitor visit an existing class.
This class parses a byte array conforming to the Java class file format and
calls the appropriate visit methods of a given class visitor for each field,
method and bytecode instruction encountered.- 作者:
- Eric Bruneton, Eugene Kuleshov
-
字段概要
字段修饰符和类型字段说明final byte[]The class to be parsed.static final intFlag to expand the stack map frames.final intStart index of the class header information (access, className...) inb.static final intFlag to skip method code.static final intFlag to skip the debug information in the class.static final intFlag to skip the stack map frames in the class. -
构造器概要
构造器构造器说明ClassReader(byte[] b) Constructs a newClassReaderobject.ClassReader(byte[] b, int off, int len) Constructs a newClassReaderobject.Constructs a newClassReaderobject.ClassReader(String name) Constructs a newClassReaderobject. -
方法概要
修饰符和类型方法说明voidaccept(ClassVisitor classVisitor, int flags) Makes the given visitor visit the Java class of thisClassReader.voidaccept(ClassVisitor classVisitor, Attribute[] attrs, int flags) Makes the given visitor visit the Java class of thisClassReader.intReturns the class's access flags (seeOpcodes).Returns the internal className of the class (seegetInternalName).String[]Returns the internal names of the class's interfaces (seegetInternalName).intgetItem(int item) Returns the start index of the constant pool item inb, plus one.intReturns the number of constant pool items inb.intReturns the maximum length of the strings contained in the constant pool of the class.Returns the internal of className of the super class (seegetInternalName).intreadByte(int index) Reads a byte value inb.readClass(int index, char[] buf) Reads a class constant pool item inb.readConst(int item, char[] buf) Reads a numeric or string constant pool item inb.intreadInt(int index) Reads a signed int value inb.protected LabelReturns the label corresponding to the given offset.longreadLong(int index) Reads a signed long value inb.shortreadShort(int index) Reads a signed short value inb.intreadUnsignedShort(int index) Reads an unsigned short value inb.readUTF8(int index, char[] buf) Reads an UTF8 string constant pool item inb.
-
字段详细资料
-
SKIP_CODE
public static final int SKIP_CODEFlag to skip method code. If this class is setCODEattribute won't be visited. This can be used, for example, to retrieve annotations for methods and method parameters.- 另请参阅:
-
SKIP_DEBUG
public static final int SKIP_DEBUGFlag to skip the debug information in the class. If this flag is set the debug information of the class is not visited, i.e. thevisitLocalVariableandvisitLineNumbermethods will not be called.- 另请参阅:
-
SKIP_FRAMES
public static final int SKIP_FRAMESFlag to skip the stack map frames in the class. If this flag is set the stack map frames of the class is not visited, i.e. thevisitFramemethod will not be called. This flag is useful when theClassWriter.COMPUTE_FRAMESoption is used: it avoids visiting frames that will be ignored and recomputed from scratch in the class writer.- 另请参阅:
-
EXPAND_FRAMES
public static final int EXPAND_FRAMESFlag 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/recompression step in ClassReader and ClassWriter which degrades performances quite a lot).- 另请参阅:
-
b
public final byte[] bThe class 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 generators or adapters. -
header
public final int headerStart index of the class header information (access, className...) inb.
-
-
构造器详细资料
-
ClassReader
public ClassReader(byte[] b) Constructs a newClassReaderobject.- 参数:
b- the bytecode of the class to be read.
-
ClassReader
public ClassReader(byte[] b, int off, int len) Constructs a newClassReaderobject.- 参数:
b- the bytecode of the class to be read.off- the start offset of the class data.len- the length of the class data.
-
ClassReader
Constructs a newClassReaderobject.- 参数:
is- an input stream from which to read the class.- 抛出:
IOException- if a problem occurs during reading.
-
ClassReader
Constructs a newClassReaderobject.- 参数:
name- the binary qualified className of the class to be read.- 抛出:
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
- 另请参阅:
-
getClassName
Returns the internal className of the class (seegetInternalName).- 返回:
- the internal class className
- 另请参阅:
-
getSuperName
Returns the internal of className of the super class (seegetInternalName). For interfaces, the super class isObject.- 返回:
- the internal className of super class, or null for
Objectclass. - 另请参阅:
-
getInterfaces
Returns the internal names of the class's interfaces (seegetInternalName).- 返回:
- the array of internal names for all implemented interfaces or null.
- 另请参阅:
-
accept
Makes the given visitor visit the Java class of thisClassReader. This class is the one specified in the constructor (seeClassReader).- 参数:
classVisitor- the visitor that must visit this class.flags- option flags that can be used to modify the default behavior of this class. SeeSKIP_DEBUG,EXPAND_FRAMES,SKIP_FRAMES,SKIP_CODE.
-
accept
Makes the given visitor visit the Java class of thisClassReader. This class is the one specified in the constructor (seeClassReader).- 参数:
classVisitor- the visitor that must visit this class.attrs- 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.flags- option flags that can be used to modify the default behavior of this class. SeeSKIP_DEBUG,EXPAND_FRAMES,SKIP_FRAMES,SKIP_CODE.
-
readLabel
Returns the label corresponding to the given offset. The default implementation of this method creates a label for the given offset if it has not been already created.- 参数:
offset- a bytecode offset in a method.labels- the already created labels, indexed by their offset. If a label already exists for offset 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[offset].
-
getItemCount
public int getItemCount()Returns the number of constant pool items inb.- 返回:
- the number of constant pool items in
b.
-
getItem
public int getItem(int item) Returns the start index of the constant pool item inb, plus one. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
item- the index a constant pool item.- 返回:
- the start index of the constant pool item in
b, plus one.
-
getMaxStringLength
public int getMaxStringLength()Returns the maximum length of the strings contained in the constant pool of the class.- 返回:
- the maximum length of the strings contained in the constant pool of the class.
-
readByte
public int readByte(int index) Reads a byte value inb. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
index- the start index of the value to be read inb.- 返回:
- the read value.
-
readUnsignedShort
public int readUnsignedShort(int index) Reads an unsigned short value inb. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
index- the start index of the value to be read inb.- 返回:
- the read value.
-
readShort
public short readShort(int index) Reads a signed short value inb. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
index- the start index of the value to be read inb.- 返回:
- the read value.
-
readInt
public int readInt(int index) Reads a signed int value inb. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
index- the start index of the value to be read inb.- 返回:
- the read value.
-
readLong
public long readLong(int index) Reads a signed long value inb. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
index- the start index of the value to be read inb.- 返回:
- the read value.
-
readUTF8
Reads an UTF8 string constant pool item inb. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
index- the start index of an unsigned short value inb, whose value is the index of an UTF8 constant pool item.buf- 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 UTF8 item.
-
readClass
Reads a class constant pool item inb. This method is intended forAttributesub classes, and is normally not needed by class generators or adapters.- 参数:
index- the start index of an unsigned short value inb, whose value is the index of a class constant pool item.buf- 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 class item.
-
readConst
-