Example usage for org.objectweb.asm.tree AbstractInsnNode LINE

List of usage examples for org.objectweb.asm.tree AbstractInsnNode LINE

Introduction

In this page you can find the example usage for org.objectweb.asm.tree AbstractInsnNode LINE.

Prototype

int LINE

To view the source code for org.objectweb.asm.tree AbstractInsnNode LINE.

Click Source Link

Document

The type of LineNumberNode "instructions".

Usage

From source file:org.evosuite.instrumentation.NodeRegularExpression.java

License:Open Source License

/**
 * <p>matches</p>// ww  w  .j ava 2 s .  co m
 *
 * @param instructions a {@link org.objectweb.asm.tree.InsnList} object.
 * @return a boolean.
 */
public boolean matches(InsnList instructions) {
    int match = 0;

    AbstractInsnNode node = instructions.getFirst();
    while (node != instructions.getLast()) {
        if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL
                || node.getType() == AbstractInsnNode.LINE) {
            node = node.getNext();
            continue;
        } else {
            boolean found = false;
            for (int opcode : pattern[match]) {
                if (node.getOpcode() == opcode) {
                    match++;
                    found = true;
                    break;
                }
            }
            if (!found)
                match = 0;
        }
        if (match == pattern.length)
            return true;

        node = node.getNext();
    }

    return false;
}

From source file:org.evosuite.instrumentation.NodeRegularExpression.java

License:Open Source License

/**
 * <p>getNextMatch</p>//  w ww. j a  va2  s  . co m
 *
 * @param start a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
 * @param instructions a {@link org.objectweb.asm.tree.InsnList} object.
 * @return a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
 */
public AbstractInsnNode getNextMatch(AbstractInsnNode start, InsnList instructions) {
    int match = 0;

    AbstractInsnNode node = start;
    AbstractInsnNode startNode = start;
    while (node != instructions.getLast()) {
        if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL
                || node.getType() == AbstractInsnNode.LINE) {
            node = node.getNext();
            continue;
        } else {
            boolean found = false;
            for (int opcode : pattern[match]) {
                if (node.getOpcode() == opcode) {
                    if (match == 0)
                        startNode = node;
                    match++;
                    found = true;
                    break;
                }
            }
            if (!found)
                match = 0;
        }
        if (match == pattern.length) {
            return startNode;
        }

        node = node.getNext();
    }

    return null;

}

From source file:org.jacoco.core.internal.analysis.filter.AbstractMatcher.java

License:Open Source License

/**
 * Returns first instruction from given and following it that is not
 * {@link AbstractInsnNode#FRAME}, {@link AbstractInsnNode#LABEL},
 * {@link AbstractInsnNode#LINE}./*  ww w . java 2  s . com*/
 */
static AbstractInsnNode skipNonOpcodes(AbstractInsnNode cursor) {
    while (cursor != null && (cursor.getType() == AbstractInsnNode.FRAME
            || cursor.getType() == AbstractInsnNode.LABEL || cursor.getType() == AbstractInsnNode.LINE)) {
        cursor = cursor.getNext();
    }
    return cursor;
}

From source file:org.jacoco.core.internal.analysis.filter.FinallyFilter.java

License:Open Source License

private static void filter(final IFilterOutput output, final List<TryCatchBlockNode> tryCatchBlocks,
        final TryCatchBlockNode catchAnyBlock) {
    final AbstractInsnNode e = next(catchAnyBlock.handler);
    final int size = size(e);
    if (size <= 0) {
        return;/*from  www.  ja v a  2  s .  c  om*/
    }

    // Determine instructions inside regions
    final Set<AbstractInsnNode> inside = new HashSet<AbstractInsnNode>();
    for (final TryCatchBlockNode t : tryCatchBlocks) {
        if (t.handler == catchAnyBlock.handler) {
            AbstractInsnNode i = t.start;
            while (i != t.end) {
                inside.add(i);
                i = i.getNext();
            }
        }
    }

    // Find and merge duplicates at exits of regions
    for (final TryCatchBlockNode t : tryCatchBlocks) {
        if (t.handler == catchAnyBlock.handler) {
            boolean continues = false;
            AbstractInsnNode i = t.start;

            while (i != t.end) {
                switch (i.getType()) {
                case AbstractInsnNode.FRAME:
                case AbstractInsnNode.LINE:
                case AbstractInsnNode.LABEL:
                    break;
                case AbstractInsnNode.JUMP_INSN:
                    final AbstractInsnNode jumpTarget = next(((JumpInsnNode) i).label);
                    if (!inside.contains(jumpTarget)) {
                        merge(output, size, e, jumpTarget);
                    }
                    continues = i.getOpcode() != Opcodes.GOTO;
                    break;
                default:
                    switch (i.getOpcode()) {
                    case Opcodes.IRETURN:
                    case Opcodes.LRETURN:
                    case Opcodes.FRETURN:
                    case Opcodes.DRETURN:
                    case Opcodes.ARETURN:
                    case Opcodes.RETURN:
                    case Opcodes.ATHROW:
                        continues = false;
                        break;
                    default:
                        continues = true;
                        break;
                    }
                    break;
                }
                i = i.getNext();
            }

            i = next(i);
            if (continues && !inside.contains(i)) {
                merge(output, size, e, i);
            }
        }

        if (t != catchAnyBlock && t.start == catchAnyBlock.start && t.end == catchAnyBlock.end) {
            final AbstractInsnNode i = next(next(t.handler));
            if (!inside.contains(i)) {
                // javac's empty catch - merge after ASTORE
                merge(output, size, e, i);
            }
        }
    }
}

From source file:org.jacoco.core.internal.analysis.filter.FinallyFilter.java

License:Open Source License

private static AbstractInsnNode next(AbstractInsnNode i) {
    do {//from ww w. ja v  a  2s  .com
        i = i.getNext();
    } while (i != null && (AbstractInsnNode.FRAME == i.getType() || AbstractInsnNode.LABEL == i.getType()
            || AbstractInsnNode.LINE == i.getType()));
    return i;
}

From source file:org.jacoco.core.internal.analysis.filter.KotlinGeneratedFilter.java

License:Open Source License

private boolean hasLineNumber(final MethodNode methodNode) {
    for (final AbstractInsnNode i : methodNode.instructions) {
        if (AbstractInsnNode.LINE == i.getType()) {
            return true;
        }/*from ww w. j  a  va 2s  .c  o  m*/
    }
    return false;
}

From source file:org.jacoco.core.internal.analysis.filter.KotlinInlineFilter.java

License:Open Source License

public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) {
    if (context.getSourceDebugExtension() == null) {
        return;//  w w  w  . ja  va2 s.co m
    }

    if (!KotlinGeneratedFilter.isKotlinClass(context)) {
        return;
    }

    if (firstGeneratedLineNumber == -1) {
        firstGeneratedLineNumber = getFirstGeneratedLineNumber(context.getSourceFileName(),
                context.getSourceDebugExtension());
    }

    int line = 0;
    for (final AbstractInsnNode i : methodNode.instructions) {
        if (AbstractInsnNode.LINE == i.getType()) {
            line = ((LineNumberNode) i).line;
        }
        if (line >= firstGeneratedLineNumber) {
            output.ignore(i, i);
        }
    }
}

From source file:org.jacoco.core.test.filter.FinallyTest.java

License:Open Source License

/**
 * This test studies placement of GOTO instructions.
 *///from   ww w  .  j a v a 2 s .  c o  m
@Test
public void gotos() throws IOException {
    final Source source = Source.getSourceFor("src", Finally.class);

    final ClassNode classNode = new ClassNode();
    new ClassReader(TargetLoader.getClassDataAsBytes(Finally.class)).accept(classNode, 0);
    final Set<String> tags = new HashSet<String>();
    for (final MethodNode m : classNode.methods) {
        if ("main".equals(m.name)) {
            // skip it
            continue;
        }
        int lineNumber = -1;
        for (AbstractInsnNode i = m.instructions.getFirst(); i != null; i = i.getNext()) {
            if (AbstractInsnNode.LINE == i.getType()) {
                lineNumber = ((LineNumberNode) i).line;
            }
            if (Opcodes.GOTO == i.getOpcode()) {
                final String line = source.getLine(lineNumber);
                if (line.indexOf('$') < 0) {
                    throw new AssertionError("No tag at line " + lineNumber);
                }
                final String tag = line.substring(line.indexOf('$') + "$line-".length(), line.lastIndexOf('$'));
                tags.add(tag);
            }
        }
    }

    final Set<String> expected = new HashSet<String>();

    if (isJDKCompiler) {
        expected.add("example.2");
    } else {
        expected.add("example.0");
    }

    expected.add("breakStatement.for");
    if (isJDKCompiler) {
        expected.add("breakStatement.1");
        expected.add("breakStatement.2");
    } else {
        expected.add("breakStatement");
    }

    if (isJDKCompiler) {
        expected.add("emptyCatch.2");
    } else {
        expected.add("emptyCatch");
        expected.add("emptyCatch.1");
    }

    if (isJDKCompiler) {
        expected.add("catchNotExecuted.2");
    } else {
        expected.add("catchNotExecuted");
        expected.add("catchNotExecuted.1");
    }

    if (isJDKCompiler) {
        expected.add("nested.5");
        expected.add("nested.6");
    } else {
        expected.add("nested.0");
        expected.add("nested.3");
    }

    if (isJDKCompiler && !isJDK8) {
        expected.add("emptyTry.2");
    }

    if (!isJDKCompiler) {
        expected.add("alwaysCompletesAbruptly.0");
    }

    assertEquals(expected, tags);
}

From source file:org.jacoco.core.test.validation.java5.FinallyTest.java

License:Open Source License

private Set<String> getTagsWithGotos() throws IOException {
    final Set<String> gotoTags = new HashSet<String>();

    byte[] b = TargetLoader.getClassDataAsBytes(FinallyTarget.class);

    final ClassNode classNode = new ClassNode();
    InstrSupport.classReaderFor(b).accept(classNode, 0);
    for (final MethodNode m : classNode.methods) {
        if ("main".equals(m.name)) {
            // skip it
            continue;
        }/*from w ww .j  a  v  a 2s .  co  m*/
        int lineNumber = -1;
        for (AbstractInsnNode i : m.instructions) {
            if (AbstractInsnNode.LINE == i.getType()) {
                lineNumber = ((LineNumberNode) i).line;
            }
            if (Opcodes.GOTO == i.getOpcode()) {
                String tag = tags.get(Integer.valueOf(lineNumber));
                if (tag == null) {
                    throw new AssertionError("No tag at line " + lineNumber);
                }
                gotoTags.add(tag);
            }
        }
    }

    return gotoTags;
}

From source file:org.jacoco.playground.filter.InsnSequenceMatcher.java

License:Open Source License

private boolean isIgnored(AbstractInsnNode node) {
    switch (node.getType()) {
    case AbstractInsnNode.LABEL:
    case AbstractInsnNode.LINE:
        return true;
    default://from w  w w .  ja  v a 2  s  .  c  o  m
        return false;
    }
}