String className, Collection<GeneratedCodeMap> basePackages) {
JavaCodeGenerator generator = new JavaCodeGenerator.Impl();
GlobalScope globalScope = generator.newGlobalScope(type2TypeHandler.values(), basePackages);
FileScope fileScope = globalScope.newFileScope(stringBuilder);
fileScope.startLine("// This is a generated source.\n");
fileScope.startLine("// See " + this.getClass().getName() + " for details\n");
fileScope.append("\n");
fileScope.startLine("package " + packageName + ";\n");
fileScope.append("\n");
fileScope.startLine("public class " + className + " implements " +
rootImpl.getType().getCanonicalName() + " {\n");
ClassScope rootClassScope = fileScope.newClassScope();
rootClassScope.indentRight();
rootImpl.writeStaticMethodJava(rootClassScope);
for (TypeHandler<?> typeHandler : type2TypeHandler.values()) {
typeHandler.writeStaticClassJava(rootClassScope);
}
rootClassScope.writeClassMembers();
rootClassScope.indentLeft();
rootClassScope.startLine("}\n");
Map<Class<?>, String> type2ImplClassName = new HashMap<Class<?>, String>();
for (TypeHandler<?> typeHandler : type2TypeHandler.values()) {
String shortName = fileScope.getTypeImplShortName(typeHandler);
String fullReference = packageName + "." + className + "." + shortName;
type2ImplClassName.put(typeHandler.getTypeClass(), fullReference);
}
return new GeneratedCodeMap(type2ImplClassName);