com.android.dx.rop.cst
Class StdConstantPool

java.lang.Object
  extended by com.android.dx.util.MutabilityControl
      extended by 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 Summary
StdConstantPool(int size)
          Constructs an instance.
 
Method Summary
 Constant get(int n)
          Get the nth entry in the constant pool, which must be valid.
 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.
 Constant getOrNull(int n)
          Get the nth entry in the constant pool, or null if the index is in-range but invalid.
 void set(int n, Constant cst)
          Sets the entry at the given index.
 int size()
          Get the "size" of the constant pool.
 
Methods inherited from class com.android.dx.util.MutabilityControl
isImmutable, isMutable, setImmutable, throwIfImmutable, throwIfMutable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

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

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


Copyright © 2013. All Rights Reserved.