本文整理匯總了Java中org.objectweb.asm.tree.InsnList.indexOf方法的典型用法代碼示例。如果您正苦於以下問題:Java InsnList.indexOf方法的具體用法?Java InsnList.indexOf怎麽用?Java InsnList.indexOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.objectweb.asm.tree.InsnList
的用法示例。
在下文中一共展示了InsnList.indexOf方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findLineNumberForInstruction
import org.objectweb.asm.tree.InsnList; //導入方法依賴的package包/類
/**
* Find line number associated with an instruction.
* @param insnList instruction list for method
* @param insnNode instruction within method being searched against
* @throws NullPointerException if any argument is {@code null} or contains {@code null}
* @throws IllegalArgumentException if arguments aren't all from the same method
* @return line number node associated with the instruction, or {@code null} if no line number exists
*/
public static LineNumberNode findLineNumberForInstruction(InsnList insnList, AbstractInsnNode insnNode) {
Validate.notNull(insnList);
Validate.notNull(insnNode);
int idx = insnList.indexOf(insnNode);
Validate.isTrue(idx != -1);
// Get index of labels and insnNode within method
ListIterator<AbstractInsnNode> insnIt = insnList.iterator(idx);
while (insnIt.hasPrevious()) {
AbstractInsnNode node = insnIt.previous();
if (node instanceof LineNumberNode) {
return (LineNumberNode) node;
}
}
return null;
}
示例2: removeNeedleFromHaystack
import org.objectweb.asm.tree.InsnList; //導入方法依賴的package包/類
/**
* removes an entire instruction set in the haystack.
*
* @param haystack
* The instruction set to be searched in
* @param needle
* The instruction set to search for and to be removed
*/
public static void removeNeedleFromHaystack(InsnList haystack, InsnList needle) {
int firstInd = haystack.indexOf(findFirstNodeFromNeedle(haystack, needle));
int lastInd = haystack.indexOf(findLastNodeFromNeedle(haystack, needle));
List<AbstractInsnNode> realNeedle = new ArrayList<>();
for (int i = firstInd; i <= lastInd; i++) {
realNeedle.add(haystack.get(i));
}
for (AbstractInsnNode node : realNeedle) {
haystack.remove(node);
}
}