Class ConstantPool


  • public class ConstantPool
    extends java.lang.Object
    ConstantPool models constants in the constant pool. Recall that the reflection mechanism represents constants as a tag and a value. ConstantPool consists of an array of reflect.Constants that are resolved into their appropriate value (e.g. Type, NameAndType, MemberRef, etc.) as they are needed.
    See Also:
    Constant
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int addConstant​(int tag, java.lang.Object value)
      Add a constant to the constant pool.
      java.lang.Object constantAt​(int idx)
      Obtain the resolved value of a constant at given index in the constant pool.
      int constantIndex​(int tag, java.lang.Object value)
      Get the index of the constant with the given tag and value.
      Constant[] constants()
      Get an array of the constants in the pool.
      int constantTag​(int index)
      Get the tag of a constant.
      int getClassIndex​(Type type)
      Returns the index of the constant pool entry for the given class.
      int getClassIndex​(java.lang.Class c)
      Returns the index of the constant pool entry for the given class
      java.util.List getConstantsList()
      Returns an unmodifiable List of constants in this constant pool.
      int getDoubleIndex​(java.lang.Double d)
      Returns the index of the constant pool entry for the given double
      int getFloatIndex​(java.lang.Float f)
      Returns the index of the constant pool entry for the given float
      int getIntegerIndex​(java.lang.Integer i)
      Returns the index of the constant pool entry for the given integer
      int getLongIndex​(java.lang.Long l)
      Returns the index of the constant pool entry for the given long
      int getMemberRefIndex​(MemberRef ref)
      Returns the index of the constant pool entry for the given MemberRef
      int getNameAndTypeIndex​(NameAndType nat)
      Returns the index of the constant pool entry for the given NameAndType
      int getStringIndex​(java.lang.String s)
      Returns the index of the constant pool entry for the given String
      int getTypeIndex​(Type type)
      Returns the index of the constant pool entry for the given Type
      int getUTF8Index​(java.lang.String s)
      Returns the index of the constant pool entry for the given UTF8 string
      int numConstants()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConstantPool

        public ConstantPool​(Constant[] c)
        Constructor. Resolve the constants in the constant pool, converting from the index-based representation of the class file to a more amenable external representation.
        Parameters:
        c - An array of Constant.
      • ConstantPool

        public ConstantPool()
        Creates a new, empty ConstantPool
    • Method Detail

      • constantAt

        public java.lang.Object constantAt​(int idx)
        Obtain the resolved value of a constant at given index in the constant pool.
        Parameters:
        idx - Index into the constant pool.
        Returns:
        The value of the constant at index.
      • numConstants

        public int numConstants()
      • constantTag

        public int constantTag​(int index)
        Get the tag of a constant.
        Parameters:
        index - Index into the constant pool.
        Returns:
        The tag of the constant at index, or Constant.UTF8.
      • constantIndex

        public int constantIndex​(int tag,
                                 java.lang.Object value)
        Get the index of the constant with the given tag and value.
        Parameters:
        tag - The constant's tag (for example, Constant.UTF8).
        value - The constant's value (for example, a String).
        Returns:
        The index of the constant.
      • getClassIndex

        public int getClassIndex​(java.lang.Class c)
        Returns the index of the constant pool entry for the given class
      • getIntegerIndex

        public int getIntegerIndex​(java.lang.Integer i)
        Returns the index of the constant pool entry for the given integer
      • getFloatIndex

        public int getFloatIndex​(java.lang.Float f)
        Returns the index of the constant pool entry for the given float
      • getLongIndex

        public int getLongIndex​(java.lang.Long l)
        Returns the index of the constant pool entry for the given long
      • getDoubleIndex

        public int getDoubleIndex​(java.lang.Double d)
        Returns the index of the constant pool entry for the given double
      • getClassIndex

        public int getClassIndex​(Type type)
        Returns the index of the constant pool entry for the given class.
      • getTypeIndex

        public int getTypeIndex​(Type type)
        Returns the index of the constant pool entry for the given Type
      • getStringIndex

        public int getStringIndex​(java.lang.String s)
        Returns the index of the constant pool entry for the given String
      • getMemberRefIndex

        public int getMemberRefIndex​(MemberRef ref)
        Returns the index of the constant pool entry for the given MemberRef
      • getNameAndTypeIndex

        public int getNameAndTypeIndex​(NameAndType nat)
        Returns the index of the constant pool entry for the given NameAndType
      • getUTF8Index

        public int getUTF8Index​(java.lang.String s)
        Returns the index of the constant pool entry for the given UTF8 string
      • addConstant

        public int addConstant​(int tag,
                               java.lang.Object value)
        Add a constant to the constant pool. Will not add the same constant twice.
        Parameters:
        tag - The constant's tag (for example, Constant.UTF8).
        value - The constant's value (for example, a String).
        Returns:
        The index of the constant.
      • constants

        public Constant[] constants()
        Get an array of the constants in the pool.
        Returns:
        An array of the constants in the pool.
      • getConstantsList

        public java.util.List getConstantsList()
        Returns an unmodifiable List of constants in this constant pool.