FileDocCategorySizeDatePackage
LocalVariableGen.javaAPI DocJava SE 5 API7118Fri Aug 26 14:55:22 BST 2005com.sun.org.apache.bcel.internal.generic

LocalVariableGen

public class LocalVariableGen extends Object implements InstructionTargeter, Cloneable, NamedAndTyped
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.1.1 2001/10/29 20:00:23 jvanzyl 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.

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;
    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 + "}");