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.AbstractMatcherTest.java

License:Open Source License

@Test
public void nextIsInvoke() {
    m.visitInsn(Opcodes.NOP);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "owner", "name", "()V", false);

    // should set cursor to null when opcode mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKESTATIC, "owner", "name", "()V");
    assertNull(matcher.cursor);/*from  www.  ja  v  a2 s .  c  om*/

    // should set cursor to null when owner mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "another_owner", "name", "()V");
    assertNull(matcher.cursor);

    // should set cursor to null when name mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "owner", "another_name", "()V");
    assertNull(matcher.cursor);

    // should set cursor to null when descriptor mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "owner", "name", "(Lanother_descriptor;)V");
    assertNull(matcher.cursor);

    // should set cursor to next instruction when match
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "owner", "name", "()V");
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should not do anything when cursor is null
    matcher.cursor = null;
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "owner", "name", "()V");
}

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

License:Open Source License

@Test
public void nextIsType() {
    m.visitInsn(Opcodes.NOP);
    m.visitTypeInsn(Opcodes.NEW, "descriptor");

    // should set cursor to null when opcode mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsType(Opcodes.CHECKCAST, "descriptor");
    assertNull(matcher.cursor);//from www .  j  av  a  2s .  co m

    // should set cursor to null when descriptor mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsType(Opcodes.NEW, "another_descriptor");
    assertNull(matcher.cursor);

    // should set cursor to next instruction when match
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsType(Opcodes.NEW, "descriptor");
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should not do anything when cursor is null
    matcher.cursor = null;
    matcher.nextIsType(Opcodes.NEW, "descriptor");
}

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

License:Open Source License

@Test
public void firstIsALoad0() {
    // should set cursor to null when opcode mismatch
    m.visitInsn(Opcodes.NOP);
    matcher.firstIsALoad0(m);//w w  w .  ja v  a  2 s . com
    assertNull(matcher.cursor);

    // should set cursor to null when var mismatch
    m.instructions.clear();
    m.visitVarInsn(Opcodes.ALOAD, 1);
    matcher.firstIsALoad0(m);
    assertNull(matcher.cursor);

    // should set cursor to first instruction when match
    m.instructions.clear();
    m.visitVarInsn(Opcodes.ALOAD, 0);
    matcher.firstIsALoad0(m);
    assertSame(m.instructions.getLast(), matcher.cursor);
}

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

License:Open Source License

@Test
public void should_filter_classes_annotated_with_runtime_visible_org_apache_avro_specific_AvroGenerated() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "readExternal", "()V", null, null);

    m.visitInsn(Opcodes.NOP);

    context.classAnnotations.add("Lorg/apache/avro/specific/AvroGenerated;");

    filter.filter(m, context, output);//from w  w  w.j a va 2s .  c o  m

    assertMethodIgnored(m);
}

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

License:Open Source License

/**
 * <code><pre>//from   w ww . j  a v a 2 s  .  c om
 * enum E {
 *   ;
 *   private E() {
 *     ...
 *   }
 * }
 * </pre></code>
 */
@Test
public void should_not_filter_non_empty_constructor() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_PRIVATE, "<init>",
            "(Ljava/lang/String;I)V", null, null);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitVarInsn(Opcodes.ILOAD, 2);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Enum", "<init>", "(Ljava/lang/String;I)V", false);
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.RETURN);
    context.superClassName = "java/lang/Enum";

    filter.filter(m, context, output);

    assertIgnored();
}

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

License:Open Source License

/**
 * <code><pre>/* www  .  ja  v a 2 s .c  o m*/
 * enum E {
 *   ;
 *   private void method(String p1, int p2) {
 *   }
 * }
 * </pre></code>
 */
@Test
public void should_not_filter_non_constructor() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_PRIVATE, "method",
            "(Ljava/lang/String;I)V", null, null);
    m.visitInsn(Opcodes.NOP);
    context.superClassName = "java/lang/Enum";

    filter.filter(m, context, output);

    assertIgnored();
}

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

License:Open Source License

@Test
public void should_not_filter_non_Enum() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_PRIVATE, "<init>",
            "(Ljava/lang/String;I)V", null, null);
    m.visitInsn(Opcodes.NOP);

    filter.filter(m, context, output);/*w  ww  .ja  v a2 s  .c o m*/

    assertIgnored();
}

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

License:Open Source License

@Test
public void testValues() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "values", "()[LFoo;", null, null);
    m.visitInsn(Opcodes.NOP);
    context.superClassName = "java/lang/Enum";

    filter.filter(m, context, output);//from w w w .  j a va  2s.  com

    assertMethodIgnored(m);
}

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

License:Open Source License

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

    filter.filter(m, context, output);/*from w  ww.j av a  2 s  .  com*/

    assertIgnored();
}

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

License:Open Source License

@Test
public void testValueOf() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "valueOf", "(Ljava/lang/String;)LFoo;",
            null, null);//  w  ww .j a va 2 s .  co  m
    m.visitInsn(Opcodes.NOP);
    context.superClassName = "java/lang/Enum";

    filter.filter(m, context, output);

    assertMethodIgnored(m);
}