MethodCollector invokables = new MethodCollector(context, logger, toGenerate);
SourceWriter sw = factory.createSourceWriter(context, pw);
for (JMethod method : toGenerate.getOverridableMethods()) {
TreeLogger l = logger.branch(Type.DEBUG, "Creating XTemplate method " + method.getName());
final String template;
XTemplate marker = method.getAnnotation(XTemplate.class);
if (marker == null) {
l.log(Type.ERROR, "Unable to create template for method " + method.getReadableDeclaration()
+ ", this may cause other failures.");
continue;
} else {
if (marker.source().length() != 0) {
if (marker.value().length() != 0) {
l.log(Type.WARN, "Found both source file and inline template, using source file");
}
InputStream stream = getTemplateResource(context, method.getEnclosingType(), l, marker.source());
if (stream == null) {
l.log(Type.ERROR, "No data could be loaded - no data at path " + marker.source());
throw new UnableToCompleteException();
}
template = Util.readStreamAsString(stream);
} else if (marker.value().length() != 0) {
template = marker.value();
} else {
l.log(Type.ERROR,
"XTemplate annotation found with no contents, cannot generate method " + method.getName()
+ ", this may cause other failures.");
continue;
}
}
XTemplateParser p = new XTemplateParser(l.branch(Type.DEBUG,
"Parsing provided template for " + method.getReadableDeclaration()));
TemplateModel m = p.parse(template);
SafeHtmlTemplatesCreator safeHtml = new SafeHtmlTemplatesCreator(context, l.branch(Type.DEBUG,
"Building SafeHtmlTemplates"), method);
sw.println(method.getReadableDeclaration(false, true, true, false, true) + "{");
sw.indent();