final JClassType sourceType = typeOracle.findType(typeName);
// Ensure that the requested type exists
if (sourceType == null) {
logger.log(TreeLogger.ERROR, "Could not find requested typeName", null);
throw new UnableToCompleteException();
}
// Pick a name for the generated class to not conflict. Enclosing class
// names must be preserved.
final String generatedSimpleSourceName = "__"
+ sourceType.getName().replaceAll("\\.", "__") + "Impl";
// Begin writing the generated source.
final ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(
sourceType.getPackage().getName(), generatedSimpleSourceName);
// Pull in source imports
f.addImport(GWT.class.getName());
f.addImport(JavaScriptObject.class.getName());
// This is a cheat, but doesn't require excessive maintenance
f.addImport("com.google.gwt.jsio.client.*");
f.addImport("com.google.gwt.jsio.client.impl.*");
// Either extend an abstract base class or implement the interface
if (sourceType.isClass() != null) {
f.setSuperclass(sourceType.getQualifiedSourceName());
} else if (sourceType.isInterface() != null) {
f.addImplementedInterface(sourceType.getQualifiedSourceName());
} else {
// Something is very wrong if this statement is reached
logger.log(TreeLogger.ERROR,
"Requested JClassType is neither a class nor an interface.", null);
throw new UnableToCompleteException();
}
// All source gets written through this Writer
final PrintWriter out = context.tryCreate(logger,
sourceType.getPackage().getName(), generatedSimpleSourceName);