use of com.google.gwt.user.rebind.ClassSourceFileComposerFactory in project GwtMobile by dennisjzh.
the class GenUtils method generateClass.
public String generateClass(String requestedTypeName, String gennedTypeNameSuffix, ClassGenerator classGenerator) {
// The package the class is going to be in.
String packageName = getPackageName(requestedTypeName);
String gennedTypeName = getClassName(requestedTypeName) + gennedTypeNameSuffix;
PrintWriter pw = context.tryCreate(logger, packageName, gennedTypeName);
// No PrintWriter means we've generated the same code before.
if (pw != null) {
factory = new ClassSourceFileComposerFactory(packageName, gennedTypeName);
classGenerator.classSetup();
sw = factory.createSourceWriter(context, pw);
classGenerator.generateClass();
sw.commit(logger);
}
return packageName + "." + gennedTypeName;
}
use of com.google.gwt.user.rebind.ClassSourceFileComposerFactory in project che by eclipse.
the class ExtensionRegistryGenerator method generateClass.
/**
* Generate the content of the class
*
* @param logger
* @param context
* @param packageName
* @param className
* @param extensions
* @throws UnableToCompleteException
*/
private void generateClass(TreeLogger logger, GeneratorContext context, String packageName, String className, List<JClassType> extensions) throws UnableToCompleteException {
PrintWriter pw = context.tryCreate(logger, packageName, className);
if (pw == null) {
return;
}
ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);
// generate imports
generateImports(extensions, composerFactory);
// interface
composerFactory.addImplementedInterface(ExtensionRegistry.class.getCanonicalName());
// get source writer
SourceWriter sw = composerFactory.createSourceWriter(context, pw);
// begin class definition
// fields
sw.println("private final Map<String, ExtensionDescription> extensions = new HashMap<>();");
generateConstructor(className, extensions, sw);
// methods
generateGetExtensionsMethod(sw);
// close it out
sw.outdent();
sw.println("}");
context.commit(logger, pw);
}
use of com.google.gwt.user.rebind.ClassSourceFileComposerFactory 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.ClassSourceFileComposerFactory 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.ClassSourceFileComposerFactory 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;
}
Aggregations