Example usage for org.objectweb.asm.commons GeneratorAdapter getReturnType

List of usage examples for org.objectweb.asm.commons GeneratorAdapter getReturnType

Introduction

In this page you can find the example usage for org.objectweb.asm.commons GeneratorAdapter getReturnType.

Prototype

public Type getReturnType() 

Source Link

Usage

From source file:org.glowroot.agent.weaving.PointcutClassVisitor.java

License:Apache License

@Override
public void visitEnd() {
    if (onBeforeMethodVisitor != null) {
        int access = onBeforeMethodVisitor.access;
        String name = onBeforeMethodVisitor.name;
        String descriptor = "(Z" + onBeforeMethodVisitor.descriptor.substring(1);
        String signature = onBeforeMethodVisitor.signature;
        String[] exceptions = onBeforeMethodVisitor.exceptions;
        GeneratorAdapter mv = new GeneratorAdapter(
                cw.visitMethod(access, name, descriptor, signature, exceptions), access, name, descriptor);
        mv.visitCode();//from   w  w w .j a va 2  s.c o m
        mv.visitVarInsn(ILOAD, 0);
        Label endWithDefaultLabel = new Label();
        mv.visitJumpInsn(IFEQ, endWithDefaultLabel);
        mv.loadArgs(1, mv.getArgumentTypes().length - 1);
        mv.visitMethodInsn(INVOKESTATIC, checkNotNull(className), name, onBeforeMethodVisitor.descriptor,
                false);
        mv.returnValue();

        mv.visitLabel(endWithDefaultLabel);
        mv.visitFrame(F_NEW, 0, new Object[0], 0, new Object[0]);
        if (mv.getReturnType().getSort() != Type.VOID) {
            // return value will be ignored when !enabled, but need to return something
            WeavingMethodVisitor.pushDefault(mv, mv.getReturnType());
        }
        mv.returnValue();
        mv.endMethod();
    }
    super.visitEnd();
}