📄 insnlist.java
字号:
throw new IllegalArgumentException();
}
++size;
if (first == null) {
first = insn;
last = insn;
} else {
first.prev = insn;
insn.next = first;
}
first = insn;
cache = null;
insn.index = 0; // insn now belongs to an InsnList
}
/**
* Inserts the given instructions at the begining of this list.
*
* @param insns an instruction list, which is cleared during the process.
* @throws IllegalArgumentException if {@link #check} is <tt>true</tt>,
* and if insn == this.
*/
public void insert(final InsnList insns) {
if (check && insns == this) {
throw new IllegalArgumentException();
}
if (insns.size == 0) {
return;
}
size += insns.size;
if (first == null) {
first = insns.first;
last = insns.last;
} else {
AbstractInsnNode elem = insns.last;
first.prev = elem;
elem.next = first;
first = insns.first;
}
cache = null;
insns.removeAll(false);
}
/**
* Inserts the given instruction after the specified instruction.
*
* @param location an instruction <i>of this list</i> after which insn must be
* inserted.
* @param insn the instruction to be inserted, <i>which must not belong to
* any {@link InsnList}</i>.
* @throws IllegalArgumentException if {@link #check} is <tt>true</tt>,
* and if i does not belong to this list or if insn belongs to an
* instruction list.
*/
public void insert(final AbstractInsnNode location, final AbstractInsnNode insn) {
if (check && !(contains(location) && insn.index == -1)) {
throw new IllegalArgumentException();
}
++size;
AbstractInsnNode next = location.next;
if (next == null) {
last = insn;
} else {
next.prev = insn;
}
location.next = insn;
insn.next = next;
insn.prev = location;
cache = null;
insn.index = 0; // insn now belongs to an InsnList
}
/**
* Inserts the given instructions after the specified instruction.
*
* @param location an instruction <i>of this list</i> after which the instructions
* must be inserted.
* @param insns the instruction list to be inserted, which is cleared during
* the process.
* @throws IllegalArgumentException if {@link #check} is <tt>true</tt>,
* and if i does not belong to this list or if insns == this.
*/
public void insert(final AbstractInsnNode location, final InsnList insns) {
if (check && !(contains(location) && insns != this)) {
throw new IllegalArgumentException();
}
if (insns.size == 0) {
return;
}
size += insns.size;
AbstractInsnNode ifirst = insns.first;
AbstractInsnNode ilast = insns.last;
AbstractInsnNode next = location.next;
if (next == null) {
last = ilast;
} else {
next.prev = ilast;
}
location.next = ifirst;
ilast.next = next;
ifirst.prev = location;
cache = null;
insns.removeAll(false);
}
/**
* Inserts the given instruction before the specified instruction.
*
* @param location an instruction <i>of this list</i> before which insn must be
* inserted.
* @param insn the instruction to be inserted, <i>which must not belong to
* any {@link InsnList}</i>.
* @throws IllegalArgumentException if {@link #check} is <tt>true</tt>,
* and if i does not belong to this list or if insn belongs to an
* instruction list.
*/
public void insertBefore(final AbstractInsnNode location, final AbstractInsnNode insn) {
if (check && !(contains(location) && insn.index == -1)) {
throw new IllegalArgumentException();
}
++size;
AbstractInsnNode prev = location.prev;
if (prev == null) {
first = insn;
} else {
prev.next = insn;
}
location.prev = insn;
insn.next = location;
insn.prev = prev;
cache = null;
insn.index = 0; // insn now belongs to an InsnList
}
/**
* Inserts the given instructions before the specified instruction.
*
* @param location an instruction <i>of this list</i> before which the instructions
* must be inserted.
* @param insns the instruction list to be inserted, which is cleared during
* the process.
* @throws IllegalArgumentException if {@link #check} is <tt>true</tt>,
* and if i does not belong to this list or if insns == this.
*/
public void insertBefore(final AbstractInsnNode location, final InsnList insns) {
if (check && !(contains(location ) && insns != this)) {
throw new IllegalArgumentException();
}
if (insns.size == 0) {
return;
}
size += insns.size;
AbstractInsnNode ifirst = insns.first;
AbstractInsnNode ilast = insns.last;
AbstractInsnNode prev = location .prev;
if (prev == null) {
first = ifirst;
} else {
prev.next = ifirst;
}
location .prev = ilast;
ilast.next = location ;
ifirst.prev = prev;
cache = null;
insns.removeAll(false);
}
/**
* Removes the given instruction from this list.
*
* @param insn the instruction <i>of this list</i> that must be removed.
* @throws IllegalArgumentException if {@link #check} is <tt>true</tt>,
* and if insn does not belong to this list.
*/
public void remove(final AbstractInsnNode insn) {
if (check && !contains(insn)) {
throw new IllegalArgumentException();
}
--size;
AbstractInsnNode next = insn.next;
AbstractInsnNode prev = insn.prev;
if (next == null) {
if (prev == null) {
first = null;
last = null;
} else {
prev.next = null;
last = prev;
}
} else {
if (prev == null) {
first = next;
next.prev = null;
} else {
prev.next = next;
next.prev = prev;
}
}
cache = null;
insn.index = -1; // insn no longer belongs to an InsnList
insn.prev = null;
insn.next = null;
}
/**
* Removes all of the instructions of this list.
*
* @param mark if the instructions must be marked as no longer belonging to
* any {@link InsnList}.
*/
private void removeAll(final boolean mark) {
if (mark) {
AbstractInsnNode insn = first;
while (insn != null) {
AbstractInsnNode next = insn.next;
insn.index = -1; // insn no longer belongs to an InsnList
insn.prev = null;
insn.next = null;
insn = next;
}
}
size = 0;
first = null;
last = null;
cache = null;
}
/**
* Removes all of the instructions of this list.
*/
public void clear() {
removeAll(check);
}
private final class InsnListIterator implements ListIterator {
AbstractInsnNode next;
AbstractInsnNode prev;
public InsnListIterator(int index) {
if(index==size()) {
next = null;
prev = getLast();
} else {
next = get(index);
prev = next.prev;
}
}
public boolean hasNext() {
return next != null;
}
public Object next() {
AbstractInsnNode result = next;
prev = result;
next = result.next;
return result;
}
public void remove() {
InsnList.this.remove(prev);
prev = prev.prev;
}
public boolean hasPrevious() {
return prev != null;
}
public Object previous() {
AbstractInsnNode result = prev;
next = result;
prev = result.prev;
return result;
}
public int nextIndex() {
if (next == null) {
return size();
}
if (cache == null) {
cache = toArray();
}
return next.index;
}
public int previousIndex() {
if (prev == null) {
return -1;
}
if (cache == null) {
cache = toArray();
}
return prev.index;
}
public void add(Object o) {
InsnList.this.insertBefore(next, (AbstractInsnNode) o);
prev = (AbstractInsnNode) o;
}
public void set(Object o) {
InsnList.this.set(next.prev, (AbstractInsnNode) o);
prev = (AbstractInsnNode) o;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -