use of com.google.gwt.user.rebind.SourceWriter in project gwt-test-utils by gwt-test-utils.
the class MyGenerator method generate.
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
String packageName = "com.slazzer";
String className = "MyGeneratedClass";
ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, className);
PrintWriter pw = context.tryCreate(logger, packageName, className);
if (pw != null) {
factory.addImplementedInterface(IGenerateWith.class.getCanonicalName());
factory.addImport(GWT.class.getCanonicalName());
factory.addImport(JavaScriptObject.class.getCanonicalName());
factory.addImport(HashMap.class.getCanonicalName());
SourceWriter writer = factory.createSourceWriter(context, pw);
writer.println("public String getMessage() {");
writer.println(" return \"generated with MyGenerator class\";");
writer.println("}");
writer.commit(logger);
}
return factory.getCreatedClassName();
}
use of com.google.gwt.user.rebind.SourceWriter in project libgdx by libgdx.
the class PreloaderBundleGenerator method createDummyClass.
private String createDummyClass(TreeLogger logger, GeneratorContext context) {
String packageName = "com.badlogic.gdx.backends.gwt.preloader";
String className = "PreloaderBundleImpl";
ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);
composer.addImplementedInterface(packageName + ".PreloaderBundle");
PrintWriter printWriter = context.tryCreate(logger, packageName, className);
if (printWriter == null) {
return packageName + "." + className;
}
SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);
sourceWriter.commit(logger);
return packageName + "." + className;
}
use of com.google.gwt.user.rebind.SourceWriter in project gwtphonegap by dankurka.
the class PhoneGapLogValueGenerator method generate.
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
PropertyOracle propertyOracle = context.getPropertyOracle();
ConfigurationProperty property = null;
int value = 100;
try {
property = propertyOracle.getConfigurationProperty("phonegap.logging.maxentries");
List<String> values = property.getValues();
if (values.size() < 1) {
logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100");
} else {
String stringValue = values.get(0);
try {
value = Integer.parseInt(stringValue);
} catch (Exception e) {
logger.log(TreeLogger.WARN, "can not prase phonegap.logging.maxentries variable - value: '" + stringValue + "' - defaulting to 100");
}
}
} catch (BadPropertyValueException e) {
logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100", e);
}
JClassType classType = null;
try {
classType = context.getTypeOracle().getType(typeName);
} catch (NotFoundException e) {
logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e);
throw new UnableToCompleteException();
}
String packageName = classType.getPackage().getName();
String simpleName = classType.getSimpleSourceName() + "_" + value;
String fullName = packageName + "." + simpleName;
ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
composer.addImplementedInterface(typeName);
composer.addImport(typeName);
PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
if (printWriter == null) {
return fullName;
}
SourceWriter writer = composer.createSourceWriter(context, printWriter);
writer.println("public int getMaxEntries() {");
writer.println("return " + value + ";");
writer.println("}");
writer.commit(logger);
return fullName;
}
use of com.google.gwt.user.rebind.SourceWriter 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();
}
use of com.google.gwt.user.rebind.SourceWriter in project rstudio by rstudio.
the class ImageResourceInfo method generate.
/**
* Generates the impl class and returns its name.
*/
public String generate() throws Exception {
ImageResourceInfo images = generateImageBundle();
simpleName_ = bundleType_.getName().replace('.', '_') + "__Impl";
PrintWriter printWriter = context_.tryCreate(logger_, packageName_, simpleName_);
if (printWriter != null) {
// always null only when printWriter is also null.
assert images != null;
ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName_, simpleName_);
factory.setSuperclass(bundleType_.getName());
factory.addImport("org.rstudio.core.client.command.AppCommand");
factory.addImport("org.rstudio.core.client.command.MenuCallback");
factory.addImport("org.rstudio.core.client.command.ShortcutManager");
factory.addImport("org.rstudio.core.client.resources.ImageResource2x");
SourceWriter writer = factory.createSourceWriter(context_, printWriter);
emitConstructor(writer, images);
emitCommandFields(writer);
emitMenus(writer);
emitShortcuts(writer);
emitCommandAccessors(writer);
// Close the class and commit it
writer.outdent();
writer.println("}");
context_.commit(logger_, printWriter);
}
return packageName_ + "." + simpleName_;
}
Aggregations