if (oldIfHandle.hasTargeters()) {
InstructionTargeter[] targeters =
oldIfHandle.getTargeters();
for (int i = 0; i < targeters.length; i++) {
InstructionTargeter targeter = targeters[i];
// Ideally, one should simply be able to use
// InstructionTargeter.updateTarget to change
// references to the old IF instruction to the new
// IF instruction. However, if a LocalVariableGen
// indicated the old IF marked the end of the range
// in which the IF variable is in use, the live
// range of the variable must extend to include the
// newly created GOTO instruction. The need for
// this sort of specific knowledge of an
// implementor of the InstructionTargeter interface
// makes the code more fragile. Future implementors
// of the interface might have similar requirements
// which wouldn't be accommodated seemlessly.
if (targeter instanceof LocalVariableGen) {
LocalVariableGen lvg =
(LocalVariableGen) targeter;
if (lvg.getStart() == oldIfHandle) {
lvg.setStart(invertedIfHandle);
} else if (lvg.getEnd() == oldIfHandle) {
lvg.setEnd(gotoHandle);
}
} else {
targeter.updateTarget(oldIfHandle,
invertedIfHandle);
}
}
}