Example usage for com.google.gwt.dev.asm.signature SignatureReader SignatureReader

List of usage examples for com.google.gwt.dev.asm.signature SignatureReader SignatureReader

Introduction

In this page you can find the example usage for com.google.gwt.dev.asm.signature SignatureReader SignatureReader.

Prototype

public SignatureReader(final String signature) 

Source Link

Document

Constructs a SignatureReader for the given signature.

Usage

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

License:Apache License

/**
 * Examines a generic RequestContext method declaration and determines the
 * expected domain return type. This implementation is limited in that it will
 * not attempt to resolve type bounds since that would essentially require
 * implementing TypeOracle. In the case where the type bound cannot be
 * resolved, this method will return Object's type.
 *///ww w.  j  av  a2 s . com
private Type getReturnType(ErrorContext logger, RFMethod method) {
    logger = logger.setMethod(method);
    final String[] returnType = { objectType.getInternalName() };
    String signature = method.getSignature();

    final int expectedCount;
    if (method.getReturnType().equals(instanceRequestIntf)) {
        expectedCount = 2;
    } else if (method.getReturnType().equals(requestIntf)) {
        expectedCount = 1;
    } else {
        logger.spam("Punting on " + signature);
        return Type.getObjectType(returnType[0]);
    }

    // TODO(bobv): If a class-based TypeOracle is built, use that instead
    new SignatureReader(signature).accept(new SignatureAdapter() {
        @Override
        public SignatureVisitor visitReturnType() {
            return new SignatureAdapter() {
                int count;

                @Override
                public SignatureVisitor visitTypeArgument(char wildcard) {
                    if (++count == expectedCount) {
                        return new SignatureAdapter() {
                            @Override
                            public void visitClassType(String name) {
                                returnType[0] = name;
                            }
                        };
                    }
                    return super.visitTypeArgument(wildcard);
                }
            };
        }
    });

    logger.spam("Extracted " + returnType[0]);
    return Type.getObjectType(returnType[0]);
}

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

License:Apache License

/**
 * Examine the arguments and return value of a method and check any
 * EntityProxies referred./*  w  w w  .  jav a  2  s  . co m*/
 */
private void maybeCheckReferredProxies(ErrorContext logger, RFMethod method) {
    if (method.getSignature() != null) {
        TypesInSignatureCollector collector = new TypesInSignatureCollector();
        SignatureReader reader = new SignatureReader(method.getSignature());
        reader.accept(collector);
        maybeCheckProxyType(logger, collector.getFound());
    } else {
        Type[] argTypes = method.getArgumentTypes();
        Type returnType = getReturnType(logger, method);

        // Check EntityProxy args ond return types against the domain
        maybeCheckProxyType(logger, argTypes);
        maybeCheckProxyType(logger, returnType);
    }
}