ClassReader (Grails 6.0.0)

Package: org.grails.asm

## [Java] Class ClassReader

- org.grails.asm.ClassReader

-     class ClassReader
      extends java.lang.Object

  A Java class parser to make a org.springframework.asm.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.

  Authors:
    Eric Bruneton
    Eugene Kuleshov

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static int` | `ACC_SYNTHETIC_ATTRIBUTE` | Pseudo access flag to distinguish between the synthetic attribute and the synthetic access flag.
    `static boolean` | `ANNOTATIONS` | True to enable annotations support.
    `static int` | `CLASS` | The type of CONSTANT_Class constant pool items.
    `static int` | `DOUBLE` | The type of CONSTANT_Double constant pool items.
    `static int` | `FIELD` | The type of CONSTANT_Fieldref constant pool items.
    `static int` | `FLOAT` | The type of CONSTANT_Float constant pool items.
    `static int` | `HANDLE` | The type of CONSTANT_MethodHandle constant pool items.
    `static int` | `IMETH` | The type of CONSTANT_InterfaceMethodref constant pool items.
    `static int` | `INDY` | The type of CONSTANT_InvokeDynamic constant pool items.
    `static int` | `INT` | The type of CONSTANT_Integer constant pool items.
    `static int` | `LONG` | The type of CONSTANT_Long constant pool items.
    `static int` | `METH` | The type of CONSTANT_Methodref constant pool items.
    `static int` | `MTYPE` | The type of CONSTANT_MethodType constant pool items.
    `static int` | `NAME_TYPE` | The type of CONSTANT_NameAndType constant pool items.
    `static boolean` | `SIGNATURES` | True to enable signatures support.
    `static int` | `SKIP_DEBUG` | Flag to skip the debug information in the class.
    `static int` | `STR` | The type of CONSTANT_String constant pool items.
    `static int` | `UTF8` | The type of CONSTANT_Utf8 constant pool items.
    `byte[]` | `b` | The class to be parsed.
    `int` | `header` | Start index of the class header information (access, name...) in b.
    `private int[]` | `items` | The start index of each constant pool item in b, plus one.
    `private int` | `maxStringLength` | Maximum length of the strings contained in the constant pool of the class.
    `private java.lang.String[]` | `strings` | The String objects corresponding to the CONSTANT_Utf8 items.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `private ClassReader (byte[] b)` Constructs a new org.springframework.asm.ClassReader object.
    `ClassReader (byte[] b, int off, int len)` Constructs a new org.springframework.asm.ClassReader object.
    `ClassReader (java.io.InputStream is)` Constructs a new org.springframework.asm.ClassReader object.
    `ClassReader (java.lang.String name)` Constructs a new org.springframework.asm.ClassReader object.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `accept(org.springframework.asm.ClassVisitor classVisitor, int flags)` Makes the given visitor visit the Java class of this org.springframework.asm.ClassReader .
    `` | `public void` | `accept(org.springframework.asm.ClassVisitor classVisitor, Attribute[] attrs, int flags)` Makes the given visitor visit the Java class of this org.springframework.asm.ClassReader.
    `` | `public int` | `getAccess()` Returns the class's access flags (see org.springframework.asm.Opcodes).
    `` | `private int` | `getAttributes()` Returns the start index of the attribute_info structure of this class.
    `` | `public java.lang.String` | `getClassName()` Returns the internal name of the class (see org.springframework.asm.Type#getInternalName()).
    `` | `public java.lang.String[]` | `getInterfaces()` Returns the internal names of the class's interfaces (see org.springframework.asm.Type#getInternalName()).
    `` | `public java.lang.String` | `getSuperName()` Returns the internal of name of the super class (see org.springframework.asm.Type#getInternalName()).
    `` | `private int` | `readAnnotationValue(int v, char[] buf, java.lang.String name, org.springframework.asm.AnnotationVisitor av)` Reads a value of an annotation and makes the given visitor visit it.
    `` | `private int` | `readAnnotationValues(int v, char[] buf, boolean named, org.springframework.asm.AnnotationVisitor av)` Reads the values of an annotation and makes the given visitor visit them.
    `` | `private Attribute` | `readAttribute(Attribute[] attrs, java.lang.String type, int off, int len, char[] buf, int codeOff, org.springframework.asm.Label[] labels)` Reads an attribute in b.
    `` | `public int` | `readByte(int index)` Reads a byte value in b.
    `` | `private static byte[]` | `readClass(java.io.InputStream is, boolean close)` Reads the bytecode of a class.
    `` | `public java.lang.String` | `readClass(int index, char[] buf)` Reads a class constant pool item in b.
    `` | `public java.lang.Object` | `readConst(int item, char[] buf)` Reads a numeric or string constant pool item in b.
    `` | `public int` | `readInt(int index)` Reads a signed int value in b.
    `` | `protected org.springframework.asm.Label` | `readLabel(int offset, org.springframework.asm.Label[] labels)` Returns the label corresponding to the given offset.
    `` | `public long` | `readLong(int index)` Reads a signed long value in b.
    `` | `public short` | `readShort(int index)` Reads a signed short value in b.
    `` | `private java.lang.String` | `readUTF(int index, int utfLen, char[] buf)` Reads UTF8 string in b.
    `` | `public java.lang.String` | `readUTF8(int index, char[] buf)` Reads an UTF8 string constant pool item in b.
    `` | `public int` | `readUnsignedShort(int index)` Reads an unsigned short value in b.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Field Detail

    - #### static final int ACC_SYNTHETIC_ATTRIBUTE

      Pseudo access flag to distinguish between the synthetic attribute and the synthetic access flag.

    - #### static final boolean ANNOTATIONS

      True to enable annotations support.

    - #### static final int CLASS

      The type of CONSTANT_Class constant pool items.

    - #### static final int DOUBLE

      The type of CONSTANT_Double constant pool items.

    - #### static final int FIELD

      The type of CONSTANT_Fieldref constant pool items.

    - #### static final int FLOAT

      The type of CONSTANT_Float constant pool items.

    - #### static final int HANDLE

      The type of CONSTANT_MethodHandle constant pool items.

    - #### static final int IMETH

      The type of CONSTANT_InterfaceMethodref constant pool items.

    - #### static final int INDY

      The type of CONSTANT_InvokeDynamic constant pool items.

    - #### static final int INT

      The type of CONSTANT_Integer constant pool items.

    - #### static final int LONG

      The type of CONSTANT_Long constant pool items.

    - #### static final int METH

      The type of CONSTANT_Methodref constant pool items.

    - #### static final int MTYPE

      The type of CONSTANT_MethodType constant pool items.

    - #### static final int NAME_TYPE

      The type of CONSTANT_NameAndType constant pool items.

    - #### static final boolean SIGNATURES

      True to enable signatures support.

    - #### public static final int SKIP_DEBUG

      Flag to skip the debug information in the class. If this flag is set the debug information of the class is not visited, i.e. the org.springframework.asm.MethodVisitor#visitLocalVariable and org.springframework.asm.MethodVisitor#visitLineNumber methods will not be called.

    - #### static final int STR

      The type of CONSTANT_String constant pool items.

    - #### static final int UTF8

      The type of CONSTANT_Utf8 constant pool items.

    - #### public final byte[] b

      The class to be parsed. The content of this array must not be modified. This field is intended for org.springframework.asm.Attribute sub classes, and is normally not needed by class generators or adapters.

    - #### public final int header

      Start index of the class header information (access, name...) in b.

    - #### 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.

    - #### private final int maxStringLength

      Maximum length of the strings contained in the constant pool of the class.

    - #### 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).

  - ### Constructor Detail

    - #### private ClassReader(byte[] b)

      Constructs a new org.springframework.asm.ClassReader object.

      Parameters:
        `b` - the bytecode of the class to be read.

    - #### public ClassReader(byte[] b, int off, int len)

      Constructs a new org.springframework.asm.ClassReader object.

      Parameters:
        `b` - the bytecode of the class to be read.
        `off` - the start offset of the class data.
        `len` - the length of the class data.

    - #### public ClassReader(java.io.InputStream is)

      Constructs a new org.springframework.asm.ClassReader object.

      throws:
        IOException if a problem occurs during reading.
      Parameters:
        `is` - an input stream from which to read the class.

    - #### public ClassReader(java.lang.String name)

      Constructs a new org.springframework.asm.ClassReader object.

      throws:
        IOException if an exception occurs during reading.
      Parameters:
        `name` - the binary qualified name of the class to be read.

  - ### Method Detail

    - #### public void accept(org.springframework.asm.ClassVisitor classVisitor, int flags)

      Makes the given visitor visit the Java class of this org.springframework.asm.ClassReader . This class is the one specified in the constructor (see ClassReader).

      Parameters:
        `classVisitor` - the visitor that must visit this class.

    - #### public void accept(org.springframework.asm.ClassVisitor classVisitor, Attribute[] attrs, int flags)

      Makes the given visitor visit the Java class of this org.springframework.asm.ClassReader. This class is the one specified in the constructor (see ClassReader).

      Parameters:
        `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.

    - #### public int getAccess()

      Returns the class's access flags (see org.springframework.asm.Opcodes). This value may not reflect Deprecated and Synthetic flags when bytecode is before 1.5 and those flags are represented by attributes.

      Returns:
        the class access flags
      See Also:
        org.springframework.asm.ClassVisitor#visit(int, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

    - #### private int getAttributes()

      Returns the start index of the attribute_info structure of this class.

      Returns:
        the start index of the attribute_info structure of this class.

    - #### public java.lang.String getClassName()

      Returns the internal name of the class (see org.springframework.asm.Type#getInternalName()).

      Returns:
        the internal class name
      See Also:
        org.springframework.asm.ClassVisitor#visit(int, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

    - #### public java.lang.String[] getInterfaces()

      Returns the internal names of the class's interfaces (see org.springframework.asm.Type#getInternalName()).

      Returns:
        the array of internal names for all implemented interfaces or `null`.
      See Also:
        org.springframework.asm.ClassVisitor#visit(int, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

    - #### public java.lang.String getSuperName()

      Returns the internal of name of the super class (see org.springframework.asm.Type#getInternalName()). For interfaces, the super class is java.lang.Object.

      Returns:
        the internal name of super class, or `null` for java.lang.Object class.
      See Also:
        org.springframework.asm.ClassVisitor#visit(int, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

    - #### private int readAnnotationValue(int v, char[] buf, java.lang.String name, org.springframework.asm.AnnotationVisitor av)

      Reads a value of an annotation and makes the given visitor visit it.

      Parameters:
        `v` - the start offset in b of the value to be read (not including the value name constant pool index).
        `buf` - buffer to be used to call readUTF8, readClass or readConst.
        `name` - the name of the value to be read.
        `av` - the visitor that must visit the value.
      Returns:
        the end offset of the annotation value.

    - #### private int readAnnotationValues(int v, char[] buf, boolean named, org.springframework.asm.AnnotationVisitor av)

      Reads the values of an annotation and makes the given visitor visit them.

      Parameters:
        `v` - the start offset in b of the values to be read (including the unsigned short that gives the number of values).
        `buf` - buffer to be used to call readUTF8, readClass or readConst.
        `named` - if the annotation values are named or not.
        `av` - the visitor that must visit the values.
      Returns:
        the end offset of the annotation values.

    - #### private Attribute readAttribute(Attribute[] attrs, java.lang.String type, int off, int len, char[] buf, int codeOff, org.springframework.asm.Label[] labels)

      Reads an attribute in b.

      Parameters:
        `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 is ignored (i.e. an empty org.springframework.asm.Attribute instance is returned).
        `type` - the type of the attribute.
        `off` - index of the first byte of the attribute's content in b. The 6 attribute header bytes, containing the type and the length of the attribute, are not taken into account here (they have already been read).
        `len` - the length of the attribute's content.
        `buf` - buffer to be used to call readUTF8, readClass or readConst.
        `codeOff` - index of the first byte of code's attribute content in b, or -1 if the attribute to be read is not a code attribute. The 6 attribute header bytes, containing the type and the length of the attribute, are not taken into account here.
        `labels` - the labels of the method's code, or `null` if the attribute to be read is not a code attribute.
      Returns:
        the attribute that has been read, or `null` to skip this attribute.

    - #### public int readByte(int index)

      Reads a byte value in b. This method is intended for org.springframework.asm.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.

    - #### private static byte[] readClass(java.io.InputStream is, boolean close)

      Reads the bytecode of a class.

      throws:
        IOException if a problem occurs during reading.
      Parameters:
        `is` - an input stream from which to read the class.
        `close` - true to close the input stream after reading.
      Returns:
        the bytecode read from the given input stream.

    - #### public java.lang.String readClass(int index, char[] buf)

      Reads a class constant pool item in b. This method is intended for org.springframework.asm.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 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.
      Returns:
        the String corresponding to the specified class item.

    - #### public java.lang.Object readConst(int item, char[] buf)

      Reads a numeric or string constant pool item in b. This method is intended for org.springframework.asm.Attribute sub classes, and is normally not needed by class generators or adapters.

      Parameters:
        `item` - the index of a 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 java.lang.Integer, java.lang.Float, java.lang.Long, java.lang.Double, java.lang.String, org.springframework.asm.Type or org.springframework.asm.Handle corresponding to the given constant pool item.

    - #### public int readInt(int index)

      Reads a signed int value in b. This method is intended for org.springframework.asm.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.

    - #### protected org.springframework.asm.Label readLabel(int offset, org.springframework.asm.Label[] labels)

      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.

      Parameters:
        `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.
      Returns:
        a non null Label, which must be equal to labels[offset].

    - #### public long readLong(int index)

      Reads a signed long value in b. This method is intended for org.springframework.asm.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.

    - #### public short readShort(int index)

      Reads a signed short value in b. This method is intended for org.springframework.asm.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.

    - #### private java.lang.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.

    - #### public java.lang.String readUTF8(int index, char[] buf)

      Reads an UTF8 string constant pool item in b. This method is intended for org.springframework.asm.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.

    - #### public int readUnsignedShort(int index)

      Reads an unsigned short value in b. This method is intended for org.springframework.asm.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.