Class LocalVariableInstruction

java.lang.Object
org.apache.bcel.generic.Instruction
org.apache.bcel.generic.LocalVariableInstruction
All Implemented Interfaces:
Cloneable, IndexedInstruction, TypedInstruction
Direct Known Subclasses:
IINC, LoadInstruction, StoreInstruction

Abstract superclass for instructions dealing with local variables.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    Deprecated.
    (since 6.0) will be made private; do not access directly, use getter/setter

    Fields inherited from class Instruction

    length, opcode
    Modifier and Type
    Field
    Description
    protected short
    Deprecated.
    (since 6.0) will be made private; do not access directly, use getter/setter
    protected short
    Deprecated.
    (since 6.0) will be made private; do not access directly, use getter/setter
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    LocalVariableInstruction(short opcode, short cTag, int n)
    Constructs a LocalVariableInstruction.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Dumps instruction as byte code to stream out.
    short
    Gets the canonical tag for instruction, for example, ALOAD for ALOAD_0.
    final int
    Gets the local variable index (n) referred to by this instruction.
    Gets the type associated with the instruction - in case of ALOAD or ASTORE Type.OBJECT is returned.
    protected void
    initFromFile(ByteSequence bytes, boolean wide)
    Reads needed data (for example index) from file.
    void
    setIndex(int index)
    Sets the local variable index. also updates opcode and length TODO Why?
    toString(boolean verbose)
    Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"< local variable index>">"

    Methods inherited from class Instruction

    accept, consumeStack, copy, equals, getComparator, getLength, getName, getOpcode, hashCode, isValidByte, isValidShort, produceStack, readInstruction, setComparator, toString, toString
    Modifier and Type
    Method
    Description
    abstract void
    Call corresponding visitor method(s).
    int
    This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.
    Use with caution, since 'BranchInstruction's have a 'target' reference which is not copied correctly (only basic types are).
    boolean
    equals(Object that)
    Tests for equality, delegated to comparator
    Deprecated.
    (6.0) use the built in comparator, or wrap this class in another object that implements these methods
    int
    Gets the length (in bytes) of instruction.
    Gets the name of instruction, that is, opcode name.
    short
    Gets this instruction's opcode.
    int
    Gets the hashCode of this object.
    static boolean
    isValidByte(int value)
    Tests if the value can fit in a byte (signed).
    static boolean
    isValidShort(int value)
    Tests if the value can fit in a short (signed).
    int
    This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.
    Reads an instruction from (byte code) input stream and return the appropriate object.
    static void
    Deprecated.
    (6.0) use the built in comparator, or wrap this class in another object that implements these methods
     
    Gets the mnemonic for instruction with symbolic references resolved.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • n

      @Deprecated protected int n
      Deprecated.
      (since 6.0) will be made private; do not access directly, use getter/setter
  • Constructor Details

    • LocalVariableInstruction

      protected LocalVariableInstruction(short opcode, short cTag, int n)
      Constructs a LocalVariableInstruction.
      Parameters:
      opcode - Instruction opcode.
      cTag - Instruction number for compact version, ALOAD_0, for example.
      n - local variable index (unsigned short).
  • Method Details

    • dump

      public void dump(DataOutputStream out) throws IOException
      Dumps instruction as byte code to stream out.
      Overrides:
      dump in class Instruction
      Parameters:
      out - Output stream.
      Throws:
      IOException - Thrown when an I/O exception of some sort has occurred.
    • getCanonicalTag

      public short getCanonicalTag()
      Gets the canonical tag for instruction, for example, ALOAD for ALOAD_0.
      Returns:
      canonical tag for instruction, for example, ALOAD for ALOAD_0.
    • getIndex

      public final int getIndex()
      Gets the local variable index (n) referred to by this instruction.
      Specified by:
      getIndex in interface IndexedInstruction
      Returns:
      local variable index (n) referred by this instruction.
    • getType

      Gets the type associated with the instruction - in case of ALOAD or ASTORE Type.OBJECT is returned. This is just a bit incorrect, because ALOAD and ASTORE may work on every ReferenceType (including Type.NULL) and ASTORE may even work on a ReturnaddressType.
      Specified by:
      getType in interface TypedInstruction
      Parameters:
      cp - The constant pool generator.
      Returns:
      type associated with the instruction.
    • initFromFile

      protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
      Reads needed data (for example index) from file.
      (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3)
      
      Overrides:
      initFromFile in class Instruction
      Parameters:
      bytes - byte sequence to read from.
      wide - "wide" instruction flag.
      Throws:
      IOException - Thrown if the implementation needs to read data from the file
    • setIndex

      public void setIndex(int index)
      Sets the local variable index. also updates opcode and length TODO Why?
      Specified by:
      setIndex in interface IndexedInstruction
      Parameters:
      index - local variable index (unsigned short).
      Throws:
      ClassGenException - Thrown if index is out of bounds.
      See Also:
      • setIndexOnly(int)
    • toString

      public String toString(boolean verbose)
      Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"< local variable index>">"
      Overrides:
      toString in class Instruction
      Parameters:
      verbose - long/short format switch.
      Returns:
      mnemonic for instruction.