Example usage for com.google.gwt.dev.asm.commons Method getReturnType

List of usage examples for com.google.gwt.dev.asm.commons Method getReturnType

Introduction

In this page you can find the example usage for com.google.gwt.dev.asm.commons Method getReturnType.

Prototype

public Type getReturnType() 

Source Link

Document

Returns the return type of the method described by this object.

Usage

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.java

License:Apache License

private static String print(Method method) {
    StringBuilder sb = new StringBuilder();
    sb.append(print(method.getReturnType())).append(" ").append(method.getName()).append("(");
    for (Type t : method.getArgumentTypes()) {
        sb.append(print(t)).append(" ");
    }// www.  ja va2 s.c om
    sb.append(")");
    return sb.toString();
}

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.java

License:Apache License

/**
 * This method checks a RequestFactory interface.
 * <p>/*from  www  .  j  av  a2  s .co  m*/
 * This method may be called repeatedly on a single instance of the validator.
 * Doing so will amortize type calculation costs. It does not perform any
 * checks as to whether or not the RequestContext could actually be generated
 * by the Generator.
 * <p>
 * Checks implemented:
 * <ul>
 * <li> <code>binaryName</code> implements RequestFactory</li>
 * <li>All referenced RequestContext types are valid</li>
 * </ul>
 * 
 * @param binaryName the binary name (e.g. {@link Class#getName()}) of the
 *          RequestContext subtype
 * @see #validateRequestContext(String)
 */
public void validateRequestFactory(String binaryName) {
    if (fastFail(binaryName)) {
        return;
    }

    Type requestFactoryType = Type.getObjectType(BinaryName.toInternalName(binaryName));
    ErrorContext logger = parentLogger.setType(requestFactoryType);

    // Quick sanity check for calling code
    if (!isAssignable(logger, Type.getType(RequestFactory.class), requestFactoryType)) {
        logger.poison("%s is not a %s", print(requestFactoryType), RequestFactory.class.getSimpleName());
        return;
    }

    // Validate each RequestContext method in the RF
    for (Method contextMethod : getMethodsInHierarchy(logger, requestFactoryType)) {
        Type returnType = contextMethod.getReturnType();
        if (isAssignable(logger, requestContextIntf, returnType)) {
            validateRequestContext(returnType.getClassName());
        }
    }

    maybeCheckExtraTypes(logger, requestFactoryType);
}

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.java

License:Apache License

/**
 * Convert a method declaration using client types (e.g. FooProxy) to domain
 * types (e.g. Foo)./* w  ww.  ja  va  2s .  c  o  m*/
 */
private Method createDomainMethod(ErrorContext logger, Method clientMethod) {
    Type[] args = clientMethod.getArgumentTypes();
    for (int i = 0, j = args.length; i < j; i++) {
        args[i] = getDomainType(logger, args[i], true);
    }
    Type returnType = getDomainType(logger, clientMethod.getReturnType(), true);
    return new Method(clientMethod.getName(), returnType, args);
}

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.java

License:Apache License

/**
 * Finds a compatible method declaration in <code>domainType</code>'s
 * hierarchy that is assignment-compatible with the given Method.
 *///  ww w.  j ava2s .  c  om
private RFMethod findCompatibleMethod(final ErrorContext logger, Type domainType, Method searchFor,
        boolean mustFind, boolean allowOverloads, boolean boxReturnTypes) {
    String methodName = searchFor.getName();
    Type[] clientArgs = searchFor.getArgumentTypes();
    Type clientReturnType = searchFor.getReturnType();
    if (boxReturnTypes) {
        clientReturnType = maybeBoxType(clientReturnType);
    }
    // Pull all methods out of the domain type
    Map<String, List<RFMethod>> domainLookup = new LinkedHashMap<String, List<RFMethod>>();
    for (RFMethod method : getMethodsInHierarchy(logger, domainType)) {
        List<RFMethod> list = domainLookup.get(method.getName());
        if (list == null) {
            list = new ArrayList<RFMethod>();
            domainLookup.put(method.getName(), list);
        }
        list.add(method);
    }

    // Find the matching method in the domain object
    List<RFMethod> methods = domainLookup.get(methodName);
    if (methods == null) {
        if (mustFind) {
            logger.poison("Could not find any methods named %s in %s", methodName, print(domainType));
        }
        return null;
    }
    if (methods.size() > 1 && !allowOverloads) {
        StringBuilder sb = new StringBuilder();
        sb.append(
                String.format("Method overloads found in type %s named %s:\n", print(domainType), methodName));
        for (RFMethod method : methods) {
            sb.append("  ").append(print(method)).append("\n");
        }
        logger.poison(sb.toString());
        return null;
    }

    // Check each overloaded name
    for (RFMethod domainMethod : methods) {
        Type[] domainArgs = domainMethod.getArgumentTypes();
        Type domainReturnType = domainMethod.getReturnType();
        if (boxReturnTypes) {
            /*
             * When looking for the implementation of a Request<Integer>, we want to
             * match either int or Integer, so we'll box the domain method's return
             * type.
             */
            domainReturnType = maybeBoxType(domainReturnType);
        }

        /*
         * Make sure the client args can be passed into the domain args and the
         * domain return type into the client return type.
         */
        if (isAssignable(logger, domainArgs, clientArgs)
                && isAssignable(logger, clientReturnType, domainReturnType)) {

            logger.spam("Mapped client method " + print(searchFor) + " to " + print(domainMethod));
            return domainMethod;
        }
    }
    if (mustFind) {
        logger.poison(messageCouldNotFindMethod(domainType, methods));
    }
    return null;
}

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryJarExtractor.java

License:Apache License

/**
 * Produce a rebased method declaration, also visiting referenced types.
 *//*from ww w . j  a va 2  s  .  c o m*/
private Method processMethod(String sourceType, String name, String desc) {
    Method method = new Method(name, desc);
    Type[] argumentTypes = method.getArgumentTypes();
    for (int i = 0, j = argumentTypes.length; i < j; i++) {
        argumentTypes[i] = processType(sourceType, argumentTypes[i]);
    }
    method = new Method(name, processType(sourceType, method.getReturnType()), argumentTypes);
    return method;
}

From source file:com.googlecode.gwt.test.internal.rewrite.RewriteSingleJsoImplDispatches.java

License:Apache License

/**
 * For regular Java objects that implement a SingleJsoImpl interface, write instance trampoline
 * dispatchers for mangled method names to the implementing method.
 *//*  ww  w .j  a  va2  s .c om*/
private void writeTrampoline(String stubIntr) {
    /*
     * This is almost the same kind of trampoline as the ones generated in WriteJsoImpl, however
     * there are enough small differences between the semantics of the dispatches that would make
     * a common implementation far more awkward than the duplication of code.
     */
    for (String mangledName : toImplement(stubIntr)) {
        for (Method method : jsoData.getDeclarations(mangledName)) {

            Method toCall = new Method(method.getName(), method.getDescriptor());

            // Must not be final
            MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName,
                    method.getDescriptor(), null, null);
            if (mv != null) {
                mv.visitCode();

                /*
                 * It just so happens that the stack and local variable sizes are the same, but
                 * they're kept distinct to aid in clarity should the dispatch logic change.
                 * 
                 * These start at 1 because we need to load "this" onto the stack
                 */
                int var = 1;
                int size = 1;

                // load this
                mv.visitVarInsn(Opcodes.ALOAD, 0);

                // then the rest of the arguments
                for (Type t : toCall.getArgumentTypes()) {
                    size += t.getSize();
                    mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var);
                    var += t.getSize();
                }

                // Make sure there's enough room for the return value
                size = Math.max(size, toCall.getReturnType().getSize());

                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(),
                        toCall.getDescriptor());
                mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN));
                mv.visitMaxs(size, var);
                mv.visitEnd();
            }
        }
    }
}