Example usage for com.google.gwt.user.rebind SourceWriter outdent

List of usage examples for com.google.gwt.user.rebind SourceWriter outdent

Introduction

In this page you can find the example usage for com.google.gwt.user.rebind SourceWriter outdent.

Prototype

void outdent();

Source Link

Usage

From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java

License:Open Source License

private void generateProxy(TreeLogger logger, SourceWriter srcWriter) {

    String viewName = this.activityDescrition.view().getSimpleName();
    srcWriter.println();//from   w  w w  .  j ava 2 s  .  c  o  m
    srcWriter.println("private static %s view;", viewName);
    srcWriter.println();
    srcWriter.println("@Override");
    srcWriter.println("public void loadView(final ViewProxy.Callback callback) {");
    srcWriter.indent();
    if (this.activityDescrition.asyncView()) {
        srcWriter.println("GWT.runAsync(%s.class, new RunAsyncCallback() {", viewName);
        srcWriter.indent();
        srcWriter.println("public void onFailure(Throwable reason) {");
        srcWriter.indent();
        srcWriter.println("if (ApplicationUnreachableException.HTTP_DOWNLOAD_FAILURE_EXCEPTION"
                + ".equals(reason.getClass().getSimpleName())) {");
        srcWriter.indent();
        srcWriter.println("reason = new ApplicationUnreachableException(reason);");
        srcWriter.outdent();
        srcWriter.println("}");
        srcWriter.println("GWT.reportUncaughtException(reason);");
        srcWriter.outdent();
        srcWriter.println("}");
        srcWriter.println("public void onSuccess() {");
        srcWriter.indent();
        srcWriter.println("if(view == null || %s){", this.activityDescrition.scope() == Scope.PROTOTYPE);
        srcWriter.indent();
        srcWriter.println("view = GWT.create(%s.class);", viewName);
        srcWriter.outdent();
        srcWriter.println("}");
        this.generateProxyResult(logger, srcWriter);
        srcWriter.outdent();
        srcWriter.println("}");
        srcWriter.outdent();
        srcWriter.println("});");
    } else {
        srcWriter.println("if(view == null || %s){", this.activityDescrition.scope() == Scope.PROTOTYPE);
        srcWriter.indent();
        srcWriter.println("view = GWT.create(%s.class);", viewName);
        srcWriter.outdent();
        srcWriter.println("}");
        this.generateProxyResult(logger, srcWriter);
    }
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.service.rebind.ServiceBinderCreator.java

License:Open Source License

public String create(TreeLogger logger, GeneratorContext context)
        throws UnableToCompleteException, NotFoundException {
    PrintWriter printWriter = this.getPrintWriter(logger, context);
    if (printWriter == null) {
        return this.proxyModelQualifiedName;
    }/*from ww w. ja va 2  s .  c om*/

    this.serializerTypeName = this.createSerializer(logger, context);
    this.collectImports();

    SourceWriter srcWriter = this.getSourceWriter(printWriter, context);

    srcWriter.indent();
    srcWriter.println();
    this.generateSerializer(srcWriter);
    srcWriter.println();
    this.generateServiceImplementation(logger, srcWriter);
    this.generateServiceImplementationWithCallback(logger, srcWriter);

    srcWriter.outdent();
    srcWriter.commit(logger);
    return this.proxyModelQualifiedName;
}

From source file:fr.putnami.pwt.core.service.rebind.ServiceBinderCreator.java

License:Open Source License

private void writeEndMethod(SourceWriter srcWriter, JMethod method) {
    srcWriter.println("CommandController.get().invokeCommand(commandDefinition, commandParam);");
    if (method.getReturnType().equals(JPrimitiveType.BOOLEAN)) {
        srcWriter.println("return false;");
    } else if (method.getReturnType().equals(JPrimitiveType.BYTE)
            || method.getReturnType().equals(JPrimitiveType.CHAR)
            || method.getReturnType().equals(JPrimitiveType.DOUBLE)
            || method.getReturnType().equals(JPrimitiveType.FLOAT)
            || method.getReturnType().equals(JPrimitiveType.INT)
            || method.getReturnType().equals(JPrimitiveType.LONG)
            || method.getReturnType().equals(JPrimitiveType.SHORT)) {
        srcWriter.println("return 0;");
    } else if (!method.getReturnType().equals(JPrimitiveType.VOID)) {
        srcWriter.println("return null;");
    }// www  .j ava2s. co m
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.service.rebind.ServiceBinderCreator.java

License:Open Source License

private void writeCommandParam(SourceWriter srcWriter, JMethod method,
        Collection<CallbackMethod> callbackSuccess, JParameter callbackParameter) {
    boolean lazy = method.getAnnotation(LazyCommand.class) != null;
    boolean quiet = method.getAnnotation(QuietCommand.class) != null;

    srcWriter.print("CommandParam commandParam = new CommandParam(");
    srcWriter.print("%s, ", lazy);
    srcWriter.print("%s, ", quiet);
    srcWriter.print("this.serializer, ");
    srcWriter.print("Lists.newArrayList(Arrays.asList(");
    int i = 0;/*from   w  ww  .  j  a v  a2 s  . c o m*/
    for (JParameter parameter : method.getParameters()) {
        if (!parameter.equals(callbackParameter)) {
            if (i++ > 0) {
                srcWriter.print(", ");
            }
            srcWriter.print("$%d_%s", i, parameter.getName());
        }
    }
    srcWriter.println(")), ");
    srcWriter.indent();
    srcWriter.println("Lists.newArrayList(");
    srcWriter.indent();
    i = 0;
    if (callbackParameter != null) {
        srcWriter.print("$%d_%s", method.getParameters().length, callbackParameter.getName());
        i++;
    }

    if (callbackSuccess != null) {
        for (CallbackMethod callbackMethod : callbackSuccess) {
            if (i++ > 0) {
                srcWriter.print(", ");
            }
            srcWriter.println("new CallbackAdapter<%s>(){", this.typeAsString(method.getReturnType(), true));
            srcWriter.indent();
            if (callbackMethod.successMethodName != null) {
                srcWriter.println("public void onSuccess(%s result){",
                        this.typeAsString(method.getReturnType(), true));
                srcWriter.indent();
                srcWriter.println("getHandler().%s(result);", callbackMethod.successMethodName);
                srcWriter.outdent();
                srcWriter.println("}");
            }
            if (callbackMethod.failureMethodName != null) {
                srcWriter.println("public void onFailure(Throwable caught){",
                        this.typeAsString(method.getReturnType(), true));
                srcWriter.indent();
                srcWriter.println("getHandler().%s(caught);", callbackMethod.failureMethodName);
                srcWriter.outdent();
                srcWriter.println("}");
            }
            srcWriter.outdent();
            srcWriter.print("}");
        }
    }
    srcWriter.outdent();
    srcWriter.println("));");
    srcWriter.outdent();
}

From source file:fr.putnami.pwt.core.widget.rebind.UiBinderLocalizedCreator.java

License:Open Source License

public String create(TreeLogger logger, GeneratorContext context) {
    Resource templateResource = this.getTemplateResource(context);
    if (templateResource == null) {
        throw new NullPointerException("no template found");
    }// w ww .  j a  va  2  s.  co m
    this.binderProxySimpleName = this.targetType.getSimpleSourceName() + "_"
            + this.binderType.getSimpleSourceName() + UiBinderLocalizedCreator.PROXY_SUFFIX;
    if (this.locale != null) {
        this.binderProxySimpleName += "_" + this.locale.toString();
    }
    this.binderProxyQualifiedName = this.targetType.getPackage().getName() + "." + this.binderProxySimpleName;

    PrintWriter printWriter = this.getPrintWriter(logger, context, this.binderProxyQualifiedName);
    if (printWriter == null) {
        return this.binderProxyQualifiedName;
    }

    SourceWriter srcWriter = this.getSourceWriter(printWriter, context);

    srcWriter.println();
    srcWriter.indent();
    this.generateProxy(logger, srcWriter);
    srcWriter.println();
    srcWriter.outdent();

    srcWriter.commit(logger);

    return this.binderProxyQualifiedName;
}

From source file:fr.putnami.pwt.core.widget.rebind.UiBinderLocalizedCreator.java

License:Open Source License

private void generateProxy(TreeLogger logger, SourceWriter srcWriter) {

    srcWriter.println("@UiTemplate(\"%s\")", this.templateName);
    srcWriter.println("interface Binder extends UiBinder<%s, %s> {", this.widgetType.getSimpleSourceName(),
            this.targetType.getSimpleSourceName());
    srcWriter.indent();//from w  w w.  j av a 2s  .  co m
    srcWriter.println("UiBinder<%s, %s> BINDER = GWT.create(Binder.class);",
            this.widgetType.getSimpleSourceName(), this.targetType.getSimpleSourceName());
    srcWriter.outdent();
    srcWriter.println("}");
    srcWriter.println();
    srcWriter.println("@Override");
    srcWriter.println("public %s createAndBindUi(%s owner) {", this.widgetType.getSimpleSourceName(),
            this.targetType.getSimpleSourceName());
    srcWriter.indent();
    srcWriter.println("return Binder.BINDER.createAndBindUi(owner);");
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.plugin.rest.rebind.RestServiceBinderCreator.java

License:Open Source License

public String create(TreeLogger logger, GeneratorContext context) {
    PrintWriter printWriter = this.getPrintWriter(logger, context);
    if (printWriter == null) {
        return this.proxyModelQualifiedName;
    }//from  www .j  a v a  2  s. c  o  m

    this.collectImports();

    SourceWriter srcWriter = this.getSourceWriter(printWriter, context);

    srcWriter.indent();
    srcWriter.println();
    this.generateCreateService(srcWriter);
    srcWriter.println();
    this.generateServiceImplementation(logger, srcWriter);
    this.generateServiceImplementationWithCallback(srcWriter);

    srcWriter.outdent();
    srcWriter.commit(logger);
    return this.proxyModelQualifiedName;
}

From source file:fr.putnami.pwt.plugin.rest.rebind.RestServiceBinderCreator.java

License:Open Source License

private void writeEndMethod(SourceWriter srcWriter, JMethod method) {
    if (method.getReturnType().equals(JPrimitiveType.BOOLEAN)) {
        srcWriter.println("return false;");
    } else if (method.getReturnType().equals(JPrimitiveType.BYTE)
            || method.getReturnType().equals(JPrimitiveType.CHAR)
            || method.getReturnType().equals(JPrimitiveType.DOUBLE)
            || method.getReturnType().equals(JPrimitiveType.FLOAT)
            || method.getReturnType().equals(JPrimitiveType.INT)
            || method.getReturnType().equals(JPrimitiveType.LONG)
            || method.getReturnType().equals(JPrimitiveType.SHORT)) {
        srcWriter.println("return 0;");
    } else if (!method.getReturnType().equals(JPrimitiveType.VOID)) {
        srcWriter.println("return null;");
    }//from w  w  w  .  j a  v a2s . c  om
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.plugin.rest.rebind.RestServiceBinderCreator.java

License:Open Source License

private void writeMethodCallback(SourceWriter srcWriter, JMethod method,
        Collection<CallbackMethod> callbackSuccess, JParameter callbackParam) {
    boolean quiet = method.getAnnotation(QuietCommand.class) != null;

    srcWriter.print("CompositeMethodCallback compositeCallback = new CompositeMethodCallback(");
    srcWriter.print("%s, ", quiet);
    srcWriter.println("Lists.newArrayList(");
    srcWriter.indent();/*w ww. ja  v a  2 s .c o m*/
    int i = 0;
    if (callbackParam != null) {
        srcWriter.print("$%d_%s", method.getParameters().length, callbackParam);
        i++;
    }

    if (callbackSuccess != null) {
        for (CallbackMethod callbackMethod : callbackSuccess) {
            if (i++ > 0) {
                srcWriter.print(", ");
            }
            srcWriter.println("new MethodCallbackAdapter<%s>(){",
                    this.typeAsString(method.getReturnType(), true));
            srcWriter.indent();
            if (callbackMethod.successMethodName != null) {
                srcWriter.println("public void onSuccess(Method method, %s result){",
                        this.typeAsString(method.getReturnType(), true));
                srcWriter.indent();
                srcWriter.println("getHandler().%s(result);", callbackMethod.successMethodName);
                srcWriter.outdent();
                srcWriter.println("}");
            }
            if (callbackMethod.failureMethodName != null) {
                srcWriter.println("public void onFailure(Method method, Throwable caught){",
                        this.typeAsString(method.getReturnType(), true));
                srcWriter.indent();
                srcWriter.println("getHandler().%s(caught);", callbackMethod.failureMethodName);
                srcWriter.outdent();
                srcWriter.println("}");
            }
            srcWriter.outdent();
            srcWriter.print("}");
        }
    }
    srcWriter.outdent();
    srcWriter.println("));");
}

From source file:geogebra.vectomatic.SVGResourceGenerator.java

License:Open Source License

@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {

    // Extract the SVG name from the @Source annotation
    URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method);
    if (resources.length != 1) {
        logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null);
        throw new UnableToCompleteException();
    }//  ww w.  j a v  a2  s.c o  m
    URL resource = resources[0];

    // The SVGResource is implemented as an anonymous inner class
    // xxx = new SVGResource() {
    // public OMSVGSVGElement getSvg() {
    // return OMSVGParser.parse("...");
    // }
    // };
    String toWrite = Util.readURLAsString(resource);
    /*
     * if (getValidated(method)) { SVGValidator.validate(toWrite,
     * resource.toExternalForm(), logger, null); }
     */

    SourceWriter sw = new StringSourceWriter();
    sw.println("new " + SVGResource.class.getName() + "() {");
    sw.indent();
    sw.println("private String svg=\"" + Generator.escape(toWrite) + "\";");

    // Convenience when examining the generated code.
    sw.println("// " + resource.toExternalForm());

    sw.println("@Override");
    sw.println("public String getName() {");
    sw.indent();
    sw.println("return \"" + method.getName() + "\";");
    sw.outdent();
    sw.println("}");

    sw.println("@Override");
    sw.println("public String getUrl() {");
    sw.indent();
    sw.println("return \"data:image/svg+xml;base64,\" + " + Browser.class.getName() + ".base64encode(svg);");
    sw.outdent();
    sw.println("}");

    sw.println("@Override");
    sw.println("public " + SafeUri.class.getName() + " getSafeUri() {");
    sw.indent();
    sw.println("return " + UriUtils.class.getName() + ".fromSafeConstant(\"data:image/svg+xml;base64,\" + "
            + Browser.class.getName() + ".base64encode(svg));");
    sw.outdent();
    sw.println("}");

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

    return sw.toString();
}