gpt4 book ai didi

java - ListIterator 交换当前和下一个

转载 作者:太空宇宙 更新时间:2023-11-04 12:43:43 25 4
gpt4 key购买 nike

我需要在ListIterator“nodeListIterator”中交换node和node.getNext(),并且我已经尝试了几个小时

 if (node instanceof LdcInsnNode && (node.getNext() instanceof FieldInsnNode && node.getNext().getOpcode() == Opcodes.GETSTATIC)
&& node.getNext().getNext().getOpcode() == Opcodes.IMUL) {
// code
}

谢谢你。

最佳答案

我想通了,虽然很老套,但很有效

final ListIterator<AbstractInsnNode> nodeListIterator = methodNode.instructions.iterator();
while (nodeListIterator.hasNext()) {
AbstractInsnNode node = nodeListIterator.next();
if (node instanceof LdcInsnNode && (node.getNext() instanceof FieldInsnNode && node.getNext().getOpcode() == Opcodes.GETSTATIC)
&& node.getNext().getNext().getOpcode() == Opcodes.IMUL) {
AbstractInsnNode temp1 = node;
nodeListIterator.remove();
node = nodeListIterator.next();
AbstractInsnNode temp2 = node;
nodeListIterator.remove();
nodeListIterator.next();
nodeListIterator.previous();
nodeListIterator.add(temp1);
nodeListIterator.previous();
nodeListIterator.add(temp2);
nodeListIterator.previous();
}
}

关于java - ListIterator 交换当前和下一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36562880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com