Class BytecodeReadingParanamer.ClassReader

java.lang.Object
com.thoughtworks.paranamer.BytecodeReadingParanamer.ClassReader
Enclosing class:
BytecodeReadingParanamer

private static class BytecodeReadingParanamer.ClassReader extends 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
    final byte[]
    The class to be parsed.
    (package private) static final int
    The type of CONSTANT_Double constant pool items.
    (package private) static final int
    The type of CONSTANT_Fieldref constant pool items.
    (package private) static final int
    The type of CONSTANT_Float constant pool items.
    final int
    Start index of the class header information (access, name...) in b.
    (package private) static final int
    The type of CONSTANT_InterfaceMethodref constant pool items.
    (package private) static final int
    The type of CONSTANT_Integer constant pool items.
    (package private) static final int
    The type of CONSTANT_InvokeDynamic constant pool items.
    private final int[]
    The start index of each constant pool item in b, plus one.
    (package private) static final int
    The type of CONSTANT_Long constant pool items.
    private final int
    Maximum length of the strings contained in the constant pool of the class.
    (package private) static final int
    The type of CONSTANT_Methodref constant pool items.
    (package private) static final int
    The type of CONSTANT_MethodHandle constant pool items.
    (package private) static final int
    The type of CONSTANT_NameAndType constant pool items.
    private final String[]
    The String objects corresponding to the CONSTANT_Utf8 items.
    (package private) static final int
    The type of CONSTANT_Utf8 constant pool items.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    ClassReader(byte[] b)
    Constructs a new BytecodeReadingParanamer.ClassReader object.
    private
    ClassReader(byte[] b, int off)
    Constructs a new BytecodeReadingParanamer.ClassReader object.
    private
    Constructs a new BytecodeReadingParanamer.ClassReader object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Makes the given visitor visit the Java class of this BytecodeReadingParanamer.ClassReader.
    private static byte[]
    Reads the bytecode of a class.
    private int
    readInt(int index)
    Reads a signed int value in b.
    private int
    readMethod(BytecodeReadingParanamer.TypeCollector classVisitor, char[] c, int u)
     
    private int
    readUnsignedShort(int index)
    Reads an unsigned short value in b.
    private String
    readUTF(int index, int utfLen, char[] buf)
    Reads UTF8 string in b.
    private String
    readUTF8(int index, char[] buf)
    Reads an UTF8 string constant pool item in b.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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 in b, plus one. The one byte offset skips the constant pool item tag that indicates its type.
    • strings

      private final 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.
    • FIELD

      static final int FIELD
      The type of CONSTANT_Fieldref constant pool items.
      See Also:
    • METH

      static final int METH
      The type of CONSTANT_Methodref constant pool items.
      See Also:
    • IMETH

      static final int IMETH
      The type of CONSTANT_InterfaceMethodref constant pool items.
      See Also:
    • INT

      static final int INT
      The type of CONSTANT_Integer constant pool items.
      See Also:
    • FLOAT

      static final int FLOAT
      The type of CONSTANT_Float constant pool items.
      See Also:
    • LONG

      static final int LONG
      The type of CONSTANT_Long constant pool items.
      See Also:
    • DOUBLE

      static final int DOUBLE
      The type of CONSTANT_Double constant pool items.
      See Also:
    • NAME_TYPE

      static final int NAME_TYPE
      The type of CONSTANT_NameAndType constant pool items.
      See Also:
    • MHANDLE

      static final int MHANDLE
      The type of CONSTANT_MethodHandle constant pool items.
      See Also:
    • INVOKEDYN

      static final int INVOKEDYN
      The type of CONSTANT_InvokeDynamic constant pool items.
      See Also:
    • UTF8

      static final int UTF8
      The type of CONSTANT_Utf8 constant pool items.
      See Also:
  • Constructor Details

  • Method Details

    • readClass

      private static byte[] readClass(InputStream is) throws 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:
      IOException - if a problem occurs during reading.
    • accept

      private void accept(BytecodeReadingParanamer.TypeCollector classVisitor)
      Makes the given visitor visit the Java class of this BytecodeReadingParanamer.ClassReader. This class is the one specified in the constructor (see ClassReader).
      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 in b. 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 in b.
      Returns:
      the read value.
    • readInt

      private int readInt(int index)
      Reads a signed int value in b. 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 in b.
      Returns:
      the read value.
    • readUTF8

      private String readUTF8(int index, char[] buf)
      Reads an UTF8 string constant pool item in b. 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 in b, 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 String readUTF(int index, int utfLen, char[] buf)
      Reads UTF8 string in b.
      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.