Class StdConstantPool

java.lang.Object
com.android.dx.util.MutabilityControl
com.android.dx.rop.cst.StdConstantPool
All Implemented Interfaces:
ConstantPool

public final class StdConstantPool extends MutabilityControl implements ConstantPool
Standard implementation of ConstantPool, which directly stores an array of Constant objects and can be made immutable.
  • Constructor Details

    • StdConstantPool

      public StdConstantPool(int size)
      Constructs an instance. All indices initially contain null.
      Parameters:
      size - the size of the pool; this corresponds to the class file field constant_pool_count, and is in fact always at least one more than the actual size of the constant pool, as element 0 is always invalid.
  • Method Details

    • size

      public int size()
      Get the "size" of the constant pool. This corresponds to the class file field constant_pool_count, and is in fact always at least one more than the actual size of the constant pool, as element 0 is always invalid.
      Specified by:
      size in interface ConstantPool
      Returns:
      >= 1; the size
    • getOrNull

      public Constant getOrNull(int n)
      Get the nth entry in the constant pool, or null if the index is in-range but invalid. In particular, null is returned for index 0 as well as the index after any entry which is defined to take up two slots (that is, Long and Double entries).
      Specified by:
      getOrNull in interface ConstantPool
      Parameters:
      n - n >= 0, n < size(); the constant pool index
      Returns:
      null-ok; the corresponding entry, or null if the index is in-range but invalid
    • get0Ok

      public Constant get0Ok(int n)
      Get the nth entry in the constant pool, which must be valid unless n == 0, in which case null is returned.
      Specified by:
      get0Ok in interface ConstantPool
      Parameters:
      n - n >= 0, n < size(); the constant pool index
      Returns:
      null-ok; the corresponding entry, if n != 0
    • get

      public Constant get(int n)
      Get the nth entry in the constant pool, which must be valid.
      Specified by:
      get in interface ConstantPool
      Parameters:
      n - n >= 0, n < size(); the constant pool index
      Returns:
      non-null; the corresponding entry
    • getEntries

      public Constant[] getEntries()
      Get all entries in this constant pool.
      Specified by:
      getEntries in interface ConstantPool
      Returns:
      the returned array may contain null entries.
    • set

      public void set(int n, Constant cst)
      Sets the entry at the given index.
      Parameters:
      n - >= 1, < size(); which entry
      cst - null-ok; the constant to store