Example usage for com.google.gwt.dev.asm Type getClassName

List of usage examples for com.google.gwt.dev.asm Type getClassName

Introduction

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

Prototype

public String getClassName() 

Source Link

Document

Returns the name of the class corresponding to this type.

Usage

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

License:Apache License

private static String print(Type type) {
    return SourceOrBinaryName.toSourceName(type.getClassName());
}

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>//from  ww w .j  av a  2  s. c o 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.server.RequestFactoryInterfaceValidator.java

License:Apache License

/**
 * This method checks a RequestFactory interface.
 * <p>//from  ww  w . java2  s. c om
 * 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

/**
 * Check that the domain object has <code>getId()</code> and
 * <code>getVersion</code> methods.
 *//*w  ww  .  j a  v  a 2 s  .  c om*/
private void checkIdAndVersion(ErrorContext logger, Type domainType) {
    if (objectType.equals(domainType)) {
        return;
    }
    logger = logger.setType(domainType);
    String findMethodName = "find" + BinaryName.getShortClassName(domainType.getClassName());
    Type keyType = null;
    RFMethod findMethod = null;

    boolean foundFind = false;
    boolean foundId = false;
    boolean foundVersion = false;
    for (RFMethod method : getMethodsInHierarchy(logger, domainType)) {
        if ("getId".equals(method.getName()) && method.getArgumentTypes().length == 0) {
            foundId = true;
            keyType = method.getReturnType();
            if (!isResolvedKeyType(logger, keyType)) {
                unresolvedKeyTypes.put(domainType, keyType);
            }
        } else if ("getVersion".equals(method.getName()) && method.getArgumentTypes().length == 0) {
            foundVersion = true;
            if (!isResolvedKeyType(logger, method.getReturnType())) {
                unresolvedKeyTypes.put(domainType, method.getReturnType());
            }
        } else if (findMethodName.equals(method.getName()) && method.getArgumentTypes().length == 1) {
            foundFind = true;
            findMethod = method;
        }
        if (foundFind && foundId && foundVersion) {
            break;
        }
    }
    if (!foundId) {
        logger.poison("There is no getId() method in type %s", print(domainType));
    }
    if (!foundVersion) {
        logger.poison("There is no getVersion() method in type %s", print(domainType));
    }

    if (foundFind) {
        if (keyType != null && !isAssignable(logger, findMethod.getArgumentTypes()[0], keyType)) {
            logger.poison("The key type returned by %s getId()" + " cannot be used as the argument to %s(%s)",
                    print(keyType), findMethod.getName(), print(findMethod.getArgumentTypes()[0]));
        }
        if (!findMethod.isDeclaredStatic()) {
            logger.poison("The %s method must be static", findMethodName);
        }
    } else {
        logger.poison("There is no %s method in type %s that returns %2$s", findMethodName, print(domainType));
    }
}

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

License:Apache License

/**
 * Examine an array of Types and call {@link #validateEntityProxy(String)} or
 * {@link #validateValueProxy(String)} if the type is a proxy.
 *///ww w . jav  a 2  s  . com
private void maybeCheckProxyType(ErrorContext logger, Type... types) {
    for (Type type : types) {
        if (isAssignable(logger, entityProxyIntf, type)) {
            validateEntityProxy(type.getClassName());
        } else if (isAssignable(logger, valueProxyIntf, type)) {
            validateValueProxy(type.getClassName());
        } else if (isAssignable(logger, baseProxyIntf, type)) {
            logger.poison("Invalid type hierarchy for %s. Only types derived from %s or %s may be used.",
                    print(type), print(entityProxyIntf), print(valueProxyIntf));
        }
    }
}

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

License:Apache License

/**
 * Process a type, possibly returning a rebased type.
 * /*from ww w  . j a  va2 s.  c o m*/
 * @param sourceType TODO
 */
private Type processType(String sourceType, Type type) {
    Type toReturn;
    synchronized (seen) {
        toReturn = seen.get(type);
        if (toReturn != null) {
            return toReturn;
        }
        toReturn = Type.getType(type.getDescriptor());
        seen.put(type, toReturn);
    }
    int sort = type.getSort();
    if (sort != Type.OBJECT && sort != Type.ARRAY) {
        return toReturn;
    }
    if (sort == Type.ARRAY) {
        processType(sourceType, type.getElementType());
        return toReturn;
    }
    assert type.getInternalName().charAt(0) != 'L';
    if (type.getInternalName().startsWith("java/") || type.getInternalName().startsWith("javax/")) {
        return toReturn;
    }
    if (VERBOSE) {
        System.out.println(sourceType + " -> " + type.getClassName());
    }
    Future<State> future = ex.submit(new ProcessOneType(type));
    inProcess.add(future);
    return toReturn;
}

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

License:Apache License

private Class<?> getClass(Type type) {
    switch (type.getSort()) {
    case Type.BOOLEAN:
        return boolean.class;
    case Type.BYTE:
        return byte.class;
    case Type.CHAR:
        return char.class;
    case Type.DOUBLE:
        return double.class;
    case Type.FLOAT:
        return float.class;
    case Type.INT:
        return int.class;
    case Type.LONG:
        return long.class;
    case Type.OBJECT:
        return forName(type.getClassName());
    case Type.SHORT:
        return short.class;
    case Type.VOID:
        return void.class;
    case Type.ARRAY:
        return die(null, "Unsupported Type used in operation descriptor %s", type.getDescriptor());
    default://from ww  w.j a  va 2s . c o  m
        // Error in this switch statement
        return die(null, "Unhandled Type: %s", type.getDescriptor());
    }
}