if (source instanceof LocalVariableTag) {
Shadow.Kind kind = getKind();
if (kind == Shadow.AdviceExecution || kind == Shadow.ConstructorExecution || kind == Shadow.MethodExecution
|| kind == Shadow.PreInitialization || kind == Shadow.Initialization
|| kind == Shadow.StaticInitialization) {
LocalVariableTag sourceLocalVariableTag = (LocalVariableTag) source;
if (sourceLocalVariableTag.getSlot() == 0) {
// might be 'this' so should be renamed if being dumped in a static method 277616
if (sourceLocalVariableTag.getName().equals("this")) {
sourceLocalVariableTag.setName("ajc$this");
}
}
// if we're extracting a whole block we can do this...
source.updateTarget(oldIh, freshIh);
} else {
// XXX destroying local variable info
// but only for a call or get join point, so no big deal
source.updateTarget(oldIh, null);
}
} else if (source instanceof Range) {
// exceptions and shadows are just moved
((Range) source).updateTarget(oldIh, freshIh, freshBody);
} else {
// line numbers can be shared,
// branches will be copied along with us.
source.updateTarget(oldIh, freshIh);
}
}
// we're now done with the old instruction entirely, and will ignore them through
// the rest of this loop. The only time we'll see them again is a second pass to
// delete them.
// now deal with local variable instructions. If this points to a remapped
// frame location, update the instruction's index. If this doesn't,
// do compaction/expansion: allocate a new local variable, and modify the remap
// to handle it. XXX We're doing the safe thing and allocating ALL these local variables
// as double-wides, in case the location is found to hold a double-wide later.
if (freshI.isLocalVariableInstruction() || freshI instanceof RET) {
// IndexedInstruction indexedI = (IndexedInstruction) freshI;
int oldIndex = freshI.getIndex();
int freshIndex;
if (!remap.hasKey(oldIndex)) {
freshIndex = freshMethod.allocateLocal(2);
remap.put(oldIndex, freshIndex);
} else {
freshIndex = remap.get(oldIndex);
}
if (freshI instanceof RET) {
freshI.setIndex(freshIndex);
} else {
freshI = ((InstructionLV) freshI).setIndexAndCopyIfNecessary(freshIndex);
freshIh.setInstruction(freshI);
}
}
// System.err.println("JUST COPIED: " +
// oldIh.getInstruction().toString(freshMethod.getEnclosingClass().getConstantPoolGen().getConstantPool())
// + " INTO " +
// freshIh.getInstruction().toString(freshMethod.getEnclosingClass().getConstantPoolGen().getConstantPool()));
}
// now go through again and update variable slots that have been altered as a result
// of remapping...
for (InstructionHandle newIh = freshBody.getStart(); newIh != freshBody.getEnd(); newIh = newIh.getNext()) {
Iterator<InstructionTargeter> tIter = newIh.getTargeters().iterator();
while (tIter.hasNext()) {
InstructionTargeter source = tIter.next();
if (source instanceof LocalVariableTag) {
LocalVariableTag lvt = (LocalVariableTag) source;
if (!lvt.isRemapped() && remap.hasKey(lvt.getSlot())) {
lvt.updateSlot(remap.get(lvt.getSlot()));
}
}
}
}