Example usage for com.google.gwt.core.ext.typeinfo JPrimitiveType VOID

List of usage examples for com.google.gwt.core.ext.typeinfo JPrimitiveType VOID

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JPrimitiveType VOID.

Prototype

JPrimitiveType VOID

To view the source code for com.google.gwt.core.ext.typeinfo JPrimitiveType VOID.

Click Source Link

Usage

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

License:Apache License

/**
 * For interfaces that consist of nothing more than getters and setters,
 * create a map-based implementation that will allow the AutoBean's internal
 * state to be easily consumed.//ww  w.j ava 2  s  . c o m
 */
private void writeCreateSimpleBean(SourceWriter sw, AutoBeanType type) {
    sw.println("@Override protected %s createSimplePeer() {", type.getPeerType().getQualifiedSourceName());
    sw.indent();
    // return new FooIntf() {
    sw.println("return new %s() {", type.getPeerType().getQualifiedSourceName());
    sw.indent();
    sw.println("private final %s data = %s.this.data;", Splittable.class.getCanonicalName(),
            type.getQualifiedSourceName());
    for (AutoBeanMethod method : type.getMethods()) {
        JMethod jmethod = method.getMethod();
        JType returnType = jmethod.getReturnType();
        sw.println("public %s {", getBaseMethodDeclaration(jmethod));
        sw.indent();
        switch (method.getAction()) {
        case GET: {
            String castType;
            if (returnType.isPrimitive() != null) {
                castType = returnType.isPrimitive().getQualifiedBoxedSourceName();
                // Boolean toReturn = Other.this.getOrReify("foo");
                sw.println("%s toReturn = %s.this.getOrReify(\"%s\");", castType, type.getSimpleSourceName(),
                        method.getPropertyName());
                // return toReturn == null ? false : toReturn;
                sw.println("return toReturn == null ? %s : toReturn;",
                        returnType.isPrimitive().getUninitializedFieldExpression());
            } else if (returnType
                    .equals(context.getTypeOracle().findType(Splittable.class.getCanonicalName()))) {
                sw.println("return data.isNull(\"%1$s\") ? null : data.get(\"%1$s\");",
                        method.getPropertyName());
            } else {
                // return (ReturnType) Outer.this.getOrReify(\"foo\");
                castType = ModelUtils.getQualifiedBaseSourceName(returnType);
                sw.println("return (%s) %s.this.getOrReify(\"%s\");", castType, type.getSimpleSourceName(),
                        method.getPropertyName());
            }
        }
            break;
        case SET:
        case SET_BUILDER: {
            JParameter param = jmethod.getParameters()[0];
            // Other.this.setProperty("foo", parameter);
            sw.println("%s.this.setProperty(\"%s\", %s);", type.getSimpleSourceName(), method.getPropertyName(),
                    param.getName());
            if (JBeanMethod.SET_BUILDER.equals(method.getAction())) {
                sw.println("return this;");
            }
            break;
        }
        case CALL:
            // return com.example.Owner.staticMethod(Outer.this, param,
            // param);
            JMethod staticImpl = method.getStaticImpl();
            if (!returnType.equals(JPrimitiveType.VOID)) {
                sw.print("return ");
            }
            sw.print("%s.%s(%s.this", staticImpl.getEnclosingType().getQualifiedSourceName(),
                    staticImpl.getName(), type.getSimpleSourceName());
            for (JParameter param : jmethod.getParameters()) {
                sw.print(", %s", param.getName());
            }
            sw.println(");");
            break;
        default:
            throw new RuntimeException();
        }
        sw.outdent();
        sw.println("}");
    }
    sw.outdent();
    sw.println("};");
    sw.outdent();
    sw.println("}");
}

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

License:Apache License

/**
 * Create the shim instance of the AutoBean's peer type that lets us hijack
 * the method calls. Using a shim type, as opposed to making the AutoBean
 * implement the peer type directly, means that there can't be any conflicts
 * between methods in the peer type and methods declared in the AutoBean
 * implementation./*w ww.  j  a  v a2 s . com*/
 */
private void writeShim(SourceWriter sw, AutoBeanType type) throws UnableToCompleteException {
    // private final FooImpl shim = new FooImpl() {
    sw.println("private final %1$s shim = new %1$s() {", type.getPeerType().getQualifiedSourceName());
    sw.indent();
    for (AutoBeanMethod method : type.getMethods()) {
        JMethod jmethod = method.getMethod();
        String methodName = jmethod.getName();
        JParameter[] parameters = jmethod.getParameters();
        if (isObjectMethodImplementedByShim(jmethod)) {
            // Skip any methods declared on Object, since we have special handling
            continue;
        }

        // foo, bar, baz
        StringBuilder arguments = new StringBuilder();
        {
            for (JParameter param : parameters) {
                arguments.append(",").append(param.getName());
            }
            if (arguments.length() > 0) {
                arguments = arguments.deleteCharAt(0);
            }
        }

        sw.println("public %s {", getBaseMethodDeclaration(jmethod));
        sw.indent();

        switch (method.getAction()) {
        case GET:
            /*
             * The getter call will ensure that any non-value return type is
             * definitely wrapped by an AutoBean instance.
             */
            sw.println("%s toReturn = %s.this.getWrapped().%s();",
                    ModelUtils.getQualifiedBaseSourceName(jmethod.getReturnType()), type.getSimpleSourceName(),
                    methodName);

            // Non-value types might need to be wrapped
            writeReturnWrapper(sw, type, method);
            sw.println("return toReturn;");
            break;
        case SET:
        case SET_BUILDER:
            // getWrapped().setFoo(foo);
            sw.println("%s.this.getWrapped().%s(%s);", type.getSimpleSourceName(), methodName,
                    parameters[0].getName());
            // FooAutoBean.this.set("setFoo", foo);
            sw.println("%s.this.set(\"%s\", %s);", type.getSimpleSourceName(), methodName,
                    parameters[0].getName());
            if (JBeanMethod.SET_BUILDER.equals(method.getAction())) {
                sw.println("return this;");
            }
            break;
        case CALL:
            // XXX How should freezing and calls work together?
            // sw.println("checkFrozen();");
            if (JPrimitiveType.VOID.equals(jmethod.getReturnType())) {
                // getWrapped().doFoo(params);
                sw.println("%s.this.getWrapped().%s(%s);", type.getSimpleSourceName(), methodName, arguments);
                // call("doFoo", null, params);
                sw.println("%s.this.call(\"%s\", null%s %s);", type.getSimpleSourceName(), methodName,
                        arguments.length() > 0 ? "," : "", arguments);
            } else {
                // Type toReturn = getWrapped().doFoo(params);
                sw.println("%s toReturn = %s.this.getWrapped().%s(%s);",
                        ModelUtils.ensureBaseType(jmethod.getReturnType()).getQualifiedSourceName(),
                        type.getSimpleSourceName(), methodName, arguments);
                // Non-value types might need to be wrapped
                writeReturnWrapper(sw, type, method);
                // call("doFoo", toReturn, params);
                sw.println("%s.this.call(\"%s\", toReturn%s %s);", type.getSimpleSourceName(), methodName,
                        arguments.length() > 0 ? "," : "", arguments);
                sw.println("return toReturn;");
            }
            break;
        default:
            throw new RuntimeException();
        }
        sw.outdent();
        sw.println("}");
    }

    // Delegate equals(), hashCode(), and toString() to wrapped object
    sw.println("@Override public boolean equals(Object o) {");
    sw.indentln("return this == o || getWrapped().equals(o);");
    sw.println("}");
    sw.println("@Override public int hashCode() {");
    sw.indentln("return getWrapped().hashCode();");
    sw.println("}");
    sw.println("@Override public String toString() {");
    sw.indentln("return getWrapped().toString();");
    sw.println("}");

    // End of shim field declaration and assignment
    sw.outdent();
    sw.println("};");
}

From source file:com.guit.rebind.binder.GuitBinderGenerator.java

License:Apache License

private void printViewFieldBindings(SourceWriter writer, JClassType presenterType, String viewTypeName,
        HashMap<String, JType> validBindingFieldsType, ArrayList<JField> fields)
        throws UnableToCompleteException {

    Set<String> validBindingFields = validBindingFieldsType.keySet();

    JClassType viewAccesorType = getType(ViewAccesor.class.getCanonicalName());

    ArrayList<JField> superFields = new ArrayList<JField>();
    collectAllFields(presenterType.getSuperclass(), superFields);

    JClassType elementDomType = getType(com.guit.client.dom.Element.class.getCanonicalName());

    for (JField f : fields) {
        if (f.isAnnotationPresent(ViewField.class)) {
            // Check for repetided fields
            if (f.getType().isClassOrInterface().isAssignableTo(elementDomType)) {
                if (superFields.contains(f)) {

                }//from w ww .j av  a2  s . c o m
            }

            String name = f.getName();
            ViewField viewField = f.getAnnotation(ViewField.class);
            String viewName = viewField.name();
            if (viewName.isEmpty()) {
                viewName = name;
            }
            if (!validBindingFields.contains(viewName)) {
                error("The field '%s' do not exists. Found: %s.%s", viewName,
                        presenterType.getQualifiedSourceName(), name);
            }

            JClassType type = f.getType().isClassOrInterface();
            // if (type.isInterface() == null && !viewField.provided()) {
            // error("A ViewField must be an interface. Found: %s.%s", presenterType
            // .getQualifiedSourceName(), name);
            // }

            if (type.isAssignableTo(viewAccesorType)) {
                writer.println("{");
                writer.indent();
                if (!type.isAnnotationPresent(Implementation.class)) {
                    writer.println(type.getQualifiedSourceName() + " accesor = "
                            + GinOracle.getProvidedInstance(type.getQualifiedSourceName()) + ".get();");
                } else {

                    JClassType implementation = getType(
                            type.getAnnotation(Implementation.class).value().getCanonicalName());

                    // If they are parameterized look for the base type
                    JParameterizedType implementationParameterized = implementation.isParameterized();
                    if (implementationParameterized != null) {
                        implementation = implementationParameterized.getBaseType();
                    }
                    JParameterizedType typeParameterized = type.isParameterized();
                    if (typeParameterized != null) {
                        type = typeParameterized.getBaseType();
                    }

                    // Verify that they are assignable
                    if (!implementation.isAssignableTo(type)) {
                        error("An implementation of a ViewAccesor must implement the ViewAccesor interface. Found: %s",
                                implementation.getQualifiedSourceName());
                    }
                    writer.println(type.getQualifiedSourceName() + " accesor = new "
                            + implementation.getQualifiedSourceName() + "();");
                }

                writer.println("accesor.setTarget(view." + viewName + ");");
                writer.println("presenter." + name + " = accesor;");
                writer.outdent();
                writer.print("}");
                writer.println();
            } else if (type == null
                    || type.isAssignableFrom(validBindingFieldsType.get(viewName).isClassOrInterface())
                    || type.getQualifiedSourceName().startsWith("elemental.")) {
                String qualifiedSourceName = f.getType().getQualifiedSourceName();
                writer.println("presenter." + name + " = (" + qualifiedSourceName + ") view." + viewName + ";");
                writer.println();
            } else {
                // Interface emulation (without exceptions)
                writer.println(
                        "presenter." + name + " = new " + type.getParameterizedQualifiedSourceName() + "() {");
                writer.indent();

                ArrayList<JMethod> methods = new ArrayList<JMethod>();
                findAllMethods(type, methods);
                for (JMethod m : methods) {
                    writer.print(m.getReadableDeclaration(false, true, true, true, true));
                    writer.println("{");
                    writer.indent();

                    // Find the parameters
                    StringBuilder callParameters = new StringBuilder();
                    for (JParameter p : m.getParameters()) {
                        if (callParameters.length() > 0) {
                            callParameters.append(", ");
                        }
                        if (p.isAnnotationPresent(ImplicitCast.class)) {
                            callParameters.append("(");
                            callParameters
                                    .append(p.getAnnotation(ImplicitCast.class).value().getCanonicalName());
                            callParameters.append(") ");
                        }
                        callParameters.append(p.getName());
                    }

                    JType returnType = m.getReturnType();
                    if (!returnType.equals(JPrimitiveType.VOID)) {
                        writer.print("return ");

                        // Implicit cast
                        writer.print("(" + returnType.getParameterizedQualifiedSourceName() + ")");
                    }

                    writer.indent();
                    writer.println(createdClassName + ".this.view." + viewName + "." + m.getName() + "("
                            + callParameters.toString() + ");");
                    writer.outdent();

                    writer.outdent();
                    writer.println("}");
                    writer.println();
                }

                // Get .equals working on emulated interfaces for
                // event.getSource() comparations
                writer.println("@Override");
                writer.println("public boolean equals(Object obj) {");
                writer.indent();
                writer.println("return view." + viewName + ".equals(obj);");
                writer.outdent();
                writer.println("}");
                writer.println();

                writer.outdent();
                writer.println("};");
            }
        }
    }
}

From source file:com.guit.rebind.binder.GuitBinderGenerator.java

License:Apache License

protected void validateHandler(JMethod m, String name, String presenterName) throws UnableToCompleteException {
    if (m.isStatic()) {
        error("All event handlers must not be static. Found: %s.%s", presenterName, name);
    }//ww w.  j a v  a  2s.c  om

    if (m.isPrivate()) {
        error("All event handlers must not be private. Found: %s.%s", presenterName, name);
    }

    JPrimitiveType returnTypePrimitive = m.getReturnType().isPrimitive();
    if (returnTypePrimitive == null || !returnTypePrimitive.equals(JPrimitiveType.VOID)) {
        error("All event handlers should return void. Found: %s.%s", presenterName, name);
    }
}

From source file:com.gwtplatform.dispatch.rest.delegates.rebind.DelegateMethodGenerator.java

License:Apache License

private String resolveReturnValue() {
    String returnValue = null;// www  .j ava  2s. co  m
    JType returnType = getMethod().getReturnType();
    JPrimitiveType primitiveType = returnType.isPrimitive();

    if (primitiveType != null) {
        if (primitiveType != JPrimitiveType.VOID) {
            returnValue = primitiveType.getUninitializedFieldExpression();
        }
    } else {
        returnValue = "null";
    }

    return returnValue;
}

From source file:com.gwtplatform.mvp.rebind.PresenterTitleMethod.java

License:Apache License

public void init(JMethod method) throws UnableToCompleteException {

    functionName = method.getName();/*from w ww .  j a v a2s. c o  m*/
    isStatic = method.isStatic();

    JClassType classReturnType = method.getReturnType().isClassOrInterface();
    if (classReturnType != null && classReturnType == classCollection.stringClass) {
        returnString = true;
    } else {
        returnString = false;

        JPrimitiveType primitiveReturnType = method.getReturnType().isPrimitive();
        if (primitiveReturnType == null || primitiveReturnType != JPrimitiveType.VOID) {
            logger.log(TreeLogger.WARN,
                    "In presenter " + presenterInspector.getPresenterClassName() + ", method " + functionName
                            + " annotated with @" + TitleFunction.class.getSimpleName()
                            + " returns something else than void or String. "
                            + "Return value will be ignored and void will be assumed.");
        }
    }

    int i = 0;
    for (JParameter parameter : method.getParameters()) {
        JClassType parameterType = parameter.getType().isClassOrInterface();
        if (parameterType.isAssignableFrom(ginjectorInspector.getGinjectorClass())
                && gingectorParamIndex == -1) {
            gingectorParamIndex = i;
        } else if (parameterType.isAssignableFrom(classCollection.placeRequestClass)
                && placeRequestParamIndex == -1) {
            placeRequestParamIndex = i;
        } else if (parameterType.isAssignableFrom(classCollection.setPlaceTitleHandlerClass)
                && setPlaceTitleHandlerParamIndex == -1) {
            setPlaceTitleHandlerParamIndex = i;
        } else {
            logger.log(TreeLogger.ERROR, "In presenter " + presenterInspector.getPresenterClassName()
                    + ", in method " + functionName + " annotated with @" + TitleFunction.class.getSimpleName()
                    + ", parameter " + i + " is invalid. Method can have at most one parameter of type "
                    + ginjectorInspector.getGinjectorClassName() + ", " + ClassCollection.placeRequestClassName
                    + " or " + ClassCollection.setPlaceTitleHandlerClassName);
            throw new UnableToCompleteException();
        }
        i++;
    }

    if (returnString && setPlaceTitleHandlerParamIndex != -1) {
        logger.log(TreeLogger.ERROR,
                "In presenter " + presenterInspector.getPresenterClassName() + ", the method " + functionName
                        + " annotated with @" + TitleFunction.class.getSimpleName()
                        + " returns a string and accepts a " + ClassCollection.setPlaceTitleHandlerClassName
                        + " parameter. This is not supported, you can have only one or the other.");
        throw new UnableToCompleteException();
    }

    if (!returnString && setPlaceTitleHandlerParamIndex == -1) {
        logger.log(TreeLogger.ERROR, "In presenter " + presenterInspector.getPresenterClassName()
                + ", the method " + functionName + " annotated with @" + TitleFunction.class.getSimpleName()
                + " doesn't return a string and doesn't accept a "
                + ClassCollection.setPlaceTitleHandlerClassName + " parameter. You need one or the other.");
        throw new UnableToCompleteException();
    }
}

From source file:com.gwtplatform.mvp.rebind.ProxyEventMethod.java

License:Apache License

public void init(JMethod method) throws UnableToCompleteException {

    ProxyEvent annotation = method.getAnnotation(ProxyEvent.class);
    assert annotation != null;

    functionName = method.getName();/*from   w ww.j ava2  s  .c o  m*/
    if (method.getReturnType().isPrimitive() != JPrimitiveType.VOID) {
        logger.log(TreeLogger.WARN,
                getErrorPrefix() + " returns something else than void. Return value will be ignored.");
    }

    if (method.getParameters().length != 1) {
        logger.log(TreeLogger.ERROR,
                getErrorPrefix() + " needs to have exactly 1 parameter of a type derived from GwtEvent.");
        throw new UnableToCompleteException();
    }

    JClassType eventType = method.getParameters()[0].getType().isClassOrInterface();
    if (eventType == null || !eventType.isAssignableTo(classCollection.gwtEventClass)) {
        logger.log(TreeLogger.ERROR,
                getErrorPrefix() + " must take a parameter extending " + ClassCollection.gwtEventClassName);
        throw new UnableToCompleteException();
    }

    eventInspector = new ClassInspector(logger, eventType);
    eventTypeName = eventType.getQualifiedSourceName();
    ensureStaticGetTypeMethodExists(eventType);

    JClassType handlerType = findHandlerType(eventType);
    handlerTypeName = handlerType.getQualifiedSourceName();

    JMethod handlerMethod = findHandlerMethod(handlerType);
    handlerMethodName = handlerMethod.getName();

    // Warn if handlerMethodName is different
    if (!handlerMethodName.equals(functionName)) {
        logger.log(TreeLogger.WARN,
                getErrorPrefix(eventTypeName, handlerTypeName) + ". The handler method '" + handlerMethodName
                        + "' differs from the annotated method '" + functionName
                        + ". You should use the same method name for easier reference.");
    }
}

From source file:com.gwtplatform.mvp.rebind.ProxyEventMethod.java

License:Apache License

private JMethod findHandlerMethod(JClassType handlerType) throws UnableToCompleteException {
    if (handlerType.getMethods().length != 1) {
        logger.log(TreeLogger.ERROR, getErrorPrefix(eventTypeName, handlerTypeName)
                + ", but the handler interface has more than one method.");
        throw new UnableToCompleteException();
    }// w  w w  .j a v  a  2 s  .  c  o m

    JMethod handlerMethod = handlerType.getMethods()[0];
    if (handlerMethod.getReturnType().isPrimitive() != JPrimitiveType.VOID) {
        logger.log(TreeLogger.WARN, getErrorPrefix(eventTypeName, handlerTypeName)
                + ", but the handler's method does not return void. Return value will be ignored.");
    }
    return handlerMethod;
}

From source file:com.hiramchirino.restygwt.rebind.RestServiceClassCreator.java

License:Apache License

private void writeMethodImpl(JMethod method) throws UnableToCompleteException {
    if (method.getReturnType().isPrimitive() != JPrimitiveType.VOID) {
        error("Invalid rest method. Method must have void return type: " + method.getReadableDeclaration());
    }/*  w w  w. j  a  v  a2s  .c  o  m*/

    Json jsonAnnotation = source.getAnnotation(Json.class);
    final Style classStyle = jsonAnnotation != null ? jsonAnnotation.style() : Style.DEFAULT;

    p(method.getReadableDeclaration(false, false, false, false, true) + " {").i(1);
    {
        String restMethod = getRestMethod(method);
        LinkedList<JParameter> args = new LinkedList<JParameter>(Arrays.asList(method.getParameters()));

        // the last arg should be the callback.
        if (args.isEmpty()) {
            error("Invalid rest method. Method must declare at least a callback argument: "
                    + method.getReadableDeclaration());
        }
        JParameter callbackArg = args.removeLast();
        JClassType callbackType = callbackArg.getType().isClassOrInterface();
        JClassType methodCallbackType = METHOD_CALLBACK_TYPE;
        if (callbackType == null || !callbackType.isAssignableTo(methodCallbackType)) {
            error("Invalid rest method. Last argument must be a " + methodCallbackType.getName() + " type: "
                    + method.getReadableDeclaration());
        }
        JClassType resultType = getCallbackTypeGenericClass(callbackType);

        String pathExpression = null;
        Path pathAnnotation = method.getAnnotation(Path.class);
        if (pathAnnotation != null) {
            pathExpression = wrap(pathAnnotation.value());
        }

        JParameter contentArg = null;
        HashMap<String, JParameter> queryParams = new HashMap<String, JParameter>();
        HashMap<String, JParameter> headerParams = new HashMap<String, JParameter>();

        for (JParameter arg : args) {
            PathParam paramPath = arg.getAnnotation(PathParam.class);
            if (paramPath != null) {
                if (pathExpression == null) {
                    error("Invalid rest method.  Invalid @PathParam annotation. Method is missing the @Path annotation: "
                            + method.getReadableDeclaration());
                }
                pathExpression = pathExpression.replaceAll(Pattern.quote("{" + paramPath.value() + "}"),
                        "\"+" + toStringExpression(arg.getType(), arg.getName()) + "+\"");
                continue;
            }

            QueryParam queryParam = arg.getAnnotation(QueryParam.class);
            if (queryParam != null) {
                queryParams.put(queryParam.value(), arg);
                continue;
            }

            HeaderParam headerParam = arg.getAnnotation(HeaderParam.class);
            if (headerParam != null) {
                headerParams.put(headerParam.value(), arg);
                continue;
            }

            if (contentArg != null) {
                error("Invalid rest method. Only one content paramter is supported: "
                        + method.getReadableDeclaration());
            }
            contentArg = arg;
        }

        String acceptTypeBuiltIn = null;
        if (callbackType.equals(TEXT_CALLBACK_TYPE)) {
            acceptTypeBuiltIn = "CONTENT_TYPE_TEXT";
        } else if (callbackType.equals(JSON_CALLBACK_TYPE)) {
            acceptTypeBuiltIn = "CONTENT_TYPE_JSON";
        } else if (callbackType.equals(XML_CALLBACK_TYPE)) {
            acceptTypeBuiltIn = "CONTENT_TYPE_XML";
        }

        if (acceptTypeBuiltIn == null) {
            p("final " + METHOD_CLASS + "  __method =");
        }

        p("this.resource");
        if (pathExpression != null) {
            // example: .resolve("path/"+arg0+"/id")
            p(".resolve(" + pathExpression + ")");
        }
        for (Map.Entry<String, JParameter> entry : queryParams.entrySet()) {
            String expr = entry.getValue().getName();
            p(".addQueryParam(" + wrap(entry.getKey()) + ", "
                    + toStringExpression(entry.getValue().getType(), expr) + ")");
        }
        // example: .get()
        p("." + restMethod + "()");

        for (Map.Entry<String, JParameter> entry : headerParams.entrySet()) {
            String expr = entry.getValue().getName();
            p(".header(" + wrap(entry.getKey()) + ", " + toStringExpression(entry.getValue().getType(), expr)
                    + ")");
        }

        if (contentArg != null) {
            if (contentArg.getType() == STRING_TYPE) {
                p(".text(" + contentArg.getName() + ")");
            } else if (contentArg.getType() == JSON_VALUE_TYPE) {
                p(".json(" + contentArg.getName() + ")");
            } else if (contentArg.getType() == DOCUMENT_TYPE) {
                p(".xml(" + contentArg.getName() + ")");
            } else {
                JClassType contentClass = contentArg.getType().isClass();
                if (contentClass == null) {
                    error("Content argument must be a class.");
                }

                jsonAnnotation = contentArg.getAnnotation(Json.class);
                Style style = jsonAnnotation != null ? jsonAnnotation.style() : classStyle;

                // example: .json(Listings$_Generated_JsonEncoder_$.INSTANCE.encode(arg0) )
                p(".json(" + locator.encodeExpression(contentClass, contentArg.getName(), style) + ")");
            }
        }

        if (acceptTypeBuiltIn != null) {
            p(".header(" + RESOURCE_CLASS + ".HEADER_ACCEPT, " + RESOURCE_CLASS + "." + acceptTypeBuiltIn
                    + ");");
            p(".send(" + callbackArg.getClass() + ");");
        } else {
            p(".header(" + RESOURCE_CLASS + ".HEADER_ACCEPT, " + RESOURCE_CLASS + ".CONTENT_TYPE_JSON);");
            p("try {").i(1);
            {
                p("__method.send(new " + ABSTRACT_REQUEST_CALLBACK_CLASS + "<"
                        + resultType.getParameterizedQualifiedSourceName() + ">(__method, "
                        + callbackArg.getName() + ") {").i(1);
                {
                    p("protected " + resultType.getParameterizedQualifiedSourceName()
                            + " parseResult() throws Exception {").i(1);
                    {
                        p("try {").i(1);
                        {
                            jsonAnnotation = method.getAnnotation(Json.class);
                            Style style = jsonAnnotation != null ? jsonAnnotation.style() : classStyle;
                            p("return " + locator.decodeExpression(resultType,
                                    JSON_PARSER_CLASS + ".parse(__method.getResponse().getText())", style)
                                    + ";");
                        }
                        i(-1).p("} catch (Throwable __e) {").i(1);
                        {
                            p("throw new " + RESPONSE_FORMAT_EXCEPTION_CLASS
                                    + "(\"Response was NOT a valid JSON document\", __e);");
                        }
                        i(-1).p("}");
                    }
                    i(-1).p("}");
                }
                i(-1).p("});");
            }
            i(-1).p("} catch (" + REQUEST_EXCEPTION_CLASS + " __e) {").i(1);
            {
                p("callback.onFailure(__method,__e);");
            }
            i(-1).p("}");
        }
    }
    i(-1).p("}");
}

From source file:com.seanchenxi.gwt.storage.rebind.TypeXmlFinder.java

License:Apache License

private void parsePrimitiveTypes(Set<JType> serializables, boolean autoArrayType) {
    logger.branch(TreeLogger.Type.DEBUG, "Adding all primitive types");
    // All primitive types and its array types will be considered as serializable
    for (JPrimitiveType jpt : JPrimitiveType.values()) {
        if (JPrimitiveType.VOID.equals(jpt)) {
            continue;
        }//from   w  w w  .ja  v  a  2  s  .  co  m
        JClassType jBoxedType = typeOracle.findType(jpt.getQualifiedBoxedSourceName());
        boolean added = false;
        if (autoArrayType) {
            if (addIfIsValidType(serializables, typeOracle.getArrayType(jpt), logger))
                added = addIfIsValidType(serializables, typeOracle.getArrayType(jBoxedType), logger);
        } else {
            if (addIfIsValidType(serializables, jpt, logger))
                added = addIfIsValidType(serializables, jBoxedType, logger);
        }
        if (added)
            logger.branch(TreeLogger.Type.TRACE, "Added " + jpt.getQualifiedSourceName());
    }
}