Class ConstantPool

java.lang.Object
EDU.purdue.cs.bloat.editor.ConstantPool

public class ConstantPool extends 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:
  • Constructor Details

    • 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 Details

    • constantAt

      public 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, 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(Class c)
      Returns the index of the constant pool entry for the given class
    • getIntegerIndex

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

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

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

      public int getDoubleIndex(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(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(String s)
      Returns the index of the constant pool entry for the given UTF8 string
    • addConstant

      public int addConstant(int tag, 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 List getConstantsList()
      Returns an unmodifiable List of constants in this constant pool.