if (pw == null) {
return packageName + "." + simpleSourceName;
}
// start making the class, with basic imports
ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName);
factory.addImplementedInterface(typeName);
SourceWriter sw = factory.createSourceWriter(context, pw);
// for each method,
for (JMethod m : toGenerate.getOverridableMethods()) {
TreeLogger l = logger.branch(Type.DEBUG, "Building method: " + m.getReadableDeclaration());
// no support for params at this time
if (m.getParameters().length != 0) {
l.log(Type.ERROR, "Method " + m.toString() + " must not have parameters.");
throw new UnableToCompleteException();
}
// ask for the types that provide the property data
JClassType ret = m.getReturnType().isClassOrInterface();
final AbstractCreator c;
if (ret.isAssignableTo(valueProviderInterface)) {
c = new ValueProviderCreator(context, l, m);
} else if (ret.isAssignableTo(modelKeyProviderInterface)) {
c = new ModelKeyProviderCreator(context, l, m);
} else if (ret.isAssignableTo(labelProviderInterface)) {
c = new LabelProviderCreator(context, l, m);
} else {
logger.log(Type.ERROR, "Method uses a return type that cannot be generated");
throw new UnableToCompleteException();
}
c.create();
// build the method
// public ValueProvider<T, V> name() { return NameValueProvider.instance;
// }
sw.println("public %1$s %2$s() {", m.getReturnType().getQualifiedSourceName(), m.getName());
sw.indentln("return %1$s;", c.getInstanceExpression());
sw.println("}");
}
sw.commit(logger);
return factory.getCreatedClassName();
}