Class ConstantPoolParser

  • All Implemented Interfaces:
    ClassConstants

    public final class ConstantPoolParser
    extends java.lang.Object
    implements ClassConstants
    A ConstantPoolParser provides read-only access to the constant pool of a class file.
    • Constructor Detail

      • ConstantPoolParser

        public ConstantPoolParser​(byte[] bytes,
                                  int offset,
                                  int itemCount)
                           throws InvalidClassFileException
        Parameters:
        bytes - the raw class file data
        offset - the start of the constant pool data
        itemCount - the number of items in the pool
        Throws:
        InvalidClassFileException
    • Method Detail

      • getRawBytes

        public byte[] getRawBytes()
        Returns:
        the buffer holding the raw class file data
      • getRawOffset

        public int getRawOffset()
                         throws java.lang.IllegalStateException
        Returns:
        the offset of the constant pool data in the raw class file buffer
        Throws:
        java.lang.IllegalStateException
      • getRawSize

        public int getRawSize()
                       throws java.lang.IllegalStateException
        Returns:
        the size of the constant pool data in the raw class file buffer
        Throws:
        java.lang.IllegalStateException
      • getItemCount

        public int getItemCount()
        Returns:
        the number of constant pool items (maximum item index plus one)
      • getItemType

        public byte getItemType​(int i)
                         throws java.lang.IllegalArgumentException
        Returns:
        the type of constant pool item i, or 0 if i is an unused constant pool item
        Throws:
        java.lang.IllegalArgumentException
      • getCPClass

        public java.lang.String getCPClass​(int i)
                                    throws InvalidClassFileException,
                                           java.lang.IllegalArgumentException
        Returns:
        the name of the Class at constant pool item i, in JVM format (e.g., java/lang/Object)
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPMethodType

        public java.lang.String getCPMethodType​(int i)
                                         throws InvalidClassFileException,
                                                java.lang.IllegalArgumentException
        Returns:
        the name of the method at constant pool item i, in JVM format (e.g., java/lang/Object)
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • isRef

        public static boolean isRef​(byte b)
        Does b represent the tag of a constant pool reference to an (interface) method or field?
      • getCPRefClass

        public java.lang.String getCPRefClass​(int i)
                                       throws InvalidClassFileException,
                                              java.lang.IllegalArgumentException
        Returns:
        the name of the class part of the FieldRef, MethodRef, or InterfaceMethodRef at constant pool item i
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPRefName

        public java.lang.String getCPRefName​(int i)
                                      throws InvalidClassFileException,
                                             java.lang.IllegalArgumentException
        Returns:
        the name part of the FieldRef, MethodRef, or InterfaceMethodRef at constant pool item i
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPRefType

        public java.lang.String getCPRefType​(int i)
                                      throws InvalidClassFileException,
                                             java.lang.IllegalArgumentException
        Returns:
        the type part of the FieldRef, MethodRef, or InterfaceMethodRef at constant pool item i, in JVM format (e.g., I, Z, or Ljava/lang/Object;)
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPNATName

        public java.lang.String getCPNATName​(int i)
                                      throws InvalidClassFileException,
                                             java.lang.IllegalArgumentException
        Returns:
        the name part of the NameAndType at constant pool item i
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPNATType

        public java.lang.String getCPNATType​(int i)
                                      throws InvalidClassFileException,
                                             java.lang.IllegalArgumentException
        Returns:
        the type part of the NameAndType at constant pool item i, in JVM format (e.g., I, Z, or Ljava/lang/Object;)
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPHandleName

        public java.lang.String getCPHandleName​(int i)
                                         throws InvalidClassFileException,
                                                java.lang.IllegalArgumentException
        Returns:
        the name part of the MethodHandle at constant pool item i, in JVM format (e.g., I, Z, or Ljava/lang/Object;)
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPHandleType

        public java.lang.String getCPHandleType​(int i)
                                         throws InvalidClassFileException,
                                                java.lang.IllegalArgumentException
        Returns:
        the name part of the MethodHandle at constant pool item i, in JVM format (e.g., I, Z, or Ljava/lang/Object;)
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPHandleClass

        public java.lang.String getCPHandleClass​(int i)
                                          throws InvalidClassFileException,
                                                 java.lang.IllegalArgumentException
        Returns:
        the name part of the MethodHandle at constant pool item i, in JVM format (e.g., I, Z, or Ljava/lang/Object;)
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPHandleKind

        public byte getCPHandleKind​(int i)
                             throws InvalidClassFileException,
                                    java.lang.IllegalArgumentException
        Returns:
        the type of the MethodHandle at constant pool item i
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException
      • getCPInt

        public int getCPInt​(int i)
                     throws java.lang.IllegalArgumentException
        Returns:
        the value of the Integer at constant pool item i
        Throws:
        java.lang.IllegalArgumentException
      • getCPFloat

        public float getCPFloat​(int i)
                         throws java.lang.IllegalArgumentException
        Returns:
        the value of the Float at constant pool item i
        Throws:
        java.lang.IllegalArgumentException
      • getCPLong

        public long getCPLong​(int i)
                       throws java.lang.IllegalArgumentException
        Returns:
        the value of the Long at constant pool item i
        Throws:
        java.lang.IllegalArgumentException
      • getCPDouble

        public double getCPDouble​(int i)
                           throws java.lang.IllegalArgumentException
        Returns:
        the value of the Double at constant pool item i
        Throws:
        java.lang.IllegalArgumentException
      • getCPUtf8

        public java.lang.String getCPUtf8​(int i)
                                   throws InvalidClassFileException,
                                          java.lang.IllegalArgumentException
        Returns:
        the value of the Utf8 string at constant pool item i
        Throws:
        InvalidClassFileException
        java.lang.IllegalArgumentException