use of com.google.template.soy.jbcsrc.SoyNodeCompiler.CompiledMethodBody in project closure-templates by google.
the class TemplateCompiler method generateRenderMethod.
private Statement generateRenderMethod() {
final Label start = new Label();
final Label end = new Label();
final LocalVariable thisVar = createThisVar(template.typeInfo(), start, end);
final LocalVariable appendableVar = createLocal("appendable", 1, LOGGING_ADVISING_APPENDABLE_TYPE, start, end).asNonNullable();
final LocalVariable contextVar = createLocal("context", 2, RENDER_CONTEXT_TYPE, start, end).asNonNullable();
final TemplateVariableManager variableSet = new TemplateVariableManager(fieldNames, template.typeInfo(), thisVar, template.renderMethod().method());
TemplateNode node = template.node();
TemplateVariables variables = new TemplateVariables(variableSet, thisVar, new RenderContextExpression(contextVar));
final CompiledMethodBody methodBody = SoyNodeCompiler.create(registry, innerClasses, stateField, thisVar, AppendableExpression.forLocal(appendableVar), variableSet, variables).compile(node);
final Statement returnDone = Statement.returnExpression(MethodRef.RENDER_RESULT_DONE.invoke());
new Statement() {
@Override
protected void doGen(CodeBuilder adapter) {
adapter.mark(start);
methodBody.body().gen(adapter);
adapter.mark(end);
returnDone.gen(adapter);
thisVar.tableEntry(adapter);
appendableVar.tableEntry(adapter);
contextVar.tableEntry(adapter);
variableSet.generateTableEntries(adapter);
}
}.writeIOExceptionMethod(Opcodes.ACC_PUBLIC, template.renderMethod().method(), writer);
writer.setNumDetachStates(methodBody.numberOfDetachStates());
variableSet.defineStaticFields(writer);
return variableSet.defineFields(writer);
}
Aggregations