Example usage for org.objectweb.asm.tree MethodNode visitInsn

List of usage examples for org.objectweb.asm.tree MethodNode visitInsn

Introduction

In this page you can find the example usage for org.objectweb.asm.tree MethodNode visitInsn.

Prototype

@Override
    public void visitInsn(final int opcode) 

Source Link

Usage

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

License:Open Source License

@Test
public void should_filter_when_default_is_first() {
    final Set<AbstractInsnNode> expectedNewTargets = new HashSet<AbstractInsnNode>();

    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "name", "()V", null, null);

    final Label case1 = new Label();
    final Label caseDefault = new Label();
    final Label h1 = new Label();

    // filter should not remember this unrelated slot
    m.visitLdcInsn("");
    m.visitVarInsn(Opcodes.ASTORE, 1);/*from   w w  w.j  av  a 2 s .c  o  m*/
    m.visitVarInsn(Opcodes.ALOAD, 1);

    // switch (...)
    m.visitInsn(Opcodes.DUP);
    m.visitVarInsn(Opcodes.ASTORE, 2);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);
    m.visitLookupSwitchInsn(caseDefault, new int[] { 97 }, new Label[] { h1 });
    final AbstractInsnNode switchNode = m.instructions.getLast();

    m.visitLabel(h1);

    m.visitVarInsn(Opcodes.ALOAD, 2);
    m.visitLdcInsn("a");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if equal "a", then goto its case
    m.visitJumpInsn(Opcodes.IFNE, case1);

    final AbstractInsnNode expectedToInclusive = m.instructions.getLast();

    m.visitLabel(caseDefault);
    m.visitInsn(Opcodes.RETURN);
    expectedNewTargets.add(m.instructions.getLast());
    m.visitLabel(case1);
    m.visitInsn(Opcodes.RETURN);
    expectedNewTargets.add(m.instructions.getLast());

    filter.filter(m, context, output);

    assertReplacedBranches(switchNode, expectedNewTargets);
    assertIgnored(new Range(switchNode.getNext(), expectedToInclusive));
}

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

License:Open Source License

@Test
public void should_not_filter_empty_lookup_switch() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "name", "(Ljava/lang/String;)V", null,
            null);//from  w ww .  j a  v  a2s.  co  m
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitVarInsn(Opcodes.ASTORE, 2);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);
    final Label defaultCase = new Label();
    m.visitLookupSwitchInsn(defaultCase, null, new Label[] {});
    m.visitLabel(defaultCase);
    m.visitInsn(Opcodes.RETURN);

    filter.filter(m, context, output);

    assertIgnored();
}

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

License:Open Source License

@Test
public void testNonSynthetic() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "name", "()V", null, null);
    m.visitInsn(Opcodes.NOP);

    filter.filter(m, context, output);/*from  www  . ja  v  a  2s . co m*/

    assertIgnored();
}

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

License:Open Source License

@Test
public void testSynthetic() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "name", "()V",
            null, null);/*from w w w . j av a 2 s .  c o  m*/
    m.visitInsn(Opcodes.NOP);

    filter.filter(m, context, output);

    assertMethodIgnored(m);
}

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

License:Open Source License

@Test
public void testLambda() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "lambda$1", "()V",
            null, null);/*from   w w  w .  ja  v  a 2  s . co m*/
    m.visitInsn(Opcodes.NOP);

    filter.filter(m, context, output);

    assertIgnored();
}

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

License:Open Source License

@Test
public void should_filter_synthetic_method_with_prefix_anonfun_in_non_Scala_classes() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "$anonfun$main$1",
            "()V", null, null);
    m.visitInsn(Opcodes.RETURN);

    filter.filter(m, context, output);//from www  . j  a  v  a 2 s  .c  o  m
    assertMethodIgnored(m);
}

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

License:Open Source License

@Test
public void should_not_filter_synthetic_method_with_prefix_anonfun_in_Scala_classes() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "$anonfun$main$1",
            "()V", null, null);
    m.visitInsn(Opcodes.RETURN);

    context.classAttributes.add("ScalaSig");
    filter.filter(m, context, output);//from w w w .  j  a  v  a2  s  . c  o  m
    assertIgnored();
}

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

License:Open Source License

@Test
public void should_not_filter_synthetic_method_with_prefix_anonfun_in_Scala_inner_classes() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "$anonfun$main$1",
            "()V", null, null);
    m.visitInsn(Opcodes.RETURN);

    context.classAttributes.add("Scala");
    filter.filter(m, context, output);/*from   w  ww  .  j a  v  a  2  s .com*/
    assertIgnored();
}

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

License:Open Source License

@Test
public void should_not_filter_method_with_suffix_default_in_kotlin_classes() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
            Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE, "example$default",
            "(LTarget;Ljava/lang/String;Ijava/lang/Object;)V", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);
    m.visitInsn(Opcodes.NOP);

    filter.filter(m, context, output);//www . j  a v a2 s.  co  m

    assertIgnored();
}

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

License:Open Source License

@Test
public void should_filter_synthetic_method_with_suffix_default_in_non_kotlin_classes() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
            Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE, "example$default",
            "(LTarget;Ljava/lang/String;Ijava/lang/Object;)V", null, null);
    m.visitInsn(Opcodes.NOP);

    filter.filter(m, context, output);/*  w w  w.ja  va  2 s .c o m*/

    assertMethodIgnored(m);
}