Example usage for org.objectweb.asm.tree InsnList iterator

List of usage examples for org.objectweb.asm.tree InsnList iterator

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList iterator.

Prototype

@SuppressWarnings("unchecked")
public ListIterator<AbstractInsnNode> iterator(final int index) 

Source Link

Document

Returns an iterator over the instructions in this list.

Usage

From source file:com.offbynull.coroutines.instrumenter.asm.SearchUtils.java

License:Open Source License

/**
 * 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
 *///  ww w . jav  a2 s.  c o  m
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;
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.GetFieldChainInliner.java

License:Open Source License

@Override
public InsnList optimize(final InsnList original, final MethodNode methodNode) throws JBOPClassException {
    optimized = false;//  w ww  . ja v  a  2s  .c o m
    final ListIterator<AbstractInsnNode> localIterator = original.iterator(iterator.nextIndex());
    Object object = input;
    Object lastObject = null;
    final List<AbstractInsnNode> nodes = new ArrayList<>();
    String fieldname = null;
    while (localIterator.hasNext()) {
        final AbstractInsnNode next = localIterator.next();
        if (next.getOpcode() == GETFIELD) {
            fieldname = NodeHelper.getFieldname(next);
            if (!ClassAccessor.isFinal(object, fieldname)) {
                correctIterator(localIterator);
                return original;
            }
            nodes.add(next);
            lastObject = object;
            object = ClassAccessor.getCurrentValue(object, fieldname);

        } else {
            if (object == input) {
                correctIterator(localIterator);
                return original;
            }
            final Type type = Type.getType(object.getClass());
            final String descriptor = type.getDescriptor();

            if (handleBuiltIn(descriptor, original, next, object, nodes, localIterator)) {
                optimized = true;
                return original;
            }
            object = handleArray(type, nodes, object, lastObject, next, fieldname, localIterator);
            if (object == null) {
                correctIterator(localIterator);
                return original;
            }
        }
    }
    return original;
}