本文整理汇总了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);
}
}