FileDocCategorySizeDatePackage
CPInstruction.javaAPI DocJava SE 5 API5677Fri Aug 26 14:55:18 BST 2005com.sun.org.apache.bcel.internal.generic

CPInstruction

public abstract class CPInstruction extends Instruction implements TypedInstruction, IndexedInstruction
Abstract super class for instructions that use an index into the constant pool such as LDC, INVOKEVIRTUAL, etc.
see
ConstantPoolGen
see
LDC
see
INVOKEVIRTUAL
version
$Id: CPInstruction.java,v 1.1.1.1 2001/10/29 20:00:07 jvanzyl Exp $
author
M. Dahm

Fields Summary
protected int
index
Constructors Summary
CPInstruction()
Empty constructor needed for the Class.newInstance() statement in Instruction.readInstruction(). Not to be used otherwise.

protected CPInstruction(short opcode, int index)

param
index to constant pool

    super(opcode, (short)3);
    setIndex(index);
  
Methods Summary
public voiddump(java.io.DataOutputStream out)
Dump instruction as byte code to stream out.

param
out Output stream

    out.writeByte(opcode);
    out.writeShort(index);
  
public final intgetIndex()

return
index in constant pool referred by this instruction.

 return index; 
public com.sun.org.apache.bcel.internal.generic.TypegetType(com.sun.org.apache.bcel.internal.generic.ConstantPoolGen cpg)

return
type related with this instruction.

    ConstantPool cp   = cpg.getConstantPool();
    String       name = cp.getConstantString(index, com.sun.org.apache.bcel.internal.Constants.CONSTANT_Class);

    if(!name.startsWith("["))
      name = "L" + name + ";";

    return Type.getType(name);
  
protected voidinitFromFile(com.sun.org.apache.bcel.internal.util.ByteSequence bytes, boolean wide)
Read needed data (i.e., index) from file.

param
bytes input stream
param
wide wide prefix?

    setIndex(bytes.readUnsignedShort());
    length = 3;
  
public voidsetIndex(int index)
Set the index to constant pool.

param
index in constant pool.

 
    if(index < 0)
      throw new ClassGenException("Negative index value: " + index);

    this.index = index;
  
public java.lang.StringtoString(boolean verbose)
Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"< constant pool index>">"

param
verbose long/short format switch
return
mnemonic for instruction

    return super.toString(verbose) + " " + index;
  
public java.lang.StringtoString(com.sun.org.apache.bcel.internal.classfile.ConstantPool cp)

return
mnemonic for instruction with symbolic references resolved

    Constant c   = cp.getConstant(index);
    String   str = cp.constantToString(c);

    if(c instanceof ConstantClass)
      str = str.replace('.", '/");

    return com.sun.org.apache.bcel.internal.Constants.OPCODE_NAMES[opcode] + " " + str;