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

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

Introduction

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

Prototype

public String getDescriptor() 

Source Link

Document

Returns the descriptor of the method described by this object.

Usage

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

License:Apache License

/**
 * This method checks a RequestContext interface against its peer domain
 * domain object to determine if the server code would be able to process a
 * request using the the methods defined in the RequestContext interface. It
 * does not perform any checks as to whether or not the RequestContext could
 * actually be generated by the Generator.
 * <p>/*w w  w.  j  a v  a  2  s. co m*/
 * This method may be called repeatedly on a single instance of the validator.
 * Doing so will amortize type calculation costs.
 * <p>
 * Checks implemented:
 * <ul>
 * <li> <code>binaryName</code> implements RequestContext</li>
 * <li><code>binaryName</code> has a {@link Service} or {@link ServiceName}
 * annotation</li>
 * <li>All service methods in the RequestContext can be mapped onto an
 * equivalent domain method (unless validation is skipped for the method)</li>
 * <li>All referenced EntityProxy types are valid</li>
 * </ul>
 * 
 * @param binaryName the binary name (e.g. {@link Class#getName()}) of the
 *          RequestContext subtype
 * @see #validateEntityProxy(String)
 */
public void validateRequestContext(String binaryName) {
    if (fastFail(binaryName)) {
        return;
    }

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

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

    Type domainServiceType = getDomainType(logger, requestContextType, false);
    if (domainServiceType == errorType) {
        logger.poison("The type %s must be annotated with a @%s or @%s annotation",
                BinaryName.toSourceName(binaryName), Service.class.getSimpleName(),
                ServiceName.class.getSimpleName());
        return;
    }

    for (RFMethod method : getMethodsInHierarchy(logger, requestContextType)) {
        // Ignore methods in RequestContext itself
        if (findCompatibleMethod(logger, requestContextIntf, method, false, true, true) != null) {
            continue;
        }

        // Check the client method against the domain
        Method found = checkClientMethodInDomain(logger, method, domainServiceType,
                !clientToLocatorMap.containsKey(requestContextType));
        if (found != null) {
            OperationKey key = new OperationKey(binaryName, method.getName(), method.getDescriptor());
            OperationData data = new OperationData.Builder().setClientMethodDescriptor(method.getDescriptor())
                    .setDomainMethodDescriptor(found.getDescriptor()).setMethodName(method.getName())
                    .setRequestContext(requestContextType.getClassName()).build();
            operationData.put(key, data);
        }
        maybeCheckReferredProxies(logger, method);
    }

    maybeCheckExtraTypes(logger, requestContextType);
    checkUnresolvedKeyTypes(logger);
}

From source file:com.google.web.bindery.requestfactory.vm.impl.OperationKey.java

License:Apache License

private static String key(String requestContextBinaryName, String methodName, String descriptor) {
    Method m = new Method(methodName, Type.VOID_TYPE, Type.getArgumentTypes(descriptor));
    String raw = requestContextBinaryName + "::" + methodName + m.getDescriptor();
    return raw.length() >= HASH_LENGTH ? hash(raw) : raw;
}

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

License:Apache License

private void writeEmptyMethod(String mangledMethodName, Method declMethod) {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, mangledMethodName,
            declMethod.getDescriptor(), null, null);
    mv.visitEnd();//ww  w . java  2 s  .co  m
}

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.
 *///w  w w  . j  av  a2  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();
            }
        }
    }
}