FileDocCategorySizeDatePackage
CstInsn.javaAPI DocAndroid 1.5 API5798Wed May 06 22:41:02 BST 2009com.android.dx.dex.code

CstInsn

public final class CstInsn extends FixedSizeInsn
Instruction which has a single constant argument in addition to all the normal instruction information.

Fields Summary
private final com.android.dx.rop.cst.Constant
constant
non-null; the constant argument for this instruction
private int
index
>= -1; the constant pool index for {@link #constant}, or -1 if not yet set
private int
classIndex
>= -1; the constant pool index for the class reference in {@link #constant} if any, or -1 if not yet set
Constructors Summary
public CstInsn(Dop opcode, com.android.dx.rop.code.SourcePosition position, com.android.dx.rop.code.RegisterSpecList registers, com.android.dx.rop.cst.Constant constant)
Constructs an instance. The output address of this instance is initially unknown (-1) as is the constant pool index.

param
opcode the opcode; one of the constants from {@link Dops}
param
position non-null; source position
param
registers non-null; register list, including a result register if appropriate (that is, registers may be either ins or outs)
param
constant non-null; constant argument

        super(opcode, position, registers);

        if (constant == null) {
            throw new NullPointerException("constant == null");
        }

        this.constant = constant;
        this.index = -1;
        this.classIndex = -1;
    
Methods Summary
protected java.lang.StringargString()
{@inheritDoc}

        return constant.toHuman();
    
public intgetClassIndex()
Gets the constant's class index. It is only valid to call this after {@link #setClassIndex} has been called.

return
>= 0; the constant's class's constant pool index

        if (classIndex < 0) {
            throw new RuntimeException("class index not yet set");
        }

        return classIndex;
    
public com.android.dx.rop.cst.ConstantgetConstant()
Gets the constant argument.

return
non-null; the constant argument

        return constant;
    
public intgetIndex()
Gets the constant's index. It is only valid to call this after {@link #setIndex} has been called.

return
>= 0; the constant pool index

        if (index < 0) {
            throw new RuntimeException("index not yet set for " + constant);
        }

        return index;
    
public booleanhasClassIndex()
Returns whether the constant's class index has been set for this instance.

see
#setClassIndex
return
true iff the index has been set

        return (classIndex >= 0);
    
public booleanhasIndex()
Returns whether the constant's index has been set for this instance.

see
#setIndex
return
true iff the index has been set

        return (index >= 0);
    
public voidsetClassIndex(int index)
Sets the constant's class index. This is the constant pool index for the class referred to by this instance's constant. Only reference constants have a class, so it is only on instances with reference constants that this method should ever be called. It is only valid to call this method once per instance.

param
index >= 0; the constant's class's constant pool index

        if (index < 0) {
            throw new IllegalArgumentException("index < 0");
        }

        if (this.classIndex >= 0) {
            throw new RuntimeException("class index already set");
        }

        this.classIndex = index;
    
public voidsetIndex(int index)
Sets the constant's index. It is only valid to call this method once per instance.

param
index >= 0; the constant pool index

        if (index < 0) {
            throw new IllegalArgumentException("index < 0");
        }

        if (this.index >= 0) {
            throw new RuntimeException("index already set");
        }

        this.index = index;
    
public DalvInsnwithOpcode(Dop opcode)
{@inheritDoc}

        CstInsn result = 
            new CstInsn(opcode, getPosition(), getRegisters(), constant);

        if (index >= 0) {
            result.setIndex(index);
        }
        
        if (classIndex >= 0) {
            result.setClassIndex(classIndex);
        }

        return result;
    
public DalvInsnwithRegisters(com.android.dx.rop.code.RegisterSpecList registers)
{@inheritDoc}

        CstInsn result =
            new CstInsn(getOpcode(), getPosition(), registers, constant);

        if (index >= 0) {
            result.setIndex(index);
        }
        
        if (classIndex >= 0) {
            result.setClassIndex(classIndex);
        }

        return result;