Search in sources :

Example 81 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.

the class InstructionsBuilderTest method jumps_should_propagate_coverage_status.

@Test
public void jumps_should_propagate_coverage_status() {
    InsnNode i1 = new InsnNode(Opcodes.NOP);
    builder.addInstruction(i1);
    Label l2 = new Label();
    builder.addJump(l2, 0);
    builder.addLabel(l2);
    InsnNode i2 = new InsnNode(Opcodes.NOP);
    builder.addInstruction(i2);
    // mark i2 as covered
    builder.addProbe(1, 0);
    // coverage should be propagated to i1
    Map<AbstractInsnNode, Instruction> map = builder.getInstructions();
    assertEquals(CounterImpl.COUNTER_0_1, map.get(i1).getInstructionCounter());
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Label(org.objectweb.asm.Label) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) Test(org.junit.Test)

Example 82 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.

the class MethodCoverageCalculatorTest method should_replace_branches_with_merged_instructions.

@Test
public void should_replace_branches_with_merged_instructions() {
    InsnNode i1 = addInsn(1, false, false, false);
    InsnNode i2 = addInsn(2, true);
    InsnNode i3 = addInsn(2, false);
    InsnNode i4 = addInsn(2, false);
    MethodCoverageCalculator c = new MethodCoverageCalculator(instructions);
    c.merge(i4, i3);
    c.merge(i3, i2);
    c.replaceBranches(i1, new HashSet<AbstractInsnNode>(Arrays.asList(i2, i3, i4)));
    c.calculate(coverage);
    assertLine(1, 0, 1, 0, 3);
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) Test(org.junit.Test)

Example 83 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.

the class MethodCoverageCalculatorTest method setup.

@Before
public void setup() {
    instructions = new HashMap<AbstractInsnNode, Instruction>();
    coverage = new MethodCoverageImpl("run", "()V", null);
    list = new InsnList();
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList) Before(org.junit.Before)

Example 84 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.

the class MethodCoverageCalculator method applyMerges.

private void applyMerges() {
    // Merge to the representative:
    for (final Entry<AbstractInsnNode, AbstractInsnNode> entry : merged.entrySet()) {
        final AbstractInsnNode node = entry.getKey();
        final Instruction instruction = instructions.get(node);
        final AbstractInsnNode representativeNode = findRepresentative(node);
        ignored.add(node);
        instructions.put(representativeNode, instructions.get(representativeNode).merge(instruction));
        entry.setValue(representativeNode);
    }
    // Get merged value back from representative
    for (final Entry<AbstractInsnNode, AbstractInsnNode> entry : merged.entrySet()) {
        instructions.put(entry.getKey(), instructions.get(entry.getValue()));
    }
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 85 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.

the class SynchronizedFilter method filter.

public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) {
    for (final TryCatchBlockNode tryCatch : methodNode.tryCatchBlocks) {
        if (tryCatch.type != null) {
            continue;
        }
        if (tryCatch.start == tryCatch.handler) {
            continue;
        }
        final AbstractInsnNode to = new Matcher(tryCatch.handler).match();
        if (to == null) {
            continue;
        }
        output.ignore(tryCatch.handler, to);
    }
}
Also used : TryCatchBlockNode(org.objectweb.asm.tree.TryCatchBlockNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Aggregations

AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)185 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)68 MethodNode (org.objectweb.asm.tree.MethodNode)54 InsnList (org.objectweb.asm.tree.InsnList)53 InsnNode (org.objectweb.asm.tree.InsnNode)41 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)38 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)37 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)35 ClassNode (org.objectweb.asm.tree.ClassNode)33 LabelNode (org.objectweb.asm.tree.LabelNode)27 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)26 Test (org.junit.Test)25 Label (org.objectweb.asm.Label)25 ClassReader (org.objectweb.asm.ClassReader)23 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)23 HashSet (java.util.HashSet)16 Type (org.objectweb.asm.Type)15 Frame (org.objectweb.asm.tree.analysis.Frame)13 ArrayList (java.util.ArrayList)12 TryCatchBlockNode (org.objectweb.asm.tree.TryCatchBlockNode)11