Example usage for com.google.gwt.editor.rebind.model ModelUtils isValueType

List of usage examples for com.google.gwt.editor.rebind.model ModelUtils isValueType

Introduction

In this page you can find the example usage for com.google.gwt.editor.rebind.model ModelUtils isValueType.

Prototype

public static boolean isValueType(TypeOracle oracle, JType type) 

Source Link

Usage

From source file:com.google.web.bindery.autobean.gwt.rebind.model.AutoBeanFactoryModel.java

License:Apache License

/**
 * Enqueue a type in {@link #toCalculate} if {@link #peers} does not already
 * contain an entry./*w  w w. j  a va 2  s  . c om*/
 */
private void maybeCalculate(JClassType type) {
    if (type.isInterface() == null || ModelUtils.isValueType(oracle, type)) {
        return;
    }
    if (!peers.containsKey(type)) {
        toCalculate.add(type);
    }
}

From source file:com.google.web.bindery.requestfactory.gwt.rebind.model.RequestFactoryModel.java

License:Apache License

/**
 * Examines a type to see if it can be transported.
 *///from   ww w.j  a va 2 s.com
private boolean validateTransportableType(RequestMethod.Builder methodBuilder, JType type,
        boolean requireObject) throws UnableToCompleteException {
    JClassType transportedClass = type.isClassOrInterface();
    if (transportedClass == null) {
        if (requireObject) {
            poison("The type %s cannot be transported by RequestFactory as" + " a return type",
                    type.getQualifiedSourceName());
            return false;
        } else {
            // Primitives always ok
            return true;
        }
    }

    if (ModelUtils.isValueType(oracle, transportedClass) || splittableType.equals(transportedClass)) {
        // Simple values, like Integer and String
        methodBuilder.setValueType(true);
    } else if (entityProxyInterface.isAssignableFrom(transportedClass)
            || valueProxyInterface.isAssignableFrom(transportedClass)) {
        // EntityProxy and ValueProxy return types
        methodBuilder.setEntityType(getEntityProxyType(transportedClass));
    } else if (collectionInterface.isAssignableFrom(transportedClass)) {
        // Only allow certain collections for now
        JParameterizedType parameterized = transportedClass.isParameterized();
        if (parameterized == null) {
            poison("Requests that return collections of List or Set must be parameterized");
            return false;
        }
        if (listInterface.equals(parameterized.getBaseType())) {
            methodBuilder.setCollectionType(CollectionType.LIST);
        } else if (setInterface.equals(parameterized.getBaseType())) {
            methodBuilder.setCollectionType(CollectionType.SET);
        } else {
            poison("Requests that return collections may be declared with" + " %s or %s only",
                    listInterface.getQualifiedSourceName(), setInterface.getQualifiedSourceName());
            return false;
        }
        // Also record the element type in the method builder
        JClassType elementType = ModelUtils.findParameterizationOf(collectionInterface, transportedClass)[0];
        methodBuilder.setCollectionElementType(elementType);
        validateTransportableType(methodBuilder, elementType, requireObject);
    } else if (mapInterface.isAssignableFrom(transportedClass)) {
        JParameterizedType parameterized = transportedClass.isParameterized();
        if (parameterized == null) {
            poison("Requests that return Maps must be parameterized");
            return false;
        }
        if (mapInterface.equals(parameterized.getBaseType())) {
            methodBuilder.setCollectionType(CollectionType.MAP);
        } else {
            poison("Requests that return maps may be declared with" + " %s only",
                    mapInterface.getQualifiedSourceName());
            return false;
        }
        // Also record the element type in the method builder
        JClassType[] params = ModelUtils.findParameterizationOf(mapInterface, transportedClass);
        JClassType keyType = params[0];
        JClassType valueType = params[1];
        methodBuilder.setMapKeyType(keyType);
        methodBuilder.setMapValueType(valueType);
        validateTransportableType(methodBuilder, keyType, requireObject);
        validateTransportableType(methodBuilder, valueType, requireObject);
    } else {
        // Unknown type, fail
        poison("Invalid Request parameterization %s", transportedClass.getQualifiedSourceName());
        return false;
    }
    methodBuilder.setDataType(transportedClass);
    return true;
}