Example usage for org.objectweb.asm Opcodes NOP

List of usage examples for org.objectweb.asm Opcodes NOP

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes NOP.

Prototype

int NOP

To view the source code for org.objectweb.asm Opcodes NOP.

Click Source Link

Usage

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

License:Open Source License

@Test
public void should_filter_suspending_lambdas_generated_by_Kotlin_1_3_30() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "invokeSuspend",
            "(Ljava/lang/Object;)Ljava/lang/Object;", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    m.visitLabel(new Label());
    final Range range1 = new Range();
    range1.fromInclusive = m.instructions.getLast();
    m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/coroutines/intrinsics/IntrinsicsKt",
            "getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false);
    m.visitVarInsn(Opcodes.ASTORE, 4);/*  w w  w .  j a  v a2 s  .c  om*/

    m.visitVarInsn(Opcodes.ALOAD, 0);
    // line of "runBlocking"
    m.visitFieldInsn(Opcodes.GETFIELD, "Target", "label", "I");
    final Label dflt = new Label();
    final Label state0 = new Label();
    final Label state1 = new Label();
    m.visitTableSwitchInsn(0, 1, dflt, state0, state1);

    m.visitLabel(state0);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/ResultKt", "throwOnFailure", "(Ljava/lang/Object;)V",
                false);
        range1.toInclusive = m.instructions.getLast();
    }

    // line before "suspendingFunction"
    m.visitInsn(Opcodes.NOP);

    // line of "suspendingFunction"
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "", "suspendingFunction",
            "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", false);

    m.visitInsn(Opcodes.DUP);
    final Range range2 = new Range();
    range2.fromInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ALOAD, 4);
    final Label continuationLabelAfterLoadedResult = new Label();
    m.visitJumpInsn(Opcodes.IF_ACMPNE, continuationLabelAfterLoadedResult);
    // line of "runBlocking"
    m.visitVarInsn(Opcodes.ALOAD, 4);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(state1);

    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitFieldInsn(Opcodes.GETFIELD, "Target", "I$0", "I");
    m.visitVarInsn(Opcodes.ISTORE, 3);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/ResultKt", "throwOnFailure", "(Ljava/lang/Object;)V",
                false);
    }
    m.visitVarInsn(Opcodes.ALOAD, 1);
    range2.toInclusive = m.instructions.getLast();
    m.visitLabel(continuationLabelAfterLoadedResult);

    // line after "suspendingFunction"
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(dflt);
    final Range range0 = new Range();
    range0.fromInclusive = m.instructions.getLast();
    m.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
    m.visitInsn(Opcodes.DUP);
    m.visitLdcInsn("call to 'resume' before 'invoke' with coroutine");
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>",
            "(Ljava/lang/String;)V", false);
    m.visitInsn(Opcodes.ATHROW);
    range0.toInclusive = m.instructions.getLast();

    filter.filter(m, context, output);

    assertIgnored(range0, range1, range2);
}

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

License:Open Source License

/**
 * <pre>/*from w w  w.j a  va  2  s . com*/
 *     runBlocking {
 *         val x = 42
 *         nop(x)
 *         suspendingFunction()
 *         nop(x)
 *     }
 * </pre>
 */
@Test
public void should_filter_suspending_lambdas() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "invokeSuspend",
            "(Ljava/lang/Object;)Ljava/lang/Object;", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    m.visitLabel(new Label());
    final Range range1 = new Range();
    range1.fromInclusive = m.instructions.getLast();
    m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/coroutines/intrinsics/IntrinsicsKt",
            "getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false);
    m.visitVarInsn(Opcodes.ASTORE, 4);

    m.visitVarInsn(Opcodes.ALOAD, 0);
    // line of "runBlocking"
    m.visitFieldInsn(Opcodes.GETFIELD, "Target", "label", "I");
    final Label dflt = new Label();
    final Label state0 = new Label();
    final Label state1 = new Label();
    m.visitTableSwitchInsn(0, 1, dflt, state0, state1);

    m.visitLabel(state0);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitInsn(Opcodes.DUP);
        m.visitTypeInsn(Opcodes.INSTANCEOF, "kotlin/Result$Failure");
        Label label = new Label();
        m.visitJumpInsn(Opcodes.IFEQ, label);
        m.visitTypeInsn(Opcodes.CHECKCAST, "kotlin/Result$Failure");
        m.visitFieldInsn(Opcodes.GETFIELD, "kotlin/Result$Failure", "exception", "Ljava/lang/Throwable");
        m.visitInsn(Opcodes.ATHROW);
        m.visitInsn(Opcodes.POP);
        range1.toInclusive = m.instructions.getLast();
        m.visitLabel(label);
    }

    // line before "suspendingFunction"
    m.visitInsn(Opcodes.NOP);

    // line of "suspendingFunction"
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "", "suspendingFunction",
            "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", false);

    m.visitInsn(Opcodes.DUP);
    final Range range2 = new Range();
    range2.fromInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ALOAD, 4);
    final Label continuationLabelAfterLoadedResult = new Label();
    m.visitJumpInsn(Opcodes.IF_ACMPNE, continuationLabelAfterLoadedResult);
    // line of "runBlocking"
    m.visitVarInsn(Opcodes.ALOAD, 4);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(state1);

    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitFieldInsn(Opcodes.GETFIELD, "Target", "I$0", "I");
    m.visitVarInsn(Opcodes.ISTORE, 3);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitInsn(Opcodes.DUP);
        m.visitTypeInsn(Opcodes.INSTANCEOF, "kotlin/Result$Failure");
        final Label label = new Label();
        m.visitJumpInsn(Opcodes.IFEQ, label);
        m.visitTypeInsn(Opcodes.CHECKCAST, "kotlin/Result$Failure");
        m.visitFieldInsn(Opcodes.GETFIELD, "kotlin/Result$Failure", "exception", "Ljava/lang/Throwable");
        m.visitInsn(Opcodes.ATHROW);
        m.visitInsn(Opcodes.POP);
        m.visitLabel(label);
    }
    m.visitVarInsn(Opcodes.ALOAD, 1);
    range2.toInclusive = m.instructions.getLast();
    m.visitLabel(continuationLabelAfterLoadedResult);

    // line after "suspendingFunction"
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(dflt);
    final Range range0 = new Range();
    range0.fromInclusive = m.instructions.getLast();
    m.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
    m.visitInsn(Opcodes.DUP);
    m.visitLdcInsn("call to 'resume' before 'invoke' with coroutine");
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>",
            "(Ljava/lang/String;)V", false);
    m.visitInsn(Opcodes.ATHROW);
    range0.toInclusive = m.instructions.getLast();

    filter.filter(m, context, output);

    assertIgnored(range0, range1, range2);
}

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

License:Open Source License

/**
 * <pre>/*from  w  w  w .  ja v  a2  s .  c  om*/
 *     suspend fun example() {
 *         suspendingFunction()
 *         nop()
 *     }
 * </pre>
 */
@Test
public void should_filter_suspending_functions() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_STATIC, "example",
            "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    final int continuationArgumentIndex = 0;
    final int continuationIndex = 2;

    m.visitVarInsn(Opcodes.ALOAD, continuationArgumentIndex);
    final Range range1 = new Range();
    range1.fromInclusive = m.instructions.getLast();
    m.visitTypeInsn(Opcodes.INSTANCEOF, "ExampleKt$example$1");
    final Label createStateInstance = new Label();
    m.visitJumpInsn(Opcodes.IFEQ, createStateInstance);

    m.visitVarInsn(Opcodes.ALOAD, continuationArgumentIndex);
    m.visitTypeInsn(Opcodes.CHECKCAST, "ExampleKt$example$1");
    m.visitVarInsn(Opcodes.ASTORE, continuationIndex);

    m.visitVarInsn(Opcodes.ALOAD, continuationIndex);
    m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "label", "I");

    m.visitLdcInsn(Integer.valueOf(Integer.MIN_VALUE));
    m.visitInsn(Opcodes.IAND);
    m.visitJumpInsn(Opcodes.IFEQ, createStateInstance);

    m.visitVarInsn(Opcodes.ALOAD, continuationIndex);
    m.visitInsn(Opcodes.DUP);
    m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "label", "I");

    m.visitLdcInsn(Integer.valueOf(Integer.MIN_VALUE));
    m.visitInsn(Opcodes.ISUB);
    m.visitFieldInsn(Opcodes.PUTFIELD, "ExampleKt$example$1", "label", "I");

    final Label afterCoroutineStateCreated = new Label();
    m.visitJumpInsn(Opcodes.GOTO, afterCoroutineStateCreated);

    m.visitLabel(createStateInstance);

    m.visitTypeInsn(Opcodes.NEW, "ExampleKt$example$1");
    m.visitInsn(Opcodes.DUP);
    m.visitVarInsn(Opcodes.ALOAD, continuationArgumentIndex);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "ExampleKt$example$1", "<init>",
            "(Lkotlin/coroutines/Continuation;)V", false);

    m.visitVarInsn(Opcodes.ASTORE, continuationIndex);

    m.visitLabel(afterCoroutineStateCreated);

    m.visitVarInsn(Opcodes.ALOAD, continuationIndex);
    m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "result", "Ljava/lang/Object;");
    m.visitVarInsn(Opcodes.ASTORE, 1);

    m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/coroutines/intrinsics/IntrinsicsKt",
            "getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false);

    // line of "fun"
    m.visitVarInsn(Opcodes.ASTORE, 3);

    m.visitVarInsn(Opcodes.ALOAD, continuationIndex);
    m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "label", "I");
    final Label dflt = new Label();
    final Label state0 = new Label();
    final Label state1 = new Label();
    m.visitTableSwitchInsn(0, 1, dflt, state0, state1);

    m.visitLabel(state0);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitInsn(Opcodes.DUP);
        m.visitTypeInsn(Opcodes.INSTANCEOF, "kotlin/Result$Failure");
        Label label = new Label();
        m.visitJumpInsn(Opcodes.IFEQ, label);
        m.visitTypeInsn(Opcodes.CHECKCAST, "kotlin/Result$Failure");
        m.visitFieldInsn(Opcodes.GETFIELD, "kotlin/Result$Failure", "exception", "Ljava/lang/Throwable");
        m.visitInsn(Opcodes.ATHROW);
        m.visitInsn(Opcodes.POP);
        range1.toInclusive = m.instructions.getLast();
        m.visitLabel(label);
    }

    // line of "suspendingFunction"
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "", "suspendingFunction",
            "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", false);

    m.visitInsn(Opcodes.DUP);
    final Range range2 = new Range();
    range2.fromInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ALOAD, 3);
    final Label continuationLabelAfterLoadedResult = new Label();
    m.visitJumpInsn(Opcodes.IF_ACMPNE, continuationLabelAfterLoadedResult);
    // line of "fun"
    m.visitVarInsn(Opcodes.ALOAD, 3);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(state1);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitInsn(Opcodes.DUP);
        m.visitTypeInsn(Opcodes.INSTANCEOF, "kotlin/Result$Failure");
        final Label label = new Label();
        m.visitJumpInsn(Opcodes.IFEQ, label);
        m.visitTypeInsn(Opcodes.CHECKCAST, "kotlin/Result$Failure");
        m.visitFieldInsn(Opcodes.GETFIELD, "kotlin/Result$Failure", "exception", "Ljava/lang/Throwable");
        m.visitInsn(Opcodes.ATHROW);
        m.visitInsn(Opcodes.POP);
        m.visitLabel(label);
    }
    m.visitVarInsn(Opcodes.ALOAD, 1);
    range2.toInclusive = m.instructions.getLast();
    m.visitLabel(continuationLabelAfterLoadedResult);

    // line after "suspendingFunction"
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(dflt);
    final Range range0 = new Range();
    range0.fromInclusive = m.instructions.getLast();
    m.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
    m.visitInsn(Opcodes.DUP);
    m.visitLdcInsn("call to 'resume' before 'invoke' with coroutine");
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>",
            "(Ljava/lang/String;)V", false);
    m.visitInsn(Opcodes.ATHROW);
    range0.toInclusive = m.instructions.getLast();

    filter.filter(m, context, output);

    assertIgnored(range0, range1, range2);
}

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

License:Open Source License

@Test
public void should_filter() {
    context.sourceFileName = "callsite.kt";
    context.sourceDebugExtension = "" //
            + "SMAP\n" //
            + "callsite.kt\n" // OutputFileName=callsite.kt
            + "Kotlin\n" // DefaultStratumId=Kotlin
            + "*S Kotlin\n" // StratumID=Kotlin
            + "*F\n" // FileSection
            + "+ 1 callsite.kt\n" // FileID=1,FileName=callsite.kt
            + "CallsiteKt\n" //
            + "+ 2 a.kt\n" // FileID=2,FileName=a.kt
            + "AKt\n" //
            + "+ 3 b.kt\n" // FileID=3,FileName=b.kt
            + "BKt\n" //
            + "*L\n" // LineSection
            + "1#1,8:1\n" // InputStartLine=1,LineFileID=1,RepeatCount=8,OutputStartLine=1
            + "2#2,2:9\n" // InputStartLine=2,LineFileID=2,RepeatCount=2,OutputStartLine=9
            + "2#3,2:11\n" // InputStartLine=2,LineFileID=3,RepeatCount=2,OutputStartLine=11
            + "*E\n"; // EndSection
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    m.visitLineNumber(2, new Label());
    m.visitInsn(Opcodes.NOP);

    m.visitLineNumber(9, new Label());
    shouldIgnorePrevious(m);/*from   www .ja v a 2s . c o m*/
    m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false);
    shouldIgnorePrevious(m);
    m.visitLineNumber(10, new Label());
    shouldIgnorePrevious(m);
    m.visitInsn(Opcodes.NOP);
    shouldIgnorePrevious(m);

    m.visitLineNumber(3, new Label());
    m.visitInsn(Opcodes.NOP);

    m.visitLineNumber(11, new Label());
    shouldIgnorePrevious(m);
    m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false);
    shouldIgnorePrevious(m);
    m.visitLineNumber(12, new Label());
    shouldIgnorePrevious(m);
    m.visitInsn(Opcodes.NOP);
    shouldIgnorePrevious(m);

    m.visitLineNumber(4, new Label());
    m.visitInsn(Opcodes.RETURN);

    filter.filter(m, context, output);

    assertIgnored(expectedRanges.toArray(new Range[0]));

    // should not reparse:
    context.sourceDebugExtension = "";
    filter.filter(m, context, output);
}

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

License:Open Source License

/**
 * <pre>//w ww .  j  ava  2 s . co m
 *     inline fun inlined_top_level() {
 *       Stubs.nop()
 *     }
 *
 *     class Callsite {
 *       fun inlined() {
 *           Stubs.nop()
 *       }
 *
 *       fun callsite {
 *         inlined_top_level()
 *         inlined()
 *       }
 *     }
 * </pre>
 */
@Test
public void should_filter_when_in_same_file() {
    context.sourceFileName = "example.kt";
    context.sourceDebugExtension = "" //
            + "SMAP\n" //
            + "example.kt\n" // OutputFileName=example.kt
            + "Kotlin\n" // DefaultStratumId=Kotlin
            + "*S Kotlin\n" // StratumID=Kotlin
            + "*F\n" // FileSection
            + "+ 1 example.kt\n" // FileID=1,FileName=example.kt
            + "Callsite\n" //
            + "+ 2 example.kt\n" // FileID=2,FileName=example.kt
            + "ExampleKt\n" //
            + "*L\n" // LineSection
            + "1#1,15:1\n" // InputStartLine=1,LineFileID=1,RepeatCount=10,OutputStartLine=1
            + "7#1,2:18\n" // InputStartLine=7,LineFileID=1,RepeatCount=2,OutputStartLine=18
            + "2#2,2:16\n" // InputStartLine=2,LineFileID=2,RepeatCount=2,OutputStartLine=16
            + "*E\n"; // EndSection
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    m.visitLineNumber(11, new Label());
    m.visitInsn(Opcodes.NOP);
    m.visitLineNumber(16, new Label());
    shouldIgnorePrevious(m);
    m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false);
    shouldIgnorePrevious(m);
    m.visitLineNumber(17, new Label());
    shouldIgnorePrevious(m);
    m.visitInsn(Opcodes.NOP);
    shouldIgnorePrevious(m);

    m.visitLineNumber(12, new Label());
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitVarInsn(Opcodes.ASTORE, 1);
    m.visitLineNumber(18, new Label());
    shouldIgnorePrevious(m);
    m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false);
    shouldIgnorePrevious(m);
    m.visitLineNumber(19, new Label());
    shouldIgnorePrevious(m);
    m.visitInsn(Opcodes.NOP);
    shouldIgnorePrevious(m);

    m.visitLineNumber(13, new Label());
    m.visitInsn(Opcodes.RETURN);

    filter.filter(m, context, output);

    assertIgnored(expectedRanges.toArray(new Range[0]));
}

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

License:Open Source License

@Test
public void should_filter_implicit_else() {
    final Label label = new Label();

    final Range range1 = new Range();

    m.visitInsn(Opcodes.NOP);

    m.visitJumpInsn(Opcodes.IFEQ, label);
    range1.fromInclusive = m.instructions.getLast();
    range1.toInclusive = m.instructions.getLast();

    m.visitInsn(Opcodes.NOP);//w w w. ja  va2s . c om

    final Range range2 = new Range();
    m.visitLabel(label);
    range2.fromInclusive = m.instructions.getLast();
    m.visitTypeInsn(Opcodes.NEW, "kotlin/NoWhenBranchMatchedException");
    m.visitInsn(Opcodes.DUP);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "kotlin/NoWhenBranchMatchedException", "<init>", "()V", false);
    m.visitInsn(Opcodes.ATHROW);
    range2.toInclusive = m.instructions.getLast();

    filter.filter(m, context, output);

    assertIgnored(range1, range2);
    assertNoReplacedBranches();
}

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

License:Open Source License

@Test
public void should_not_filter_explicit_else() {
    final Label label = new Label();

    m.visitInsn(Opcodes.NOP);

    m.visitJumpInsn(Opcodes.IFEQ, label);

    m.visitInsn(Opcodes.NOP);/*from ww  w  .  ja v  a 2s. c  o  m*/

    m.visitLabel(label);
    m.visitTypeInsn(Opcodes.NEW, "kotlin/NoWhenBranchMatchedException");
    m.visitInsn(Opcodes.DUP);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "kotlin/NoWhenBranchMatchedException", "<init>", "()V", false);
    m.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Throwable");
    m.visitInsn(Opcodes.ATHROW);

    filter.filter(m, context, output);

    assertIgnored();
    assertNoReplacedBranches();
}

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

License:Open Source License

@Test
public void should_filter_implicit_default() {
    final Label case1 = new Label();
    final Label caseDefault = new Label();
    final Label after = new Label();

    m.visitInsn(Opcodes.NOP);

    m.visitTableSwitchInsn(0, 0, caseDefault, case1);
    final AbstractInsnNode switchNode = m.instructions.getLast();
    final Set<AbstractInsnNode> newTargets = new HashSet<AbstractInsnNode>();

    m.visitLabel(case1);
    m.visitInsn(Opcodes.ICONST_1);//from ww  w  .j a v a 2s .  c o  m
    newTargets.add(m.instructions.getLast());
    m.visitJumpInsn(Opcodes.GOTO, after);

    final Range range1 = new Range();
    m.visitLabel(caseDefault);
    range1.fromInclusive = m.instructions.getLast();
    m.visitTypeInsn(Opcodes.NEW, "kotlin/NoWhenBranchMatchedException");
    m.visitInsn(Opcodes.DUP);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "kotlin/NoWhenBranchMatchedException", "<init>", "()V", false);
    m.visitInsn(Opcodes.ATHROW);
    range1.toInclusive = m.instructions.getLast();

    m.visitLabel(after);

    filter.filter(m, context, output);

    assertIgnored(range1);
    assertReplacedBranches(switchNode, newTargets);
}

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

License:Open Source License

@Test
public void javac() {
    final Label start = new Label();
    final Label end = new Label();
    final Label handler = new Label();
    final Label handlerEnd = new Label();
    m.visitTryCatchBlock(start, end, handler, null);
    m.visitTryCatchBlock(handler, handlerEnd, handler, null);

    m.visitVarInsn(Opcodes.ALOAD, 0);//from  ww  w.j  a va 2 s .  c o  m
    m.visitFieldInsn(Opcodes.GETFIELD, "Fun", "lock", "Ljava/lang/Object;");
    m.visitInsn(Opcodes.DUP);
    m.visitVarInsn(Opcodes.ASTORE, 1);
    m.visitInsn(Opcodes.MONITORENTER);
    m.visitLabel(start);
    m.visitInsn(Opcodes.NOP);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitInsn(Opcodes.MONITOREXIT);
    m.visitLabel(end);
    final Label exit = new Label();
    m.visitJumpInsn(Opcodes.GOTO, exit);
    m.visitLabel(handler);
    m.visitVarInsn(Opcodes.ASTORE, 2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitInsn(Opcodes.MONITOREXIT);
    m.visitLabel(handlerEnd);
    m.visitVarInsn(Opcodes.ALOAD, 2);
    m.visitInsn(Opcodes.ATHROW);
    m.visitLabel(exit);
    m.visitInsn(Opcodes.RETURN);

    filter.filter(m, context, output);

    assertIgnored(new Range((LabelNode) handler.info, ((LabelNode) exit.info).getPrevious()));
}

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

License:Open Source License

/**
 * <pre>/*from  w  ww .j a  v  a 2  s .  c om*/
 *     try {
 *         ...
 *     } catch (Exception e) {
 *         ...
 *     } finally {
 *         ...
 *     }
 * </pre>
 */
@Test
public void javacTryCatchFinally() {
    final Label start = new Label();
    final Label end = new Label();
    final Label catchHandler = new Label();
    final Label finallyHandler = new Label();
    final Label catchHandlerEnd = new Label();
    m.visitTryCatchBlock(start, end, catchHandler, "java/lang/Exception");
    m.visitTryCatchBlock(start, end, finallyHandler, null);
    m.visitTryCatchBlock(catchHandler, catchHandlerEnd, finallyHandler, null);

    m.visitLabel(start);
    // body
    m.visitInsn(Opcodes.NOP);
    m.visitLabel(end);
    // finally
    m.visitInsn(Opcodes.NOP);
    final Label exit = new Label();
    m.visitJumpInsn(Opcodes.GOTO, exit);
    m.visitLabel(catchHandler);
    m.visitVarInsn(Opcodes.ASTORE, 1);
    // catch
    m.visitInsn(Opcodes.NOP);
    m.visitLabel(catchHandlerEnd);
    // finally
    m.visitInsn(Opcodes.NOP);
    m.visitJumpInsn(Opcodes.GOTO, exit);
    m.visitLabel(finallyHandler);
    m.visitVarInsn(Opcodes.ASTORE, 2);
    // finally
    m.visitInsn(Opcodes.NOP);
    m.visitVarInsn(Opcodes.ALOAD, 2);
    m.visitInsn(Opcodes.ATHROW);
    m.visitLabel(exit);
    m.visitInsn(Opcodes.RETURN);

    filter.filter(m, context, output);

    assertIgnored();
}