Package EDU.purdue.cs.bloat.editor
Class ConstantPool
- java.lang.Object
-
- EDU.purdue.cs.bloat.editor.ConstantPool
-
public class ConstantPool extends java.lang.ObjectConstantPool 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
-
-
Constructor Summary
Constructors Constructor Description ConstantPool()Creates a new, emptyConstantPoolConstantPool(Constant[] c)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddConstant(int tag, java.lang.Object value)Add a constant to the constant pool.java.lang.ObjectconstantAt(int idx)Obtain the resolved value of a constant at given index in the constant pool.intconstantIndex(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.intconstantTag(int index)Get the tag of a constant.intgetClassIndex(Type type)Returns the index of the constant pool entry for the given class.intgetClassIndex(java.lang.Class c)Returns the index of the constant pool entry for the given classjava.util.ListgetConstantsList()Returns an unmodifiable List of constants in this constant pool.intgetDoubleIndex(java.lang.Double d)Returns the index of the constant pool entry for the given doubleintgetFloatIndex(java.lang.Float f)Returns the index of the constant pool entry for the given floatintgetIntegerIndex(java.lang.Integer i)Returns the index of the constant pool entry for the given integerintgetLongIndex(java.lang.Long l)Returns the index of the constant pool entry for the given longintgetMemberRefIndex(MemberRef ref)Returns the index of the constant pool entry for the givenMemberRefintgetNameAndTypeIndex(NameAndType nat)Returns the index of the constant pool entry for the givenNameAndTypeintgetStringIndex(java.lang.String s)Returns the index of the constant pool entry for the given StringintgetTypeIndex(Type type)Returns the index of the constant pool entry for the givenTypeintgetUTF8Index(java.lang.String s)Returns the index of the constant pool entry for the given UTF8 stringintnumConstants()
-
-
-
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, emptyConstantPool
-
-
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 givenType
-
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 givenMemberRef
-
getNameAndTypeIndex
public int getNameAndTypeIndex(NameAndType nat)
Returns the index of the constant pool entry for the givenNameAndType
-
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.
-
-