Example usage for org.objectweb.asm.signature SignatureWriter visitReturnType

List of usage examples for org.objectweb.asm.signature SignatureWriter visitReturnType

Introduction

In this page you can find the example usage for org.objectweb.asm.signature SignatureWriter visitReturnType.

Prototype

@Override
    public SignatureVisitor visitReturnType() 

Source Link

Usage

From source file:co.cask.cdap.internal.asm.Signatures.java

License:Apache License

/**
 * Generates signature for the given method.
 *
 * @param method Method that needs signature to be generated
 * @param types List of {@link TypeToken} that matches with the number of arguments in the given method.
 *              For a given method argument, if the coresponding {@link TypeToken} is non-null, it will be
 *              used to generate the type parameter in the signature, otherwise, the one in the method will be used.
 *              It's useful if the method is parameterized so that parameterize type information can be passed
 *              through the type tokens.
 * @return A method signature string//w w w  .  j ava2  s . c o m
 */
public static String getMethodSignature(Method method, TypeToken<?>... types) {
    SignatureWriter signWriter = new SignatureWriter();

    Type[] argumentTypes = method.getArgumentTypes();

    for (int i = 0; i < argumentTypes.length; i++) {
        SignatureVisitor sv = signWriter.visitParameterType();
        if (types[i] != null) {
            visitTypeSignature(types[i], sv);
        } else {
            sv.visitClassType(argumentTypes[i].getInternalName());
            sv.visitEnd();
        }
    }

    signWriter.visitReturnType().visitBaseType('V');

    return signWriter.toString();
}

From source file:co.cask.tigon.internal.asm.Signatures.java

License:Apache License

public static String getMethodSignature(Method method, TypeToken<?>[] types) {
    SignatureWriter signWriter = new SignatureWriter();

    Type[] argumentTypes = method.getArgumentTypes();

    for (int i = 0; i < argumentTypes.length; i++) {
        SignatureVisitor sv = signWriter.visitParameterType();
        if (types[i] != null) {
            visitTypeSignature(types[i], sv);
        } else {//from   ww  w.ja v  a2s. c o m
            sv.visitClassType(argumentTypes[i].getInternalName());
            sv.visitEnd();
        }
    }

    signWriter.visitReturnType().visitBaseType('V');

    return signWriter.toString();
}

From source file:com.google.code.jconts.instrument.gen.ComputationClassGenerator.java

License:Apache License

private String executeSignature() {
    SignatureWriter sw = new SignatureWriter();
    contSignature(sw.visitParameterType());
    sw.visitReturnType().visitBaseType('V');
    return sw.toString();
}

From source file:com.google.code.jconts.instrument.gen.ContinuationClassGenerator.java

License:Apache License

private void generateExecute(ClassVisitor cv, boolean execute) {
    final String name = info.continuationClassName;
    final Type outerType = Type.getObjectType(info.owner);

    // Generate invoke(T result);
    String signature = null;/*from   w w  w  .j a  v a  2s  .  co  m*/
    if (execute) {
        SignatureWriter sign = new SignatureWriter();
        sign.visitParameterType().visitTypeVariable("T");
        sign.visitReturnType().visitBaseType('V'); // void
        signature = sign.toString();
    }
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC,
            execute ? CONTINUATION_INVOKE_NAME : CONTINUATION_SET_EXCEPTION_NAME,
            execute ? CONTINUATION_INVOKE_DESC : CONTINUATION_SET_EXCEPTION_DESC, signature, null);
    mv.visitCode();
    Label start = new Label();
    Label end = new Label();
    mv.visitLabel(start);

    // Load outer this
    if (!info.isStatic()) {
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, name, "this$0", outerType.getDescriptor());
    }

    // state.result = result or state.exception = throwable
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, info.stateClassName, execute ? "result" : "exception",
            execute ? OBJECT_DESC : THROWABLE_DESC);

    // Load state field
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc);

    // Continue from this index or index+1 (for exception)
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, name, "index", "I");
    if (!execute) {
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitInsn(Opcodes.IADD);
    }

    mv.visitMethodInsn(info.isStatic() ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL, info.owner,
            info.name + "$async",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { info.stateType, Type.INT_TYPE }));

    mv.visitInsn(Opcodes.RETURN);
    mv.visitLabel(end);

    mv.visitLocalVariable("this", 'L' + name + ';', signature, start, end, 0);
    if (!info.isStatic()) {
        mv.visitLocalVariable("this$0", outerType.getDescriptor(), null, start, end, 1);
    }
    mv.visitLocalVariable("result", OBJECT_DESC, "TT;", start, end, 1 + info.thisOffset);

    mv.visitMaxs(3 + info.thisOffset + (execute ? 0 : 1), 2 + info.thisOffset);
    mv.visitEnd();
}