Search in sources :

Example 1 with GenerateParseInfoVisitor

use of com.google.template.soy.parseinfo.passes.GenerateParseInfoVisitor in project closure-templates by google.

the class SoyFileSet method generateParseInfo.

/**
 * Generates Java classes containing parse info (param names, template names, meta info). There
 * will be one Java class per Soy file.
 *
 * @param javaPackage The Java package for the generated classes.
 * @param javaClassNameSource Source of the generated class names. Must be one of "filename",
 *     "namespace", or "generic".
 * @return A map from generated file name (of the form "<*>SoyInfo.java") to generated file
 *     content.
 * @throws SoyCompilationException If compilation fails.
 */
ImmutableMap<String, String> generateParseInfo(String javaPackage, String javaClassNameSource) {
    resetErrorReporter();
    // TODO(lukes): see if we can enforce that globals are provided at compile time here. given that
    // types have to be, this should be possible.  Currently it is disabled for backwards
    // compatibility
    // N.B. we do not run the optimizer here for 2 reasons:
    // 1. it would just waste time, since we are not running code generation the optimization work
    // doesn't help anything
    // 2. it potentially removes metadata from the tree by precalculating expressions. For example,
    // trivial print nodes are evaluated, which can remove globals from the tree, but the
    // generator requires data about globals to generate accurate proto descriptors.  Also, the
    // ChangeCallsToPassAllData pass will change the params of templates.
    ParseResult result = parse(passManagerBuilder(SyntaxVersion.V2_0).allowUnknownGlobals().optimize(false), typeRegistry, new PluginResolver(// we allow undefined plugins since they typically aren't provided :(
    PluginResolver.Mode.ALLOW_UNDEFINED, printDirectives, soyFunctionMap, errorReporter));
    throwIfErrorsPresent();
    SoyFileSetNode soyTree = result.fileSet();
    TemplateRegistry registry = result.registry();
    // Do renaming of package-relative class names.
    ImmutableMap<String, String> parseInfo = new GenerateParseInfoVisitor(javaPackage, javaClassNameSource, registry).exec(soyTree);
    throwIfErrorsPresent();
    reportWarnings();
    return parseInfo;
}
Also used : TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) GenerateParseInfoVisitor(com.google.template.soy.parseinfo.passes.GenerateParseInfoVisitor) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) PluginResolver(com.google.template.soy.soyparse.PluginResolver)

Aggregations

ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)1 GenerateParseInfoVisitor (com.google.template.soy.parseinfo.passes.GenerateParseInfoVisitor)1 PluginResolver (com.google.template.soy.soyparse.PluginResolver)1 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)1 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)1