Search in sources :

Example 1 with StringSourceWriter

use of com.google.gwt.user.rebind.StringSourceWriter in project rstudio by rstudio.

the class StaticDataResourceGenerator method createAssignment.

@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();
    }
    URL resource = resources[0];
    String outputUrlExpression = context.deploy(resource, null, true);
    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + StaticDataResource.class.getName() + "() {");
    sw.indent();
    // Convenience when examining the generated code.
    sw.println("// " + resource.toExternalForm());
    sw.println("public String getUrl() {");
    sw.indent();
    sw.println("return " + outputUrlExpression + ";");
    sw.outdent();
    sw.println("}");
    sw.println("public com.google.gwt.safehtml.shared.SafeUri getSafeUri() {");
    sw.indent();
    sw.println("return new org.rstudio.core.client.SafeUriStringImpl(" + outputUrlExpression + ");");
    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();
}
Also used : UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) StaticDataResource(org.rstudio.core.client.resources.StaticDataResource) StringSourceWriter(com.google.gwt.user.rebind.StringSourceWriter) SourceWriter(com.google.gwt.user.rebind.SourceWriter) URL(java.net.URL) StringSourceWriter(com.google.gwt.user.rebind.StringSourceWriter)

Aggregations

UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)1 SourceWriter (com.google.gwt.user.rebind.SourceWriter)1 StringSourceWriter (com.google.gwt.user.rebind.StringSourceWriter)1 URL (java.net.URL)1 StaticDataResource (org.rstudio.core.client.resources.StaticDataResource)1