Package com.thoughtworks.paranamer
Class BytecodeReadingParanamer.ClassReader
- java.lang.Object
-
- com.thoughtworks.paranamer.BytecodeReadingParanamer.ClassReader
-
- Enclosing class:
- BytecodeReadingParanamer
private static class BytecodeReadingParanamer.ClassReader extends java.lang.Object
A Java class parser to make a Class Visitor 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.
-
-
Field Summary
Fields Modifier and Type Field Description byte[]
b
The class to be parsed.(package private) static int
DOUBLE
The type of CONSTANT_Double constant pool items.(package private) static int
FIELD
The type of CONSTANT_Fieldref constant pool items.(package private) static int
FLOAT
The type of CONSTANT_Float constant pool items.int
header
Start index of the class header information (access, name...) inb
.(package private) static int
IMETH
The type of CONSTANT_InterfaceMethodref constant pool items.(package private) static int
INT
The type of CONSTANT_Integer constant pool items.(package private) static int
INVOKEDYN
The type of CONSTANT_InvokeDynamic constant pool items.private int[]
items
The start index of each constant pool item inb
, plus one.(package private) static int
LONG
The type of CONSTANT_Long constant pool items.private int
maxStringLength
Maximum length of the strings contained in the constant pool of the class.(package private) static int
METH
The type of CONSTANT_Methodref constant pool items.(package private) static int
MHANDLE
The type of CONSTANT_MethodHandle constant pool items.(package private) static int
NAME_TYPE
The type of CONSTANT_NameAndType constant pool items.private java.lang.String[]
strings
The String objects corresponding to the CONSTANT_Utf8 items.(package private) static int
UTF8
The type of CONSTANT_Utf8 constant pool items.
-
Constructor Summary
Constructors Modifier Constructor Description private
ClassReader(byte[] b)
Constructs a newBytecodeReadingParanamer.ClassReader
object.private
ClassReader(byte[] b, int off)
Constructs a newBytecodeReadingParanamer.ClassReader
object.private
ClassReader(java.io.InputStream is)
Constructs a newBytecodeReadingParanamer.ClassReader
object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
accept(BytecodeReadingParanamer.TypeCollector classVisitor)
Makes the given visitor visit the Java class of thisBytecodeReadingParanamer.ClassReader
.private static byte[]
readClass(java.io.InputStream is)
Reads the bytecode of a class.private int
readInt(int index)
Reads a signed int value inb
.private int
readMethod(BytecodeReadingParanamer.TypeCollector classVisitor, char[] c, int u)
private int
readUnsignedShort(int index)
Reads an unsigned short value inb
.private java.lang.String
readUTF(int index, int utfLen, char[] buf)
Reads UTF8 string inb
.private java.lang.String
readUTF8(int index, char[] buf)
Reads an UTF8 string constant pool item inb
.
-
-
-
Field Detail
-
b
public final byte[] b
The class to be parsed. The content of this array must not be modified. This field is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
-
items
private final int[] items
The start index of each constant pool item inb
, plus one. The one byte offset skips the constant pool item tag that indicates its type.
-
strings
private final java.lang.String[] strings
The String objects corresponding to the CONSTANT_Utf8 items. This cache avoids multiple parsing of a given CONSTANT_Utf8 constant pool item, which GREATLY improves performances (by a factor 2 to 3). This caching strategy could be extended to all constant pool items, but its benefit would not be so great for these items (because they are much less expensive to parse than CONSTANT_Utf8 items).
-
maxStringLength
private final int maxStringLength
Maximum length of the strings contained in the constant pool of the class.
-
header
public final int header
Start index of the class header information (access, name...) inb
.
-
FIELD
static final int FIELD
The type of CONSTANT_Fieldref constant pool items.- See Also:
- Constant Field Values
-
METH
static final int METH
The type of CONSTANT_Methodref constant pool items.- See Also:
- Constant Field Values
-
IMETH
static final int IMETH
The type of CONSTANT_InterfaceMethodref constant pool items.- See Also:
- Constant Field Values
-
INT
static final int INT
The type of CONSTANT_Integer constant pool items.- See Also:
- Constant Field Values
-
FLOAT
static final int FLOAT
The type of CONSTANT_Float constant pool items.- See Also:
- Constant Field Values
-
LONG
static final int LONG
The type of CONSTANT_Long constant pool items.- See Also:
- Constant Field Values
-
DOUBLE
static final int DOUBLE
The type of CONSTANT_Double constant pool items.- See Also:
- Constant Field Values
-
NAME_TYPE
static final int NAME_TYPE
The type of CONSTANT_NameAndType constant pool items.- See Also:
- Constant Field Values
-
MHANDLE
static final int MHANDLE
The type of CONSTANT_MethodHandle constant pool items.- See Also:
- Constant Field Values
-
INVOKEDYN
static final int INVOKEDYN
The type of CONSTANT_InvokeDynamic constant pool items.- See Also:
- Constant Field Values
-
UTF8
static final int UTF8
The type of CONSTANT_Utf8 constant pool items.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ClassReader
private ClassReader(byte[] b)
Constructs a newBytecodeReadingParanamer.ClassReader
object.- Parameters:
b
- the bytecode of the class to be read.
-
ClassReader
private ClassReader(byte[] b, int off)
Constructs a newBytecodeReadingParanamer.ClassReader
object.- Parameters:
b
- the bytecode of the class to be read.off
- the start offset of the class data.
-
ClassReader
private ClassReader(java.io.InputStream is) throws java.io.IOException
Constructs a newBytecodeReadingParanamer.ClassReader
object.- Parameters:
is
- an input stream from which to read the class.- Throws:
java.io.IOException
- if a problem occurs during reading.
-
-
Method Detail
-
readClass
private static byte[] readClass(java.io.InputStream is) throws java.io.IOException
Reads the bytecode of a class.- Parameters:
is
- an input stream from which to read the class.- Returns:
- the bytecode read from the given input stream.
- Throws:
java.io.IOException
- if a problem occurs during reading.
-
accept
private void accept(BytecodeReadingParanamer.TypeCollector classVisitor)
Makes the given visitor visit the Java class of thisBytecodeReadingParanamer.ClassReader
. This class is the one specified in the constructor (seeClassReader
).- Parameters:
classVisitor
- the visitor that must visit this class.
-
readMethod
private int readMethod(BytecodeReadingParanamer.TypeCollector classVisitor, char[] c, int u)
-
readUnsignedShort
private int readUnsignedShort(int index)
Reads an unsigned short value inb
. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- Parameters:
index
- the start index of the value to be read inb
.- Returns:
- the read value.
-
readInt
private int readInt(int index)
Reads a signed int value inb
. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- Parameters:
index
- the start index of the value to be read inb
.- Returns:
- the read value.
-
readUTF8
private java.lang.String readUTF8(int index, char[] buf)
Reads an UTF8 string constant pool item inb
. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- Parameters:
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.- Returns:
- the String corresponding to the specified UTF8 item.
-
readUTF
private java.lang.String readUTF(int index, int utfLen, char[] buf)
Reads UTF8 string inb
.- Parameters:
index
- start offset of the UTF8 string to be read.utfLen
- length of the UTF8 string to be read.buf
- buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.- Returns:
- the String corresponding to the specified UTF8 string.
-
-