LocalVariableGenpublic class LocalVariableGen extends Object implements InstructionTargeter, Cloneable, NamedAndTyped, SerializableThis 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. |
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.
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.Object | clone()
try {
return super.clone();
} catch(CloneNotSupportedException e) {
System.err.println(e);
return null;
}
| public boolean | containsTarget(com.sun.org.apache.bcel.internal.generic.InstructionHandle ih)
return (start == ih) || (end == ih);
| public boolean | equals(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.InstructionHandle | getEnd() return end;
| public int | getIndex() return index;
| public com.sun.org.apache.bcel.internal.classfile.LocalVariable | getLocalVariable(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.
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.String | getName() return name;
| public com.sun.org.apache.bcel.internal.generic.InstructionHandle | getStart() return start;
| public com.sun.org.apache.bcel.internal.generic.Type | getType() return type;
| public void | setEnd(com.sun.org.apache.bcel.internal.generic.InstructionHandle end)
BranchInstruction.notifyTarget(this.end, end, this);
this.end = end;
| public void | setIndex(int index) this.index = index;
| public void | setName(java.lang.String name) this.name = name;
| public void | setStart(com.sun.org.apache.bcel.internal.generic.InstructionHandle start)
BranchInstruction.notifyTarget(this.start, start, this);
this.start = start;
| public void | setType(com.sun.org.apache.bcel.internal.generic.Type type) this.type = type;
| public java.lang.String | toString()
return "LocalVariableGen(" + name + ", " + type + ", " + start + ", " + end + ")";
| public void | updateTarget(com.sun.org.apache.bcel.internal.generic.InstructionHandle old_ih, com.sun.org.apache.bcel.internal.generic.InstructionHandle new_ih)
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 + "}");
|
|