sw.println("}");
}
private void writeMethods(SourceWriter sw) throws UnableToCompleteException {
for (AutoBeanFactoryMethod method : model.getMethods()) {
AutoBeanType autoBeanType = method.getAutoBeanType();
// public AutoBean<Foo> foo(FooSubtype wrapped) {
sw.println("public %s %s(%s) {",
method.getReturnType().getQualifiedSourceName(), method.getName(),
method.isWrapper()
? (method.getWrappedType().getQualifiedSourceName() + " wrapped")
: "");
if (method.isWrapper()) {
sw.indent();
// AutoBean<Foo> toReturn = AutoBeanUtils.getAutoBean(wrapped);
sw.println("%s toReturn = %s.getAutoBean(wrapped);",
method.getReturnType().getParameterizedQualifiedSourceName(),
AutoBeanUtils.class.getCanonicalName());
sw.println("if (toReturn != null) {return toReturn;}");
// return new FooAutoBean(Factory.this, wrapped);
sw.println("return new %s(%s.this, wrapped);",
autoBeanType.getQualifiedSourceName(), simpleSourceName);
sw.outdent();
} else {
// return new FooAutoBean(Factory.this);
sw.indentln("return new %s(%s.this);",
autoBeanType.getQualifiedSourceName(), simpleSourceName);
}
sw.println("}");
}
}