2016-04-12 20 views
1

我需要交換節點和node.getNext()中的ListIterator「nodeListIterator」我一直在嘗試了幾個小時的ListIterator交換當前和下一

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

謝謝你。

+1

你能實際上包含的代碼,並描述你看到的具體問題? – hooda

+0

@hooda代碼是完全不相關的,這是一個算法問題。它達到了給定的if語句和if語句正在驗證我只需要重新排列ListIterator ......... –

+0

@JordFlo請解釋你的代碼試圖完成的算法,而不是編碼。例如,你說你想交換'node'和'node.getNext()',但是我不確定你是否想要交換第一個和第二個節點,或者如果你想交換其他節點,等等,這有點令人困惑。 –

回答

0

我想通了,它的哈克但它的工作原理

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(); 
    } 
} 
相關問題