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();
}
Aggregations