Example usage for org.objectweb.asm Opcodes IRETURN

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

Introduction

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

Prototype

int IRETURN

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

Click Source Link

Usage

From source file:org.gradle.model.internal.manage.schema.extract.ManagedProxyClassGenerator.java

License:Apache License

private void writeHashCodeMethod(ClassVisitor visitor, Type generatedType) {
    MethodVisitor methodVisitor = declareMethod(visitor, "hashCode", HASH_CODE_METHOD_DESCRIPTOR, null);
    putStateFieldValueOnStack(methodVisitor, generatedType);
    methodVisitor.visitMethodInsn(INVOKEINTERFACE, GENERATED_VIEW_STATE_TYPE_NAME, "hashCode",
            HASH_CODE_METHOD_DESCRIPTOR, true);
    finishVisitingMethod(methodVisitor, Opcodes.IRETURN);
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedProxyClassGenerator.java

License:Apache License

private void writeEqualsMethod(ClassVisitor cw, Type generatedType) {
    MethodVisitor methodVisitor = cw.visitMethod(Opcodes.ACC_PUBLIC, "equals", EQUALS_METHOD_DESCRIPTOR, null,
            null);/*from   w ww.ja  v  a2  s.  co m*/
    methodVisitor.visitCode();

    // if (arg == this) { return true; }
    methodVisitor.visitVarInsn(ALOAD, 0);
    methodVisitor.visitVarInsn(ALOAD, 1);
    Label notSameLabel = new Label();
    methodVisitor.visitJumpInsn(IF_ACMPNE, notSameLabel);
    methodVisitor.visitInsn(ICONST_1);
    methodVisitor.visitInsn(IRETURN);

    // if (!(age instanceof GeneratedView)) { return false; }
    methodVisitor.visitLabel(notSameLabel);
    methodVisitor.visitVarInsn(ALOAD, 1);
    methodVisitor.visitTypeInsn(INSTANCEOF, GENERATED_VIEW_TYPE.getInternalName());
    Label generatedViewLabel = new Label();
    methodVisitor.visitJumpInsn(IFNE, generatedViewLabel);
    methodVisitor.visitInsn(ICONST_0);
    methodVisitor.visitInsn(IRETURN);

    // return state.equals(((GeneratedView)arg).__view_state());
    methodVisitor.visitLabel(generatedViewLabel);
    putStateFieldValueOnStack(methodVisitor, generatedType);
    methodVisitor.visitVarInsn(ALOAD, 1);
    methodVisitor.visitTypeInsn(CHECKCAST, GENERATED_VIEW_TYPE.getInternalName());
    methodVisitor.visitMethodInsn(INVOKEINTERFACE, GENERATED_VIEW_TYPE.getInternalName(), "__view_state__",
            GET_VIEW_STATE_METHOD_DESCRIPTOR, true);
    methodVisitor.visitMethodInsn(INVOKEINTERFACE, GENERATED_VIEW_STATE_TYPE_NAME, "equals",
            EQUALS_METHOD_DESCRIPTOR, true);
    finishVisitingMethod(methodVisitor, Opcodes.IRETURN);
}

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

License:Open Source License

@Test
public void should_filter_methods_annotated_with_runtime_visible_org_groovy_transform_Generated() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);
    m.visitAnnotation("Lgroovy/transform/Generated;", true);

    m.visitInsn(Opcodes.ICONST_0);//from   w w w .j ava  2  s.c  o  m
    m.visitInsn(Opcodes.IRETURN);

    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_methods_annotated_with_runtime_invisible_lombok_Generated() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);
    m.visitAnnotation("Llombok/Generated;", false);

    m.visitInsn(Opcodes.ICONST_0);//from w  ww . j  a  va 2  s. c  o  m
    m.visitInsn(Opcodes.IRETURN);

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

    m.visitInsn(Opcodes.ICONST_0);//from   ww w . j a  v  a  2  s . co 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_when_annotation_is_inner() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);

    m.visitInsn(Opcodes.ICONST_0);//w  w w.  jav  a  2 s.c  om
    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.  java 2  s. co 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  www  .  j  av a2  s .c o  m
    m.visitInsn(Opcodes.IRETURN);

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

    filter.filter(m, context, output);

    assertIgnored();
}

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

License:Open Source License

private static void filter(final IFilterOutput output, final List<TryCatchBlockNode> tryCatchBlocks,
        final TryCatchBlockNode catchAnyBlock) {
    final AbstractInsnNode e = next(catchAnyBlock.handler);
    final int size = size(e);
    if (size <= 0) {
        return;/*from w w w  . j  a  va2s  .c o  m*/
    }

    // Determine instructions inside regions
    final Set<AbstractInsnNode> inside = new HashSet<AbstractInsnNode>();
    for (final TryCatchBlockNode t : tryCatchBlocks) {
        if (t.handler == catchAnyBlock.handler) {
            AbstractInsnNode i = t.start;
            while (i != t.end) {
                inside.add(i);
                i = i.getNext();
            }
        }
    }

    // Find and merge duplicates at exits of regions
    for (final TryCatchBlockNode t : tryCatchBlocks) {
        if (t.handler == catchAnyBlock.handler) {
            boolean continues = false;
            AbstractInsnNode i = t.start;

            while (i != t.end) {
                switch (i.getType()) {
                case AbstractInsnNode.FRAME:
                case AbstractInsnNode.LINE:
                case AbstractInsnNode.LABEL:
                    break;
                case AbstractInsnNode.JUMP_INSN:
                    final AbstractInsnNode jumpTarget = next(((JumpInsnNode) i).label);
                    if (!inside.contains(jumpTarget)) {
                        merge(output, size, e, jumpTarget);
                    }
                    continues = i.getOpcode() != Opcodes.GOTO;
                    break;
                default:
                    switch (i.getOpcode()) {
                    case Opcodes.IRETURN:
                    case Opcodes.LRETURN:
                    case Opcodes.FRETURN:
                    case Opcodes.DRETURN:
                    case Opcodes.ARETURN:
                    case Opcodes.RETURN:
                    case Opcodes.ATHROW:
                        continues = false;
                        break;
                    default:
                        continues = true;
                        break;
                    }
                    break;
                }
                i = i.getNext();
            }

            i = next(i);
            if (continues && !inside.contains(i)) {
                merge(output, size, e, i);
            }
        }

        if (t != catchAnyBlock && t.start == catchAnyBlock.start && t.end == catchAnyBlock.end) {
            final AbstractInsnNode i = next(next(t.handler));
            if (!inside.contains(i)) {
                // javac's empty catch - merge after ASTORE
                merge(output, size, e, i);
            }
        }
    }
}

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

License:Open Source License

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

    m.visitInsn(Opcodes.ICONST_0);//from w w  w.  ja v  a 2s.  c om
    m.visitInsn(Opcodes.IRETURN);

    filter.filter("Foo", "java/lang/Object", m, this);

    assertNull(fromInclusive);
    assertNull(toInclusive);
}