@Override
    public Template toTemplate(Template template) {
      try {
        Scope nestedScope = scope.nest();
        Transformer nested = new Transformer(nestedScope);
        return template
            .withDeclaration(nested.asTemplateDeclaration(template, template.declaration()))
            .withParts(nested.asTemplatePartsElements(template, template.parts()));
      } catch (RuntimeException ex) {
        throw new RuntimeException("In template " + template.declaration().name() + ": " + ex.getMessage(), ex);
      }
    }
Overriden to specify order in which we process declaration first, and then parts.
generator-processor/src/org/immutables/generator/processor/TypeResolver.java