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

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

Introduction

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

Prototype

void println(String s);

Source Link

Usage

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

License:Open Source License

private void writeMethodCall(SourceWriter srcWriter, JMethod method, JParameter callbackParam) {
    srcWriter.print("REST.<%s> withCallback(compositeCallback).call(restService).%s(",
            this.typeAsString(method.getReturnType(), true), method.getName());
    int i = 0;//ww w . j a v a2  s.c  o m
    for (JParameter parameter : method.getParameters()) {
        if (!parameter.equals(callbackParam)) {
            if (i++ > 0) {
                srcWriter.print(", ");
            }
            srcWriter.print("$%d_%s", i, parameter.getName());
        }
    }
    srcWriter.println(");");
}

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   ww  w .jav a  2 s.  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();//  ww w .  j  a  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();
    }/*from   w  ww. j  a  v  a  2 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();
}

From source file:gwt.g2d.resources.ExternalImageResourceGenerator.java

License:Apache License

@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {
    String name = "ExternalImageResourceGenerator.createAssignment";
    URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method);

    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + ExternalImageResource.class.getName() + "() {");
    sw.indent();/*from ww  w. ja va 2  s.co  m*/

    sw.println(String.format("public void getImage(%s<%s> callback) {", ResourceCallback.class.getName(),
            ImageElementResource.class.getName()));
    sw.indent();

    int index = 0;
    String abstractImageElementResourceClassName = AbstractImageElementResource.class.getName();
    for (URL resource : resources) {
        String outputUrlExpression = context.deploy(resource, false);
        sw.println("{");
        sw.println(abstractImageElementResourceClassName + " imgResource = new "
                + abstractImageElementResourceClassName + "() {");

        sw.indent();

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

        sw.println("public String getBaseUrl() {");
        sw.indent();
        sw.println("return \"" + ResourceGeneratorUtil.baseName(resource) + "\";");
        sw.outdent();
        sw.println("}");

        sw.println("public int getIndex() {");
        sw.indent();
        sw.println("return " + index + ";");
        sw.outdent();
        sw.println("}");

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

        sw.println(ImageLoader.class.getName() + ".loadImageAsync(" + outputUrlExpression
                + ", imgResource, callback);");
        sw.println("}");
        index++;
    }
    sw.outdent();
    sw.println("}");

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

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

    return sw.toString();
}

From source file:gwt.g3d.resources.ExternalMeshResourceGenerator.java

License:Apache License

@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {
    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();
    }//from ww  w  . j av a2s .c  om

    MeshDataInfo meshDataInfo = getMeshDataInfo(method);

    String url = null;
    URL modelUrl = resources[0];
    if (modelUrl.getFile().endsWith(".obj")) {
        try {
            String content = Util.readURLAsString(modelUrl);
            File outFile = File.createTempFile("temp", ".json");
            BufferedWriter writer = new BufferedWriter(new FileWriter(outFile));
            new ObjParser().parse(content).export(meshDataInfo, writer);
            writer.close();
            url = context.deploy(outFile.toURI().toURL(), true);
        } catch (ParserException e) {
            e.printStackTrace();
            throw new UnableToCompleteException();
        } catch (IOException e) {
            e.printStackTrace();
            throw new UnableToCompleteException();
        }
    } else if (modelUrl.getFile().endsWith(".json")) {
        url = context.deploy(modelUrl, true);
    } else {
        // Unsupported format.
        throw new UnableToCompleteException();
    }

    SourceWriter sw = new StringSourceWriter();
    sw.println(String.format("new %s() {", AbstractExternalMeshResource.class.getName()));
    sw.indent();

    // Creates method: void getMesh(ResourceCallback<MeshResource>);
    sw.println(String.format("public void getMesh(%s<%s> callback) {", ResourceCallback.class.getName(),
            MeshResource.class.getName()));
    sw.indent();

    // Creates the MeshDataInfo.
    sw.println(String.format("%s meshDataInfo = new %s();", MeshDataInfo.class.getName(),
            MeshDataInfo.class.getName()));

    sw.println(String.format("meshDataInfo.setPositionDataType(%s.%s);", DataType.class.getName(),
            meshDataInfo.getPositionDataType()));
    sw.println(String.format("meshDataInfo.setPositionDataSize(%s);", meshDataInfo.getPositionDataSize()));

    sw.println(String.format("meshDataInfo.setNormalDataType(%s.%s);", DataType.class.getName(),
            meshDataInfo.getNormalDataType()));
    sw.println(String.format("meshDataInfo.setNormalDataSize(%s);", meshDataInfo.getNormalDataSize()));
    sw.println(String.format("meshDataInfo.setNormalized(%s);", meshDataInfo.isNormalized()));

    sw.println(String.format("meshDataInfo.setTexCoordDataType(%s.%s);", DataType.class.getName(),
            meshDataInfo.getTexCoordDataType()));
    sw.println(String.format("meshDataInfo.setTexCoordDataSize(%s);", meshDataInfo.getTexCoordDataSize()));

    sw.println(String.format("getMesh(%s, meshDataInfo, callback);", url));
    sw.outdent();
    sw.println("}");

    // Creates method: String getName();
    sw.println("public String getName() {");
    sw.indent();
    sw.println("return \"" + method.getName() + "\";");
    sw.outdent();
    sw.println("}");

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

    return sw.toString();
}

From source file:gwt.g3d.resources.ExternalTexture2DResourceGenerator.java

License:Apache License

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

    SourceWriter sw = new StringSourceWriter();
    sw.println(String.format("new %s() {", AbstractExternalTexture2DResource.class.getName()));
    sw.indent();//  w w  w .j ava2  s  .  c om

    // Creates method: void getTexture(ResourceCallback<Texture2DResource>);
    sw.println(String.format("public void getTexture(%s<%s> textureResource) {",
            ResourceCallback.class.getName(), Texture2DResource.class.getName()));
    sw.indent();
    String externalImageResourceObjectSrc = new ExternalImageResourceGenerator().createAssignment(logger,
            context, method);
    sw.println(String.format("getTexture(%s, textureResource);", externalImageResourceObjectSrc));
    sw.outdent();
    sw.println("}");

    // Creates method: void onImageLoaded(ImageElementResource,
    //         ResourceCallback<Texture2DResource>);
    sw.println(String.format("protected void onImageLoaded(%s imageResource, %s<%s> textureResource) {",
            ImageElementResource.class.getName(), ResourceCallback.class.getName(),
            Texture2DResource.class.getName()));
    sw.indent();
    sw.println(String.format("textureResource.onSuccess(%s);",
            createAbstractTexture2DImageResource(logger, context, method)));
    sw.outdent();
    sw.println("}");

    // Creates method: String getName();
    sw.println("public String getName() {");
    sw.indent();
    sw.println("return \"" + method.getName() + "\";");
    sw.outdent();
    sw.println("}");

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

    return sw.toString();
}

From source file:gwt.g3d.resources.ExternalTexture2DResourceGenerator.java

License:Apache License

/**
 * Creates an assignment for an {@link AbstractTexture2DResource} object.
 *//*from   w w w  .j  av a2 s .c o m*/
private String createAbstractTexture2DImageResource(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {

    SourceWriter sw = new StringSourceWriter();
    sw.println(String.format("new %s(imageResource) {", AbstractTexture2DResource.class.getName()));
    sw.indent();

    // Creates method: void setTextureParameters(Texture2D);
    String texture2DClassName = Texture2D.class.getName();
    sw.println(String.format("protected void setTextureParameters(%s texture2d) {", texture2DClassName));
    sw.indent();

    // Sets up the parameters as declared.
    {
        MagFilter magFilter = method.getAnnotation(MagFilter.class);
        TextureMagFilter textureMagFilter = magFilter != null ? magFilter.value() : TextureMagFilter.LINEAR;
        sw.println(String.format("texture2d.setMagFilter(%s.%s);", TextureMagFilter.class.getName(),
                textureMagFilter));
    }

    {
        MinFilter minFilter = method.getAnnotation(MinFilter.class);
        TextureMinFilter textureMinFilter = minFilter != null ? minFilter.value() : TextureMinFilter.LINEAR;
        sw.println(String.format("texture2d.setMinFilter(%s.%s);", TextureMinFilter.class.getName(),
                textureMinFilter));
    }

    {
        WrapMode wrapMode = method.getAnnotation(WrapMode.class);
        if (wrapMode != null) {
            sw.println(String.format("texture2d.setWrapMode(%s.%s);", TextureWrapMode.class.getName(),
                    wrapMode.value()));
        }
    }

    if (method.getAnnotation(GenerateMipmap.class) != null) {
        sw.println("texture2d.generateMipmap();");
    }
    sw.outdent();
    sw.println("}");

    // Creates method: String getName();
    sw.println("public String getName() {");
    sw.indent();
    sw.println("return \"" + method.getName() + "\";");
    sw.outdent();
    sw.println("}");

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

From source file:gwt.g3d.resources.ShaderResourceGenerator.java

License:Apache License

@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {
    URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method);

    if (resources.length != 2) {
        logger.log(TreeLogger.ERROR, "Exactly two resources must be specified", null);
        throw new UnableToCompleteException();
    }//from  ww  w.ja va  2s  .  c  o  m

    SourceWriter sw = new StringSourceWriter();
    sw.println("new " + ShaderResource.class.getName() + "() {");
    sw.indent();

    sw.println("public String getVertexShaderSource() {");
    sw.indent();
    String vertexSource = Generator.escape(Util.readURLAsString(resources[0]));
    sw.println("return \"" + vertexSource + "\";");
    sw.outdent();
    sw.println("}");

    sw.println("public String getFragmentShaderSource() {");
    sw.indent();
    String fragmentSource = Generator.escape(Util.readURLAsString(resources[1]));
    sw.println("return \"" + fragmentSource + "\";");
    sw.outdent();
    sw.println("}");

    sw.println(String.format("public %s createShader(%s gl) throws %s {", AbstractShader.class.getName(),
            GL2.class.getName(), ShaderException.class.getName()));
    sw.indent();
    sw.println(String.format("%s shader = %s;", AbstractShader.class.getName(),
            createAbstractShader(logger, context, method)));
    sw.println("shader.init(gl);");
    sw.println("return shader;");
    sw.outdent();
    sw.println("}");

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

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

    return sw.toString();
}

From source file:gwt.g3d.resources.ShaderResourceGenerator.java

License:Apache License

/**
 * Creates an assignment for {@link AbstractShader}.
 *///from ww  w.  ja  v a 2s .  c o m
private String createAbstractShader(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {
    SourceWriter sw = new StringSourceWriter();
    sw.println("new " + AbstractShader.class.getName() + "() {");
    sw.indent();

    sw.println(String.format("protected void initImpl() throws %s {", ShaderException.class.getName()));
    sw.indent();
    sw.println("initProgram(getVertexShaderSource(), getFragmentShaderSource());");
    sw.outdent();
    sw.println("}");

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