FileDocCategorySizeDatePackage
CstInsn.javaAPI DocAndroid 5.1 API5830Thu Mar 12 22:18:28 GMT 2015com.android.dexgen.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.dexgen.rop.cst.Constant
constant
{@code non-null;} the constant argument for this instruction
private int
index
{@code >= -1;} the constant pool index for {@link #constant}, or {@code -1} if not yet set
private int
classIndex
{@code >= -1;} the constant pool index for the class reference in {@link #constant} if any, or {@code -1} if not yet set
Constructors Summary
public CstInsn(Dop opcode, com.android.dexgen.rop.code.SourcePosition position, com.android.dexgen.rop.code.RegisterSpecList registers, com.android.dexgen.rop.cst.Constant constant)
Constructs an instance. The output address of this instance is initially unknown ({@code -1}) as is the constant pool index.

param
opcode the opcode; one of the constants from {@link Dops}
param
position {@code non-null;} source position
param
registers {@code non-null;} register list, including a result register if appropriate (that is, registers may be either ins or outs)
param
constant {@code 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
{@code >= 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.dexgen.rop.cst.ConstantgetConstant()
Gets the constant argument.

return
{@code 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
{@code >= 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
{@code 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
{@code 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 {@code >= 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 {@code >= 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.dexgen.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;