in src/main/java/org/apache/bcel/generic/InstructionList.java [873:921]
public void move(final InstructionHandle start, final InstructionHandle end, final InstructionHandle target) {
// Step 1: Check constraints
if (start == null || end == null) {
throw new ClassGenException("Invalid null handle: From " + start + " to " + end);
}
if (target == start || target == end) {
throw new ClassGenException("Invalid range: From " + start + " to " + end + " contains target " + target);
}
for (InstructionHandle ih = start; ih != end.getNext(); ih = ih.getNext()) {
if (ih == null) {
throw new ClassGenException("Invalid range: From " + start + " to " + end);
}
if (ih == target) {
throw new ClassGenException("Invalid range: From " + start + " to " + end + " contains target " + target);
}
}
// Step 2: Temporarily remove the given instructions from the list
final InstructionHandle prev = start.getPrev();
InstructionHandle next = end.getNext();
if (prev != null) {
prev.setNext(next);
} else {
this.start = next;
}
if (next != null) {
next.setPrev(prev);
} else {
this.end = prev;
}
start.setPrev(end.setNext(null));
// Step 3: append after target
if (target == null) { // append to start of list
if (this.start != null) {
this.start.setPrev(end);
}
end.setNext(this.start);
this.start = start;
} else {
next = target.getNext();
target.setNext(start);
start.setPrev(target);
end.setNext(next);
if (next != null) {
next.setPrev(end);
} else {
this.end = end;
}
}
}