# Class LocalVariableGen

java.lang.Object
org.apache.bcel.generic.LocalVariableGen

All Implemented Interfaces:
  `Cloneable, InstructionTargeter, NamedAndTyped`

public class LocalVariableGen extends Object implements InstructionTargeter, NamedAndTyped, Cloneable
Represents a local variable within a method. It contains its scope, name and type. The generated LocalVariable object can be obtained with getLocalVariable which needs the instruction list and the constant pool as parameters.

See Also:
  - `LocalVariable`
  - `MethodGen`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LocalVariableGen(int index, String name, Type type, InstructionHandle start, InstructionHandle end)`
  Generate a local variable that with index 'index'.
  `LocalVariableGen(int index, String name, Type type, InstructionHandle start, InstructionHandle end, int origIndex)`
  Generates a local variable that with index 'index'.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  `boolean`
  `containsTarget(InstructionHandle ih)`
  Tests whether this targeter targets the specified instruction handle.
  `boolean`
  `equals(Object o)`
  We consider to local variables to be equal, if the use the same index and are valid in the same range.
  `InstructionHandle`
  `getEnd()`
  Gets the end instruction handle.
  `int`
  `getIndex()`
  Gets the index.
  `boolean`
  `getLiveToEnd()`
  Gets whether the variable lives to the end.
  `LocalVariable`
  `getLocalVariable(ConstantPoolGen cp)`
  Gets LocalVariable object.
  `String`
  `getName()`
  Gets the name.
  `int`
  `getOrigIndex()`
  Gets the original index.
  `InstructionHandle`
  `getStart()`
  Gets the start instruction handle.
  `Type`
  `getType()`
  Gets the type.
  `int`
  `hashCode()`
  `void`
  `setEnd(InstructionHandle end)`
  Sets the end instruction handle.
  `void`
  `setIndex(int index)`
  Sets the index.
  `void`
  `setLiveToEnd(boolean liveToEnd)`
  Sets whether the variable lives to the end.
  `void`
  `setName(String name)`
  Sets the name.
  `void`
  `setStart(InstructionHandle start)`
  Sets the start instruction handle.
  `void`
  `setType(Type type)`
  Sets the type.
  `String`
  `toString()`
  `void`
  `updateTarget(InstructionHandle oldIh, InstructionHandle newIh)`
  Replaces the target of this targeter from this old handle to the new handle.

  ### Methods inherited from class Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### LocalVariableGen

    public LocalVariableGen(int index, String name, Type type, InstructionHandle start, InstructionHandle end)
    Generate a local variable that with index 'index'. Note that double and long variables need two indexs. Index indices have to be provided by the user.
    Parameters:
      `index` - index of local variable.
      `name` - its name.
      `type` - its type.
      `start` - from where the instruction is valid (null means from the start).
      `end` - until where the instruction is valid (null means to the end).

  - ### LocalVariableGen

    public LocalVariableGen(int index, String name, Type type, InstructionHandle start, InstructionHandle end, int origIndex)
    Generates a local variable that with index 'index'. Note that double and long variables need two indexs. Index indices have to be provided by the user.
    Parameters:
      `index` - index of local variable.
      `name` - its name.
      `type` - its type.
      `start` - from where the instruction is valid (null means from the start).
      `end` - until where the instruction is valid (null means to the end).
      `origIndex` - index of local variable prior to any changes to index.

- ## Method Details

  - ### clone

    public Object clone()
    Overrides:
      `clone` in class `Object`

  - ### containsTarget

    public boolean containsTarget(InstructionHandle ih)
    Description copied from interface: `InstructionTargeter`
    Tests whether this targeter targets the specified instruction handle.
    Specified by:
      `containsTarget` in interface `InstructionTargeter`
    Parameters:
      `ih` - the instruction handle to test.
    Returns:
      true, if ih is target of this variable.

  - ### equals

    public boolean equals(Object o)
    We consider to local variables to be equal, if the use the same index and are valid in the same range.
    Overrides:
      `equals` in class `Object`

  - ### getEnd

    public InstructionHandle getEnd()
    Gets the end instruction handle.
    Returns:
      the end instruction handle.

  - ### getIndex

    public int getIndex()
    Gets the index.
    Returns:
      the index.

  - ### getLiveToEnd

    public boolean getLiveToEnd()
    Gets whether the variable lives to the end.
    Returns:
      true if the variable lives to the end.

  - ### getLocalVariable

    public LocalVariable getLocalVariable(ConstantPoolGen cp)
    Gets LocalVariable object. This relies on that the instruction list has already been dumped to byte code or that the 'setPositions' methods has been called for the instruction list. Note that due to the conversion from byte code offset to InstructionHandle, it is impossible to tell the difference between a live range that ends BEFORE the last insturction of the method or a live range that ends AFTER the last instruction of the method. Hence the liveToEnd flag to differentiate between these two cases.
    Parameters:
      `cp` - constant pool.
    Returns:
      the local variable.

  - ### getName

    public String getName()
    Description copied from interface: `NamedAndTyped`
    Gets the name.
    Specified by:
      `getName` in interface `NamedAndTyped`
    Returns:
      the name.

  - ### getOrigIndex

    public int getOrigIndex()
    Gets the original index.
    Returns:
      the original index.

  - ### getStart

    public InstructionHandle getStart()
    Gets the start instruction handle.
    Returns:
      the start instruction handle.

  - ### getType

    public Type getType()
    Description copied from interface: `NamedAndTyped`
    Gets the type.
    Specified by:
      `getType` in interface `NamedAndTyped`
    Returns:
      the type.

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### setEnd

    public void setEnd(InstructionHandle end)
    Sets the end instruction handle.
    Parameters:
      `end` - the end instruction handle.

  - ### setIndex

    public void setIndex(int index)
    Sets the index.
    Parameters:
      `index` - the index.

  - ### setLiveToEnd

    public void setLiveToEnd(boolean liveToEnd)
    Sets whether the variable lives to the end.
    Parameters:
      `liveToEnd` - true if the variable lives to the end.

  - ### setName

    public void setName(String name)
    Description copied from interface: `NamedAndTyped`
    Sets the name.
    Specified by:
      `setName` in interface `NamedAndTyped`
    Parameters:
      `name` - the name.

  - ### setStart

    public void setStart(InstructionHandle start)
    Sets the start instruction handle.
    Parameters:
      `start` - the start instruction handle.

  - ### setType

    public void setType(Type type)
    Description copied from interface: `NamedAndTyped`
    Sets the type.
    Specified by:
      `setType` in interface `NamedAndTyped`
    Parameters:
      `type` - the type.

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### updateTarget

    public void updateTarget(InstructionHandle oldIh, InstructionHandle newIh)
    Description copied from interface: `InstructionTargeter`
    Replaces the target of this targeter from this old handle to the new handle.
    Specified by:
      `updateTarget` in interface `InstructionTargeter`
    Parameters:
      `oldIh` - old target, either start or end.
      `newIh` - new target.