public class 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.
public static final int | EXPAND_FRAMES = 8 A flag to expand the stack map frames. |
public static final int | SKIP_CODE = 1 A flag to skip the Code attributes. |
public static final int | SKIP_DEBUG = 2 A flag to skip the SourceFile, SourceDebugExtension, LocalVariableTable,
LocalVariableTypeTable, LineNumberTable and MethodParameters attributes. |
public static final int | SKIP_FRAMES = 4 A flag to skip the StackMap and StackMapTable attributes. |
public final byte[] | Use readByte( |
public final int | The offset in bytes of the ClassFile's access_flags field. |
public | ClassReader( Constructs a new ClassReader object. |
public | ClassReader( Constructs a new ClassReader object. |
public | ClassReader( Constructs a new ClassReader object. |
public | ClassReader( Constructs a new ClassReader object. |
public void | accept( Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this
ClassReader. |
public void | accept( Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this
ClassReader. |
public int | Returns the class's access flags (see Opcodes). |
public String | Returns the internal name of the class (see Type.getInternalName()). |
public String[] | Returns the internal names of the implemented interfaces (see Type.getInternalName()). |
public int | getItem( Returns the start offset in this ClassReader of a JVMS 'cp_info' structure (i.e. |
public int | Returns the number of entries in the class's constant pool table. |
public int | Returns a conservative estimate of the maximum length of the strings contained in the class's
constant pool table. |
public String | Returns the internal of name of the super class (see Type.getInternalName()). |
public int | readByte( Reads a byte value in this ClassReader. |
public String | readClass( Reads a CONSTANT_Class constant pool entry in this ClassReader. |
public Object | readConst( Reads a numeric or string constant pool entry in this ClassReader. |
public int | readInt( Reads a signed int value in this ClassReader. |
protected Label | Returns the label corresponding to the given bytecode offset. |
public long | readLong( Reads a signed long value in this ClassReader. |
public String | readModule( Reads a CONSTANT_Module constant pool entry in this ClassReader. |
public String | readPackage( Reads a CONSTANT_Package constant pool entry in this ClassReader. |
public short | readShort( Reads a signed short value in this ClassReader. |
public String | readUTF8( Reads a CONSTANT_Utf8 constant pool entry in this ClassReader. |
public int | readUnsignedShort( Reads an unsigned short value in this ClassReader. |
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).
A flag to skip the Code attributes. If this flag is set the Code attributes are neither parsed
nor visited.
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(String, String) , MethodVisitor.visitLocalVariable(String, String, String, Label, Label, int) , MethodVisitor.visitLineNumber(int, Label) and MethodVisitor.visitParameter(String, int) are not called).
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, Object[], int, 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.
Use readByte(int) and the other read methods instead. This field will
eventually be deleted.
A byte array containing the JVMS ClassFile structure to be parsed.
The offset in bytes of the ClassFile's access_flags field.
Constructs a new ClassReader object.
inputStreaman 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.
IOExceptionif a problem occurs during reading.
Constructs a new ClassReader object.
classNamethe fully qualified name of the class to be read. The ClassFile structure is
retrieved with the current class loader's ClassLoader.getSystemResourceAsStream(String) .
IOExceptionif an exception occurs during reading.
Constructs a new ClassReader object.
classFilethe JVMS ClassFile structure to be read.
Constructs a new ClassReader object.
classFileBuffera byte array containing the JVMS ClassFile structure to be read.
classFileOffsetthe offset in byteBuffer of the first byte of the ClassFile to be read.
classFileLengththe length in bytes of the ClassFile to be read.
Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this
ClassReader.
classVisitorthe visitor that must visit this class.
parsingOptionsthe options to use to parse this class. One or more of SKIP_CODE, SKIP_DEBUG, SKIP_FRAMES or EXPAND_FRAMES.
Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this
ClassReader.
classVisitorthe visitor that must visit this class.
attributePrototypesprototypes 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.
parsingOptionsthe options to use to parse this class. One or more of SKIP_CODE, SKIP_DEBUG, SKIP_FRAMES or EXPAND_FRAMES.
Returns the class's access flags (see Opcodes). 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.
Returns the internal name of the class (see Type.getInternalName()).
the internal class name.
Returns the internal names of the implemented interfaces (see Type.getInternalName()).
the internal names of the directly implemented interfaces. Inherited implemented
interfaces are not returned.
Returns the start offset in this 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.
constantPoolEntryIndexthe index a constant pool entry in the class's constant pool
table.
the start offset in this ClassReader of the corresponding JVMS 'cp_info'
structure, plus one.
Returns the number of entries in the class's constant pool table.
the number of entries in the class's constant pool table.
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.
Returns the internal of name of the super class (see Type.getInternalName()). For
interfaces, the super class is Object.
the internal name of the super class, or null for Object class.
Reads a byte value in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
offsetthe start offset of the value to be read in this ClassReader.
the read value.
Reads a CONSTANT_Class constant pool entry in this ClassReader. This method is
intended for Attribute sub classes, and is normally not needed by class generators or
adapters.
offsetthe 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.
charBufferthe 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.
Reads a numeric or string constant pool entry in this ClassReader. This method is
intended for Attribute sub classes, and is normally not needed by class generators or
adapters.
constantPoolEntryIndexthe 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.
charBufferthe buffer to be used to read strings. This buffer must be sufficiently
large. It is not automatically resized.
Reads a signed int value in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
offsetthe start offset of the value to be read in this ClassReader.
the read value.
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.
bytecodeOffseta bytecode offset in a method.
labelsthe 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].
Reads a signed long value in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
offsetthe start offset of the value to be read in this ClassReader.
the read value.
Reads a CONSTANT_Module constant pool entry in this ClassReader. This method is
intended for Attribute sub classes, and is normally not needed by class generators or
adapters.
offsetthe 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.
charBufferthe 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.
Reads a CONSTANT_Package constant pool entry in this ClassReader. This method is
intended for Attribute sub classes, and is normally not needed by class generators or
adapters.
offsetthe 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.
charBufferthe 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.
Reads a signed short value in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
offsetthe start offset of the value to be read in this ClassReader.
the read value.
Reads a CONSTANT_Utf8 constant pool entry in this ClassReader. This method is
intended for Attribute sub classes, and is normally not needed by class generators or
adapters.
offsetthe 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.
charBufferthe 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.
Reads an unsigned short value in this ClassReader. This method is intended for
Attribute sub classes, and is normally not needed by class generators or adapters.
offsetthe start index of the value to be read in this ClassReader.
the read value.