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 signatureIndex. The LocalVariableTypeTable attribute does have a signatureIndex.
See Also:
  • Constructor Details Link icon

    • LocalVariable Link icon

      public LocalVariable(int startPc, int length, int nameIndex, int signatureIndex, int index, ConstantPool constantPool)
      Parameters:
      startPc - Range in which the variable
      length - ... is valid
      nameIndex - Index in constant pool of variable name
      signatureIndex - Index of variable's signature
      index - Variable is 'index'th local variable on the method's frame
      constantPool - Array of constants
    • LocalVariable Link icon

      public LocalVariable(int startPc, int length, int nameIndex, int signatureIndex, int index, ConstantPool constantPool, int origIndex)
      Parameters:
      startPc - Range in which the variable
      length - ... is valid
      nameIndex - Index in constant pool of variable name
      signatureIndex - Index of variable's signature
      index - Variable is 'index'th local variable on the method's frame
      constantPool - Array of constants
      origIndex - Variable is 'index'th local variable on the method's frame prior to any changes
    • LocalVariable Link icon

      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.
  • Method Details Link icon

    • accept Link icon

      public void accept(Visitor v)
      Called by objects that are traversing the nodes of the tree implicitly 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
    • copy Link icon

      public LocalVariable copy()
      Returns:
      deep copy of this object
    • dump Link icon

      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 Link icon

      Returns:
      Constant pool used by this object.
    • getIndex Link icon

      public int getIndex()
      Returns:
      index of register where variable is stored
    • getLength Link icon

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

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

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

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

      public String getSignature()
      Returns:
      Signature.
    • getSignatureIndex Link icon

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

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

      public void setConstantPool(ConstantPool constantPool)
      Parameters:
      constantPool - Constant pool to be used for this object.
    • setIndex Link icon

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

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

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

      public void setSignatureIndex(int signatureIndex)
      Parameters:
      signatureIndex - the index into the constant pool for the signature of this variable
    • setStartPC Link icon

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

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