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

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

Introduction

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

Prototype

public MethodNode(final int api, final int access, final String name, final String descriptor,
        final String signature, final String[] exceptions) 

Source Link

Document

Constructs a new MethodNode .

Usage

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_immutables_value_Generated() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);

    m.visitInsn(Opcodes.ICONST_0);//w  ww. j  av  a2s.  c  o m
    m.visitInsn(Opcodes.IRETURN);

    context.classAnnotations.add("Lorg/immutables/value/Generated;");

    filter.filter(m, context, output);

    assertMethodIgnored(m);
}

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);//from  ww w .  ja v a2 s . c o  m

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

    filter.filter(m, context, output);

    assertMethodIgnored(m);
}

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

License:Open Source License

@Test
public void should_filter_when_annotation_is_inner() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);

    m.visitInsn(Opcodes.ICONST_0);//w ww .  j  av a 2 s  .  com
    m.visitInsn(Opcodes.IRETURN);

    context.classAnnotations.add("Lorg/example/Class$Generated;");

    filter.filter(m, context, output);

    assertMethodIgnored(m);
}

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

License:Open Source License

@Test
public void should_not_filter_when_no_annotations() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);

    m.visitInsn(Opcodes.ICONST_0);/*from  w  w  w  .  jav a 2  s  . c o m*/
    m.visitInsn(Opcodes.IRETURN);

    filter.filter(m, context, output);

    assertIgnored();
}

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

License:Open Source License

@Test
public void should_not_filter_when_other_annotations() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);
    m.visitAnnotation("LOtherAnnotation;", true);

    m.visitInsn(Opcodes.ICONST_0);/*from   w ww . ja va  2 s  . c om*/
    m.visitInsn(Opcodes.IRETURN);

    context.classAnnotations.add("LOtherAnnotation;");

    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_filter() {
    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);//from   w w  w  .  j a v a  2 s . c o  m
    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.RETURN);
    context.superClassName = "java/lang/Enum";

    filter.filter(m, context, output);

    assertIgnored(new Range(m.instructions.getFirst(), m.instructions.getLast()));
}

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

License:Open Source License

/**
 * <code><pre>/* w  w  w .j av  a 2  s. co m*/
 * 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>/*  ww  w. j a  v a2 s  . c  o m*/
 * enum E {
 *   ;
 *   private E(long p) {
 *   }
 * }
 * </pre></code>
 */
@Test
public void should_not_filter_constructor_with_additional_parameters() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_PRIVATE, "<init>",
            "(Ljava/lang/String;IJ)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.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>//  ww w  .jav  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);//from w  w  w  . jav  a 2  s.c  om

    filter.filter(m, context, output);

    assertIgnored();
}