Class LocalVariable

java.lang.Object
org.apache.bcel.classfile.LocalVariable
All Implemented Interfaces:
Cloneable, Node, Constants

public final class LocalVariable extends Object implements Cloneable, Node, Constants
This class represents a local variable within a method. It contains its scope, name, signature and index on the method's frame. It is used both to represent an element of the LocalVariableTable as well as an element of the LocalVariableTypeTable. The nomenclature used here may be a bit confusing; while the two items have the same layout in a class file, a LocalVariableTable attribute contains a descriptor_index, not a signature_index. The LocalVariableTypeTable attribute does have a signature_index.
See Also:
  • Field Details

    • start_pc

      private int start_pc
    • length

      private int length
    • name_index

      private int name_index
    • signature_index

      private int signature_index
    • index

      private int index
    • constant_pool

      private ConstantPool constant_pool
    • orig_index

      private int orig_index
  • Constructor Details

    • LocalVariable

      public LocalVariable(LocalVariable localVariable)
      Initializes from another LocalVariable. Note that both objects use the same references (shallow copy). Use copy() for a physical copy.
      Parameters:
      localVariable - Another LocalVariable.
    • LocalVariable

      LocalVariable(DataInput file, ConstantPool constant_pool) throws IOException
      Constructs object from file stream.
      Parameters:
      file - Input stream
      Throws:
      IOException
    • LocalVariable

      public LocalVariable(int start_pc, int length, int name_index, int signature_index, int index, ConstantPool constant_pool)
      Parameters:
      start_pc - Range in which the variable
      length - ... is valid
      name_index - Index in constant pool of variable name
      signature_index - Index of variable's signature
      index - Variable is `index'th local variable on the method's frame
      constant_pool - Array of constants
    • LocalVariable

      public LocalVariable(int start_pc, int length, int name_index, int signature_index, int index, ConstantPool constant_pool, int orig_index)
      Parameters:
      start_pc - Range in which the variable
      length - ... is valid
      name_index - Index in constant pool of variable name
      signature_index - Index of variable's signature
      index - Variable is `index'th local variable on the method's frame
      constant_pool - Array of constants
      orig_index - Variable is `index'th local variable on the method's frame prior to any changes
  • Method Details

    • accept

      public void accept(Visitor v)
      Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
      Specified by:
      accept in interface Node
      Parameters:
      v - Visitor object
    • dump

      public void dump(DataOutputStream dataOutputStream) throws IOException
      Dumps local variable to file stream in binary format.
      Parameters:
      dataOutputStream - Output file stream
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • getConstantPool

      public ConstantPool getConstantPool()
      Returns:
      Constant pool used by this object.
    • getLength

      public int getLength()
      Returns:
      Variable is valid within getStartPC() .. getStartPC()+getLength()
    • getName

      public String getName()
      Returns:
      Variable name.
    • getNameIndex

      public int getNameIndex()
      Returns:
      Index in constant pool of variable name.
    • getSignature

      public String getSignature()
      Returns:
      Signature.
    • getSignatureIndex

      public int getSignatureIndex()
      Returns:
      Index in constant pool of variable signature.
    • getIndex

      public int getIndex()
      Returns:
      index of register where variable is stored
    • getOrigIndex

      public int getOrigIndex()
      Returns:
      index of register where variable was originally stored
    • getStartPC

      public int getStartPC()
      Returns:
      Start of range where the variable is valid
    • toStringShared

      String toStringShared(boolean typeTable)
    • setConstantPool

      public void setConstantPool(ConstantPool constant_pool)
      Parameters:
      constant_pool - Constant pool to be used for this object.
    • setLength

      public void setLength(int length)
      Parameters:
      length - the length of this local variable
    • setNameIndex

      public void setNameIndex(int name_index)
      Parameters:
      name_index - the index into the constant pool for the name of this variable
    • setSignatureIndex

      public void setSignatureIndex(int signature_index)
      Parameters:
      signature_index - the index into the constant pool for the signature of this variable
    • setIndex

      public void setIndex(int index)
      Parameters:
      index - the index in the local variable table of this variable
    • setStartPC

      public void setStartPC(int start_pc)
      Parameters:
      start_pc - Specify range where the local variable is valid.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      string representation.
    • copy

      public LocalVariable copy()
      Returns:
      deep copy of this object