Class ConstantPool
java.lang.Object
EDU.purdue.cs.bloat.editor.ConstantPool
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddConstant(int tag, Object value) Add a constant to the constant pool.constantAt(int idx) Obtain the resolved value of a constant at given index in the constant pool.intconstantIndex(int tag, Object value) Get the index of the constant with the given tag and value.Constant[]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.intReturns the index of the constant pool entry for the given classReturns an unmodifiable List of constants in this constant pool.intReturns the index of the constant pool entry for the given doubleintReturns the index of the constant pool entry for the given floatintReturns the index of the constant pool entry for the given integerintgetLongIndex(Long l) Returns the index of the constant pool entry for the given longintReturns the index of the constant pool entry for the givenMemberRefintReturns the index of the constant pool entry for the givenNameAndTypeintReturns the index of the constant pool entry for the given StringintgetTypeIndex(Type type) Returns the index of the constant pool entry for the givenTypeintReturns the index of the constant pool entry for the given UTF8 stringint
-
Constructor Details
-
ConstantPool
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 Details
-
constantAt
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
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
Returns the index of the constant pool entry for the given class -
getIntegerIndex
Returns the index of the constant pool entry for the given integer -
getFloatIndex
Returns the index of the constant pool entry for the given float -
getLongIndex
Returns the index of the constant pool entry for the given long -
getDoubleIndex
Returns the index of the constant pool entry for the given double -
getClassIndex
Returns the index of the constant pool entry for the given class. -
getTypeIndex
Returns the index of the constant pool entry for the givenType -
getStringIndex
Returns the index of the constant pool entry for the given String -
getMemberRefIndex
Returns the index of the constant pool entry for the givenMemberRef -
getNameAndTypeIndex
Returns the index of the constant pool entry for the givenNameAndType -
getUTF8Index
Returns the index of the constant pool entry for the given UTF8 string -
addConstant
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
Get an array of the constants in the pool.- Returns:
- An array of the constants in the pool.
-
getConstantsList
Returns an unmodifiable List of constants in this constant pool.
-