Class LocalVariable

  • All Implemented Interfaces:
    java.lang.Cloneable, Node, Constants

    public final class LocalVariable
    extends java.lang.Object
    implements java.lang.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:
    for more details on the difference., LocalVariableTable, LocalVariableTypeTable
    • Field Detail

      • startPc

        private int startPc
        Range in which the variable is valid.
      • length

        private int length
      • nameIndex

        private int nameIndex
        Index in constant pool of variable name.
      • signatureIndex

        private int signatureIndex
        Technically, a decscriptor_index for a local variable table entry and a signatureIndex for a local variable type table entry. Index of variable signature
      • index

        private int index
      • origIndex

        private final int origIndex
        Never changes; used to match up with LocalVariableTypeTable entries.
    • Constructor Detail

      • LocalVariable

        LocalVariable​(java.io.DataInput file,
                      ConstantPool constantPool)
               throws java.io.IOException
        Constructs object from file stream.
        Parameters:
        file - Input stream.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • LocalVariable

        public LocalVariable​(int startPc,
                             int length,
                             int nameIndex,
                             int signatureIndex,
                             int index,
                             ConstantPool constantPool)
        Constructs a LocalVariable.
        Parameters:
        startPc - Range in which the variable is valid.
        length - length of validity.
        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

        public LocalVariable​(int startPc,
                             int length,
                             int nameIndex,
                             int signatureIndex,
                             int index,
                             ConstantPool constantPool,
                             int origIndex)
        Constructs a LocalVariable.
        Parameters:
        startPc - Range in which the variable is valid.
        length - length of validity.
        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

        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 Detail

      • accept

        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

        public LocalVariable copy()
        Creates a deep copy of this object.
        Returns:
        deep copy of this object.
      • dump

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

        public ConstantPool getConstantPool()
        Gets the constant pool used by this object.
        Returns:
        Constant pool used by this object.
      • getIndex

        public int getIndex()
        Gets the index of register where variable is stored.
        Returns:
        index of register where variable is stored.
      • getLength

        public int getLength()
        Gets the length of validity.
        Returns:
        Variable is valid within getStartPC() .. getStartPC()+getLength().
      • getName

        public java.lang.String getName()
        Gets the variable name.
        Returns:
        Variable name.
      • getNameIndex

        public int getNameIndex()
        Gets the index in constant pool of variable name.
        Returns:
        Index in constant pool of variable name.
      • getOrigIndex

        public int getOrigIndex()
        Gets the index of register where variable was originally stored.
        Returns:
        index of register where variable was originally stored.
      • getSignature

        public java.lang.String getSignature()
        Gets the signature.
        Returns:
        Signature.
      • getSignatureIndex

        public int getSignatureIndex()
        Gets the index in constant pool of variable signature.
        Returns:
        Index in constant pool of variable signature.
      • getStartPC

        public int getStartPC()
        Gets the start of range where the variable is valid.
        Returns:
        Start of range where the variable is valid.
      • setConstantPool

        public void setConstantPool​(ConstantPool constantPool)
        Sets the constant pool to be used for this object.
        Parameters:
        constantPool - Constant pool to be used for this object.
      • setIndex

        public void setIndex​(int index)
        Sets the index in the local variable table of this variable.
        Parameters:
        index - the index in the local variable table of this variable.
      • setLength

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

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

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

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

        public java.lang.String toString()
        Gets the string representation.
        Overrides:
        toString in class java.lang.Object
        Returns:
        string representation.
      • toStringShared

        java.lang.String toStringShared​(boolean typeTable)