Class ConstPool


  • public final class ConstPool
    extends java.lang.Object
    Constant pool table.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConstPool​(java.io.DataInputStream in)
      Constructs a constant pool table from the given byte stream.
      ConstPool​(java.lang.String thisclass)
      Constructs a constant pool table.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int addClassInfo​(java.lang.String qname)
      Adds a new CONSTANT_Class_info structure.
      int addClassInfo​(CtClass c)
      Adds a new CONSTANT_Class_info structure.
      int addDoubleInfo​(double d)
      Adds a new CONSTANT_Double_info structure.
      int addDynamicInfo​(int bootstrap, int nameAndType)
      Adds a new CONSTANT_Dynamic_info structure.
      int addFieldrefInfo​(int classInfo, int nameAndTypeInfo)
      Adds a new CONSTANT_Fieldref_info structure.
      int addFieldrefInfo​(int classInfo, java.lang.String name, java.lang.String type)
      Adds a new CONSTANT_Fieldref_info structure.
      int addFloatInfo​(float f)
      Adds a new CONSTANT_Float_info structure.
      int addIntegerInfo​(int i)
      Adds a new CONSTANT_Integer_info structure.
      int addInterfaceMethodrefInfo​(int classInfo, int nameAndTypeInfo)
      Adds a new CONSTANT_InterfaceMethodref_info structure.
      int addInterfaceMethodrefInfo​(int classInfo, java.lang.String name, java.lang.String type)
      Adds a new CONSTANT_InterfaceMethodref_info structure.
      int addInvokeDynamicInfo​(int bootstrap, int nameAndType)
      Adds a new CONSTANT_InvokeDynamic_info structure.
      int addLongInfo​(long l)
      Adds a new CONSTANT_Long_info structure.
      int addMethodHandleInfo​(int kind, int index)
      Adds a new CONSTANT_MethodHandle_info structure.
      int addMethodrefInfo​(int classInfo, int nameAndTypeInfo)
      Adds a new CONSTANT_Methodref_info structure.
      int addMethodrefInfo​(int classInfo, java.lang.String name, java.lang.String type)
      Adds a new CONSTANT_Methodref_info structure.
      int addMethodTypeInfo​(int desc)
      Adds a new CONSTANT_MethodType_info structure.
      int addModuleInfo​(int nameIndex)
      Adds a new CONSTANT_Module_info
      int addNameAndTypeInfo​(int name, int type)
      Adds a new CONSTANT_NameAndType_info structure.
      int addNameAndTypeInfo​(java.lang.String name, java.lang.String type)
      Adds a new CONSTANT_NameAndType_info structure.
      int addPackageInfo​(int nameIndex)
      Adds a new CONSTANT_Package_info
      int addStringInfo​(java.lang.String str)
      Adds a new CONSTANT_String_info structure.
      int addUtf8Info​(java.lang.String utf8)
      Adds a new CONSTANT_Utf8_info structure.
      int copy​(int n, ConstPool dest, java.util.Map<java.lang.String,​java.lang.String> classnames)
      Copies the n-th item in this ConstPool object into the destination ConstPool object.
      java.lang.String eqMember​(java.lang.String membername, java.lang.String desc, int index)
      Determines whether CONSTANT_Methodref_info, CONSTANT_Fieldref_info, or CONSTANT_InterfaceMethodref_info structure at the given index has the name and the descriptor given as the arguments.
      java.lang.String getClassInfo​(int index)
      Reads CONSTANT_Class_info structure at the given index.
      java.lang.String getClassInfoByDescriptor​(int index)
      Reads CONSTANT_Class_info structure at the given index.
      java.lang.String getClassName()
      Returns the name of the class using this constant pool table.
      java.util.Set<java.lang.String> getClassNames()
      Get all the class names.
      double getDoubleInfo​(int index)
      Reads CONSTANT_Double_info structure at the given index.
      int getDynamicBootstrap​(int index)
      Reads the bootstrap_method_attr_index field of the CONSTANT_Dynamic_info structure at the given index.
      int getDynamicNameAndType​(int index)
      Reads the name_and_type_index field of the CONSTANT_Dynamic_info structure at the given index.
      java.lang.String getDynamicType​(int index)
      Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
      int getFieldrefClass​(int index)
      Reads the class_index field of the CONSTANT_Fieldref_info structure at the given index.
      java.lang.String getFieldrefClassName​(int index)
      Reads the class_index field of the CONSTANT_Fieldref_info structure at the given index.
      java.lang.String getFieldrefName​(int index)
      Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
      int getFieldrefNameAndType​(int index)
      Reads the name_and_type_index field of the CONSTANT_Fieldref_info structure at the given index.
      java.lang.String getFieldrefType​(int index)
      Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
      float getFloatInfo​(int index)
      Reads CONSTANT_Float_info structure at the given index.
      int getIntegerInfo​(int index)
      Reads CONSTANT_Integer_info structure at the given index.
      int getInterfaceMethodrefClass​(int index)
      Reads the class_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.
      java.lang.String getInterfaceMethodrefClassName​(int index)
      Reads the class_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.
      java.lang.String getInterfaceMethodrefName​(int index)
      Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
      int getInterfaceMethodrefNameAndType​(int index)
      Reads the name_and_type_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.
      java.lang.String getInterfaceMethodrefType​(int index)
      Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
      int getInvokeDynamicBootstrap​(int index)
      Reads the bootstrap_method_attr_index field of the CONSTANT_InvokeDynamic_info structure at the given index.
      int getInvokeDynamicNameAndType​(int index)
      Reads the name_and_type_index field of the CONSTANT_InvokeDynamic_info structure at the given index.
      java.lang.String getInvokeDynamicType​(int index)
      Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
      java.lang.Object getLdcValue​(int index)
      Reads CONSTANT_Integer_info, _Float_info, _Long_info, _Double_info, or _String_info structure.
      long getLongInfo​(int index)
      Reads CONSTANT_Long_info structure at the given index.
      int getMemberClass​(int index)
      Reads the class_index field of the CONSTANT_Fieldref_info, CONSTANT_Methodref_info, or CONSTANT_Interfaceref_info, structure at the given index.
      int getMemberNameAndType​(int index)
      Reads the name_and_type_index field of the CONSTANT_Fieldref_info, CONSTANT_Methodref_info, or CONSTANT_Interfaceref_info, structure at the given index.
      int getMethodHandleIndex​(int index)
      Reads the reference_index field of the CONSTANT_MethodHandle_info structure at the given index.
      int getMethodHandleKind​(int index)
      Reads the reference_kind field of the CONSTANT_MethodHandle_info structure at the given index.
      int getMethodrefClass​(int index)
      Reads the class_index field of the CONSTANT_Methodref_info structure at the given index.
      java.lang.String getMethodrefClassName​(int index)
      Reads the class_index field of the CONSTANT_Methodref_info structure at the given index.
      java.lang.String getMethodrefName​(int index)
      Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
      int getMethodrefNameAndType​(int index)
      Reads the name_and_type_index field of the CONSTANT_Methodref_info structure at the given index.
      java.lang.String getMethodrefType​(int index)
      Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
      int getMethodTypeInfo​(int index)
      Reads the descriptor_index field of the CONSTANT_MethodType_info structure at the given index.
      java.lang.String getModuleInfo​(int index)
      Reads the name_index field of the CONSTANT_Module_info structure at the given index.
      int getNameAndTypeDescriptor​(int index)
      Reads the descriptor_index field of the CONSTANT_NameAndType_info structure at the given index.
      int getNameAndTypeName​(int index)
      Reads the name_index field of the CONSTANT_NameAndType_info structure at the given index.
      java.lang.String getPackageInfo​(int index)
      Reads the name_index field of the CONSTANT_Package_info structure at the given index.
      int getSize()
      Returns the number of entries in this table.
      java.lang.String getStringInfo​(int index)
      Reads CONSTANT_String_info structure at the given index.
      int getTag​(int index)
      Returns the tag field of the constant pool table entry at the given index.
      int getThisClassInfo()
      Returns the index of CONSTANT_Class_info structure specifying the class using this constant pool table.
      java.lang.String getUtf8Info​(int index)
      Reads CONSTANT_utf8_info structure at the given index.
      int isConstructor​(java.lang.String classname, int index)
      Determines whether CONSTANT_Methodref_info structure at the given index represents the constructor of the given class.
      int isMember​(java.lang.String classname, java.lang.String membername, int index)
      Determines whether CONSTANT_Methodref_info, CONSTANT_Fieldref_info, or CONSTANT_InterfaceMethodref_info structure at the given index represents the member with the specified name and declaring class.
      void print()
      Prints the contents of the constant pool table.
      void print​(java.io.PrintWriter out)
      Prints the contents of the constant pool table.
      void renameClass​(java.lang.String oldName, java.lang.String newName)
      Replaces all occurrences of a class name.
      void renameClass​(java.util.Map<java.lang.String,​java.lang.String> classnames)
      Replaces all occurrences of class names.
      void write​(java.io.DataOutputStream out)
      Writes the contents of the constant pool table.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CONST_Fieldref

        public static final int CONST_Fieldref
        CONSTANT_Fieldref
        See Also:
        Constant Field Values
      • CONST_Methodref

        public static final int CONST_Methodref
        CONSTANT_Methodref
        See Also:
        Constant Field Values
      • CONST_InterfaceMethodref

        public static final int CONST_InterfaceMethodref
        CONSTANT_InterfaceMethodref
        See Also:
        Constant Field Values
      • CONST_NameAndType

        public static final int CONST_NameAndType
        CONSTANT_NameAndType
        See Also:
        Constant Field Values
      • CONST_MethodHandle

        public static final int CONST_MethodHandle
        CONSTANT_MethodHandle
        See Also:
        Constant Field Values
      • CONST_MethodType

        public static final int CONST_MethodType
        CONSTANT_MethodHandle
        See Also:
        Constant Field Values
      • CONST_DynamicCallSite

        public static final int CONST_DynamicCallSite
        CONSTANT_DynamicCallSite, also known as CONSTANT_InvokeDynamic
        See Also:
        Constant Field Values
      • THIS

        public static final CtClass THIS
        Represents the class using this constant pool table.
      • REF_getField

        public static final int REF_getField
        reference_kind of CONSTANT_MethodHandle_info.
        See Also:
        Constant Field Values
      • REF_getStatic

        public static final int REF_getStatic
        reference_kind of CONSTANT_MethodHandle_info.
        See Also:
        Constant Field Values
      • REF_putField

        public static final int REF_putField
        reference_kind of CONSTANT_MethodHandle_info.
        See Also:
        Constant Field Values
      • REF_putStatic

        public static final int REF_putStatic
        reference_kind of CONSTANT_MethodHandle_info.
        See Also:
        Constant Field Values
      • REF_invokeVirtual

        public static final int REF_invokeVirtual
        reference_kind of CONSTANT_MethodHandle_info.
        See Also:
        Constant Field Values
      • REF_invokeStatic

        public static final int REF_invokeStatic
        reference_kind of CONSTANT_MethodHandle_info.
        See Also:
        Constant Field Values
      • REF_invokeSpecial

        public static final int REF_invokeSpecial
        reference_kind of CONSTANT_MethodHandle_info.
        See Also:
        Constant Field Values
      • REF_newInvokeSpecial

        public static final int REF_newInvokeSpecial
        reference_kind of CONSTANT_MethodHandle_info.
        See Also:
        Constant Field Values
      • REF_invokeInterface

        public static final int REF_invokeInterface
        reference_kind of CONSTANT_MethodHandle_info.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ConstPool

        public ConstPool​(java.lang.String thisclass)
        Constructs a constant pool table.
        Parameters:
        thisclass - the name of the class using this constant pool table
      • ConstPool

        public ConstPool​(java.io.DataInputStream in)
                  throws java.io.IOException
        Constructs a constant pool table from the given byte stream.
        Parameters:
        in - byte stream.
        Throws:
        java.io.IOException
    • Method Detail

      • getSize

        public int getSize()
        Returns the number of entries in this table.
      • getClassName

        public java.lang.String getClassName()
        Returns the name of the class using this constant pool table.
      • getThisClassInfo

        public int getThisClassInfo()
        Returns the index of CONSTANT_Class_info structure specifying the class using this constant pool table.
      • getTag

        public int getTag​(int index)
        Returns the tag field of the constant pool table entry at the given index.
        Returns:
        either CONST_Class, CONST_Fieldref, CONST_Methodref, or ...
      • getClassInfo

        public java.lang.String getClassInfo​(int index)
        Reads CONSTANT_Class_info structure at the given index.
        Returns:
        a fully-qualified class or interface name specified by name_index. If the type is an array type, this method returns an encoded name like [Ljava.lang.Object; (note that the separators are not slashes but dots).
        See Also:
        ClassPool.getCtClass(String)
      • getClassInfoByDescriptor

        public java.lang.String getClassInfoByDescriptor​(int index)
        Reads CONSTANT_Class_info structure at the given index.
        Returns:
        the descriptor of the type specified by name_index.
        Since:
        3.15
        See Also:
        ClassPool.getCtClass(String)
      • getNameAndTypeName

        public int getNameAndTypeName​(int index)
        Reads the name_index field of the CONSTANT_NameAndType_info structure at the given index.
      • getNameAndTypeDescriptor

        public int getNameAndTypeDescriptor​(int index)
        Reads the descriptor_index field of the CONSTANT_NameAndType_info structure at the given index.
      • getMemberClass

        public int getMemberClass​(int index)
        Reads the class_index field of the CONSTANT_Fieldref_info, CONSTANT_Methodref_info, or CONSTANT_Interfaceref_info, structure at the given index.
        Since:
        3.6
      • getMemberNameAndType

        public int getMemberNameAndType​(int index)
        Reads the name_and_type_index field of the CONSTANT_Fieldref_info, CONSTANT_Methodref_info, or CONSTANT_Interfaceref_info, structure at the given index.
        Since:
        3.6
      • getFieldrefClass

        public int getFieldrefClass​(int index)
        Reads the class_index field of the CONSTANT_Fieldref_info structure at the given index.
      • getFieldrefClassName

        public java.lang.String getFieldrefClassName​(int index)
        Reads the class_index field of the CONSTANT_Fieldref_info structure at the given index.
        Returns:
        the name of the class at that class_index.
      • getFieldrefNameAndType

        public int getFieldrefNameAndType​(int index)
        Reads the name_and_type_index field of the CONSTANT_Fieldref_info structure at the given index.
      • getFieldrefName

        public java.lang.String getFieldrefName​(int index)
        Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
        Parameters:
        index - an index to a CONSTANT_Fieldref_info.
        Returns:
        the name of the field.
      • getFieldrefType

        public java.lang.String getFieldrefType​(int index)
        Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
        Parameters:
        index - an index to a CONSTANT_Fieldref_info.
        Returns:
        the type descriptor of the field.
      • getMethodrefClass

        public int getMethodrefClass​(int index)
        Reads the class_index field of the CONSTANT_Methodref_info structure at the given index.
      • getMethodrefClassName

        public java.lang.String getMethodrefClassName​(int index)
        Reads the class_index field of the CONSTANT_Methodref_info structure at the given index.
        Returns:
        the name of the class at that class_index.
      • getMethodrefNameAndType

        public int getMethodrefNameAndType​(int index)
        Reads the name_and_type_index field of the CONSTANT_Methodref_info structure at the given index.
      • getMethodrefName

        public java.lang.String getMethodrefName​(int index)
        Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
        Parameters:
        index - an index to a CONSTANT_Methodref_info.
        Returns:
        the name of the method.
      • getMethodrefType

        public java.lang.String getMethodrefType​(int index)
        Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
        Parameters:
        index - an index to a CONSTANT_Methodref_info.
        Returns:
        the descriptor of the method.
      • getInterfaceMethodrefClass

        public int getInterfaceMethodrefClass​(int index)
        Reads the class_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.
      • getInterfaceMethodrefClassName

        public java.lang.String getInterfaceMethodrefClassName​(int index)
        Reads the class_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.
        Returns:
        the name of the class at that class_index.
      • getInterfaceMethodrefNameAndType

        public int getInterfaceMethodrefNameAndType​(int index)
        Reads the name_and_type_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.
      • getInterfaceMethodrefName

        public java.lang.String getInterfaceMethodrefName​(int index)
        Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
        Parameters:
        index - an index to a CONSTANT_InterfaceMethodref_info.
        Returns:
        the name of the method.
      • getInterfaceMethodrefType

        public java.lang.String getInterfaceMethodrefType​(int index)
        Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
        Parameters:
        index - an index to a CONSTANT_InterfaceMethodref_info.
        Returns:
        the descriptor of the method.
      • getLdcValue

        public java.lang.Object getLdcValue​(int index)
        Reads CONSTANT_Integer_info, _Float_info, _Long_info, _Double_info, or _String_info structure. These are used with the LDC instruction.
        Returns:
        a String value or a wrapped primitive-type value.
      • getIntegerInfo

        public int getIntegerInfo​(int index)
        Reads CONSTANT_Integer_info structure at the given index.
        Returns:
        the value specified by this entry.
      • getFloatInfo

        public float getFloatInfo​(int index)
        Reads CONSTANT_Float_info structure at the given index.
        Returns:
        the value specified by this entry.
      • getLongInfo

        public long getLongInfo​(int index)
        Reads CONSTANT_Long_info structure at the given index.
        Returns:
        the value specified by this entry.
      • getDoubleInfo

        public double getDoubleInfo​(int index)
        Reads CONSTANT_Double_info structure at the given index.
        Returns:
        the value specified by this entry.
      • getStringInfo

        public java.lang.String getStringInfo​(int index)
        Reads CONSTANT_String_info structure at the given index.
        Returns:
        the string specified by string_index.
      • getUtf8Info

        public java.lang.String getUtf8Info​(int index)
        Reads CONSTANT_utf8_info structure at the given index.
        Returns:
        the string specified by this entry.
      • getMethodHandleIndex

        public int getMethodHandleIndex​(int index)
        Reads the reference_index field of the CONSTANT_MethodHandle_info structure at the given index.
        Since:
        3.17
      • getMethodTypeInfo

        public int getMethodTypeInfo​(int index)
        Reads the descriptor_index field of the CONSTANT_MethodType_info structure at the given index.
        Since:
        3.17
      • getInvokeDynamicBootstrap

        public int getInvokeDynamicBootstrap​(int index)
        Reads the bootstrap_method_attr_index field of the CONSTANT_InvokeDynamic_info structure at the given index.
        Since:
        3.17
      • getInvokeDynamicNameAndType

        public int getInvokeDynamicNameAndType​(int index)
        Reads the name_and_type_index field of the CONSTANT_InvokeDynamic_info structure at the given index.
        Since:
        3.17
      • getInvokeDynamicType

        public java.lang.String getInvokeDynamicType​(int index)
        Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
        Parameters:
        index - an index to a CONSTANT_InvokeDynamic_info.
        Returns:
        the descriptor of the bootstrap method.
        Since:
        3.17
      • getDynamicBootstrap

        public int getDynamicBootstrap​(int index)
        Reads the bootstrap_method_attr_index field of the CONSTANT_Dynamic_info structure at the given index.
        Since:
        3.26
      • getDynamicNameAndType

        public int getDynamicNameAndType​(int index)
        Reads the name_and_type_index field of the CONSTANT_Dynamic_info structure at the given index.
        Since:
        3.26
      • getDynamicType

        public java.lang.String getDynamicType​(int index)
        Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
        Parameters:
        index - an index to a CONSTANT_Dynamic_info.
        Returns:
        the descriptor of the bootstrap method.
        Since:
        3.26
      • getModuleInfo

        public java.lang.String getModuleInfo​(int index)
        Reads the name_index field of the CONSTANT_Module_info structure at the given index.
        Returns:
        the module name at name_index.
        Since:
        3.22
      • getPackageInfo

        public java.lang.String getPackageInfo​(int index)
        Reads the name_index field of the CONSTANT_Package_info structure at the given index.
        Returns:
        the package name at name_index. It is a slash- separated name such as com/oracle/net.
        Since:
        3.22
      • isConstructor

        public int isConstructor​(java.lang.String classname,
                                 int index)
        Determines whether CONSTANT_Methodref_info structure at the given index represents the constructor of the given class.
        Returns:
        the descriptor_index specifying the type descriptor of the that constructor. If it is not that constructor, isConstructor() returns 0.
      • isMember

        public int isMember​(java.lang.String classname,
                            java.lang.String membername,
                            int index)
        Determines whether CONSTANT_Methodref_info, CONSTANT_Fieldref_info, or CONSTANT_InterfaceMethodref_info structure at the given index represents the member with the specified name and declaring class.
        Parameters:
        classname - the class declaring the member
        membername - the member name
        index - the index into the constant pool table
        Returns:
        the descriptor_index specifying the type descriptor of that member. If it is not that member, isMember() returns 0.
      • eqMember

        public java.lang.String eqMember​(java.lang.String membername,
                                         java.lang.String desc,
                                         int index)
        Determines whether CONSTANT_Methodref_info, CONSTANT_Fieldref_info, or CONSTANT_InterfaceMethodref_info structure at the given index has the name and the descriptor given as the arguments.
        Parameters:
        membername - the member name
        desc - the descriptor of the member.
        index - the index into the constant pool table
        Returns:
        the name of the target class specified by the ..._info structure at index. Otherwise, null if that structure does not match the given member name and descriptor.
      • copy

        public int copy​(int n,
                        ConstPool dest,
                        java.util.Map<java.lang.String,​java.lang.String> classnames)
        Copies the n-th item in this ConstPool object into the destination ConstPool object. The class names that the item refers to are renamed according to the given map.
        Parameters:
        n - the n-th item
        dest - destination constant pool table
        classnames - the map or null.
        Returns:
        the index of the copied item into the destination ClassPool.
      • addClassInfo

        public int addClassInfo​(CtClass c)
        Adds a new CONSTANT_Class_info structure.

        This also adds a CONSTANT_Utf8_info structure for storing the class name.

        Returns:
        the index of the added entry.
      • addClassInfo

        public int addClassInfo​(java.lang.String qname)
        Adds a new CONSTANT_Class_info structure.

        This also adds a CONSTANT_Utf8_info structure for storing the class name.

        Parameters:
        qname - a fully-qualified class name (or the JVM-internal representation of that name).
        Returns:
        the index of the added entry.
      • addNameAndTypeInfo

        public int addNameAndTypeInfo​(java.lang.String name,
                                      java.lang.String type)
        Adds a new CONSTANT_NameAndType_info structure.

        This also adds CONSTANT_Utf8_info structures.

        Parameters:
        name - name_index
        type - descriptor_index
        Returns:
        the index of the added entry.
      • addNameAndTypeInfo

        public int addNameAndTypeInfo​(int name,
                                      int type)
        Adds a new CONSTANT_NameAndType_info structure.
        Parameters:
        name - name_index
        type - descriptor_index
        Returns:
        the index of the added entry.
      • addFieldrefInfo

        public int addFieldrefInfo​(int classInfo,
                                   java.lang.String name,
                                   java.lang.String type)
        Adds a new CONSTANT_Fieldref_info structure.

        This also adds a new CONSTANT_NameAndType_info structure.

        Parameters:
        classInfo - class_index
        name - name_index of CONSTANT_NameAndType_info.
        type - descriptor_index of CONSTANT_NameAndType_info.
        Returns:
        the index of the added entry.
      • addFieldrefInfo

        public int addFieldrefInfo​(int classInfo,
                                   int nameAndTypeInfo)
        Adds a new CONSTANT_Fieldref_info structure.
        Parameters:
        classInfo - class_index
        nameAndTypeInfo - name_and_type_index.
        Returns:
        the index of the added entry.
      • addMethodrefInfo

        public int addMethodrefInfo​(int classInfo,
                                    java.lang.String name,
                                    java.lang.String type)
        Adds a new CONSTANT_Methodref_info structure.

        This also adds a new CONSTANT_NameAndType_info structure.

        Parameters:
        classInfo - class_index
        name - name_index of CONSTANT_NameAndType_info.
        type - descriptor_index of CONSTANT_NameAndType_info.
        Returns:
        the index of the added entry.
      • addMethodrefInfo

        public int addMethodrefInfo​(int classInfo,
                                    int nameAndTypeInfo)
        Adds a new CONSTANT_Methodref_info structure.
        Parameters:
        classInfo - class_index
        nameAndTypeInfo - name_and_type_index.
        Returns:
        the index of the added entry.
      • addInterfaceMethodrefInfo

        public int addInterfaceMethodrefInfo​(int classInfo,
                                             java.lang.String name,
                                             java.lang.String type)
        Adds a new CONSTANT_InterfaceMethodref_info structure.

        This also adds a new CONSTANT_NameAndType_info structure.

        Parameters:
        classInfo - class_index
        name - name_index of CONSTANT_NameAndType_info.
        type - descriptor_index of CONSTANT_NameAndType_info.
        Returns:
        the index of the added entry.
      • addInterfaceMethodrefInfo

        public int addInterfaceMethodrefInfo​(int classInfo,
                                             int nameAndTypeInfo)
        Adds a new CONSTANT_InterfaceMethodref_info structure.
        Parameters:
        classInfo - class_index
        nameAndTypeInfo - name_and_type_index.
        Returns:
        the index of the added entry.
      • addStringInfo

        public int addStringInfo​(java.lang.String str)
        Adds a new CONSTANT_String_info structure.

        This also adds a new CONSTANT_Utf8_info structure.

        Returns:
        the index of the added entry.
      • addIntegerInfo

        public int addIntegerInfo​(int i)
        Adds a new CONSTANT_Integer_info structure.
        Returns:
        the index of the added entry.
      • addFloatInfo

        public int addFloatInfo​(float f)
        Adds a new CONSTANT_Float_info structure.
        Returns:
        the index of the added entry.
      • addLongInfo

        public int addLongInfo​(long l)
        Adds a new CONSTANT_Long_info structure.
        Returns:
        the index of the added entry.
      • addDoubleInfo

        public int addDoubleInfo​(double d)
        Adds a new CONSTANT_Double_info structure.
        Returns:
        the index of the added entry.
      • addUtf8Info

        public int addUtf8Info​(java.lang.String utf8)
        Adds a new CONSTANT_Utf8_info structure.
        Returns:
        the index of the added entry.
      • addMethodHandleInfo

        public int addMethodHandleInfo​(int kind,
                                       int index)
        Adds a new CONSTANT_MethodHandle_info structure.
        Parameters:
        kind - reference_kind such as REF_invokeStatic.
        index - reference_index.
        Returns:
        the index of the added entry.
        Since:
        3.17
      • addMethodTypeInfo

        public int addMethodTypeInfo​(int desc)
        Adds a new CONSTANT_MethodType_info structure.
        Parameters:
        desc - descriptor_index.
        Returns:
        the index of the added entry.
        Since:
        3.17
      • addInvokeDynamicInfo

        public int addInvokeDynamicInfo​(int bootstrap,
                                        int nameAndType)
        Adds a new CONSTANT_InvokeDynamic_info structure.
        Parameters:
        bootstrap - bootstrap_method_attr_index.
        nameAndType - name_and_type_index.
        Returns:
        the index of the added entry.
        Since:
        3.17
      • addDynamicInfo

        public int addDynamicInfo​(int bootstrap,
                                  int nameAndType)
        Adds a new CONSTANT_Dynamic_info structure.
        Parameters:
        bootstrap - bootstrap_method_attr_index.
        nameAndType - name_and_type_index.
        Returns:
        the index of the added entry.
        Since:
        3.26
      • addModuleInfo

        public int addModuleInfo​(int nameIndex)
        Adds a new CONSTANT_Module_info
        Parameters:
        nameIndex - the index of the Utf8 entry.
        Returns:
        the index of the added entry.
        Since:
        3.22
      • addPackageInfo

        public int addPackageInfo​(int nameIndex)
        Adds a new CONSTANT_Package_info
        Parameters:
        nameIndex - the index of the Utf8 entry.
        Returns:
        the index of the added entry.
        Since:
        3.22
      • getClassNames

        public java.util.Set<java.lang.String> getClassNames()
        Get all the class names.
        Returns:
        a set of class names (String objects).
      • renameClass

        public void renameClass​(java.lang.String oldName,
                                java.lang.String newName)
        Replaces all occurrences of a class name.
        Parameters:
        oldName - the replaced name (JVM-internal representation).
        newName - the substituted name (JVM-internal representation).
      • renameClass

        public void renameClass​(java.util.Map<java.lang.String,​java.lang.String> classnames)
        Replaces all occurrences of class names.
        Parameters:
        classnames - specifies pairs of replaced and substituted name.
      • write

        public void write​(java.io.DataOutputStream out)
                   throws java.io.IOException
        Writes the contents of the constant pool table.
        Throws:
        java.io.IOException
      • print

        public void print()
        Prints the contents of the constant pool table.
      • print

        public void print​(java.io.PrintWriter out)
        Prints the contents of the constant pool table.