FileDocCategorySizeDatePackage
LocalVariableGen.javaAPI DocJava SE 6 API7518Tue Jun 10 00:22:22 BST 2008com.sun.org.apache.bcel.internal.generic

LocalVariableGen

public class LocalVariableGen extends Object implements InstructionTargeter, Cloneable, NamedAndTyped, Serializable
This class 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.
version
$Id: LocalVariableGen.java,v 1.1.2.1 2005/07/31 23:45:23 jeffsuttor Exp $
author
M. Dahm
see
LocalVariable
see
MethodGen

Fields Summary
private int
index
private String
name
private Type
type
private InstructionHandle
start
private InstructionHandle
end
Constructors Summary
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.

param
index index of local variable
param
name its name
param
type its type
param
start from where the instruction is valid (null means from the start)
param
end until where the instruction is valid (null means to the end)

    if((index < 0) || (index > Constants.MAX_SHORT))
      throw new ClassGenException("Invalid index index: " + index);
    
    this.name  = name;
    this.type  = type;
    this.index  = index;
    setStart(start);
    setEnd(end);
  
Methods Summary
public java.lang.Objectclone()

    try {
      return super.clone();
    } catch(CloneNotSupportedException e) {
      System.err.println(e);
      return null;
    }
  
public booleancontainsTarget(com.sun.org.apache.bcel.internal.generic.InstructionHandle ih)

return
true, if ih is target of this variable

    return (start == ih) || (end == ih);
  
public booleanequals(java.lang.Object o)
We consider to local variables to be equal, if the use the same index and are valid in the same range.

    if(!(o instanceof LocalVariableGen))
      return false;

    LocalVariableGen l = (LocalVariableGen)o;
    return (l.index == index) && (l.start == start) && (l.end == end);
  
public com.sun.org.apache.bcel.internal.generic.InstructionHandlegetEnd()

 return end; 
public intgetIndex()

 return index; 
public com.sun.org.apache.bcel.internal.classfile.LocalVariablegetLocalVariable(com.sun.org.apache.bcel.internal.generic.ConstantPoolGen cp)
Get LocalVariable object. This relies on that the instruction list has already been dumped to byte code or or that the `setPositions' methods has been called for the instruction list. Note that for local variables whose scope end at the last instruction of the method's code, the JVM specification is ambiguous: both a start_pc+length ending at the last instruction and start_pc+length ending at first index beyond the end of the code are valid.

param
il instruction list (byte code) which this variable belongs to
param
cp constant pool

    int start_pc        = start.getPosition();
    int length          = end.getPosition() - start_pc;

    if(length > 0)
      length += end.getInstruction().getLength();
    
    int name_index      = cp.addUtf8(name);
    int signature_index = cp.addUtf8(type.getSignature());

    return new LocalVariable(start_pc, length, name_index,
			     signature_index, index, cp.getConstantPool());
  
public java.lang.StringgetName()

 return name; 
public com.sun.org.apache.bcel.internal.generic.InstructionHandlegetStart()

 return start; 
public com.sun.org.apache.bcel.internal.generic.TypegetType()

 return type; 
public voidsetEnd(com.sun.org.apache.bcel.internal.generic.InstructionHandle end)

    BranchInstruction.notifyTarget(this.end, end, this);
    this.end = end;
  
public voidsetIndex(int index)

 this.index = index; 
public voidsetName(java.lang.String name)

 this.name = name; 
public voidsetStart(com.sun.org.apache.bcel.internal.generic.InstructionHandle start)

    BranchInstruction.notifyTarget(this.start, start, this);
    this.start = start;
  
public voidsetType(com.sun.org.apache.bcel.internal.generic.Type type)

 this.type = type; 
public java.lang.StringtoString()

    return "LocalVariableGen(" + name +  ", " + type +  ", " + start + ", " + end + ")";
  
public voidupdateTarget(com.sun.org.apache.bcel.internal.generic.InstructionHandle old_ih, com.sun.org.apache.bcel.internal.generic.InstructionHandle new_ih)

param
old_ih old target, either start or end
param
new_ih new target

    boolean targeted = false;

    if(start == old_ih) {
      targeted = true;
      setStart(new_ih);
    }

    if(end == old_ih) {
      targeted = true;
      setEnd(new_ih);
    }

    if(!targeted)
      throw new ClassGenException("Not targeting " + old_ih + ", but {" + start + ", " +
				  end + "}");