Search in sources :

Example 16 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class TypeNodeTest method parse.

private TypeNode parse(String typeString) {
    TemplateNode template = SoyFileSetParserBuilder.forTemplateContents("{@param p : " + typeString + "}\n{$p ? 't' : 'f'}").typeRegistry(new SoyTypeRegistry()).errorReporter(// ignore parse errors
    ErrorReporter.exploding()).parse().fileSet().getChild(0).getChild(0);
    HeaderParam param = (HeaderParam) Iterables.getOnlyElement(template.getAllParams());
    return param.getTypeNode();
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) HeaderParam(com.google.template.soy.soytree.defn.HeaderParam)

Example 17 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class SoyFileSet method getTransitiveIjs.

private ImmutableMap<String, ImmutableSortedSet<String>> getTransitiveIjs(SoyFileSetNode soyTree, TemplateRegistry registry) {
    ImmutableMap<TemplateNode, IjParamsInfo> templateToIjParamsInfoMap = new FindIjParamsVisitor(registry).execOnAllTemplates(soyTree);
    ImmutableMap.Builder<String, ImmutableSortedSet<String>> templateToTransitiveIjParams = ImmutableMap.builder();
    for (Map.Entry<TemplateNode, IjParamsInfo> entry : templateToIjParamsInfoMap.entrySet()) {
        templateToTransitiveIjParams.put(entry.getKey().getTemplateName(), entry.getValue().ijParamSet);
    }
    return templateToTransitiveIjParams.build();
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) IjParamsInfo(com.google.template.soy.passes.FindIjParamsVisitor.IjParamsInfo) FindIjParamsVisitor(com.google.template.soy.passes.FindIjParamsVisitor) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 18 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class FindTransitiveDepTemplatesVisitorTest method testTwoPathsToSameRecursiveCycle.

@Test
public void testTwoPathsToSameRecursiveCycle() {
    // aaa -> {bbb, ccc}, bbb -> ddd, ccc -> ddd, ddd -> bbb.
    String fileContent = "" + "{namespace ns}\n" + "\n" + "/***/\n" + "{template .aaa}\n" + "  {$ij.boo} {$ij.foo} {call .bbb /} {call .ccc /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .bbb}\n" + "  {$ij.boo} {$ij.goo} {call .ddd /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ccc}\n" + "  {$ij.boo} {$ij.moo} {call .ddd /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ddd}\n" + "  {$ij.boo} {$ij.too} {call .bbb /}\n" + "{/template}\n";
    ParseResult result = SoyFileSetParserBuilder.forFileContents(fileContent).errorReporter(FAIL).parse();
    TemplateRegistry templateRegistry = result.registry();
    SoyFileSetNode soyTree = result.fileSet();
    TemplateNode aaa = soyTree.getChild(0).getChild(0);
    TemplateNode bbb = soyTree.getChild(0).getChild(1);
    TemplateNode ccc = soyTree.getChild(0).getChild(2);
    TemplateNode ddd = soyTree.getChild(0).getChild(3);
    // Test with exec(aaa).
    // Exercises: processCalleeHelper case 4 with incorporateCalleeVisitInfo case 4 (ccc -> ddd).
    FindTransitiveDepTemplatesVisitor visitor = new FindTransitiveDepTemplatesVisitor(templateRegistry);
    Map<TemplateNode, TransitiveDepTemplatesInfo> memoizedInfoMap = visitor.templateToFinishedInfoMap;
    visitor.exec(aaa);
    assertThat(memoizedInfoMap).hasSize(4);
    assertThat(memoizedInfoMap.get(bbb).depTemplateSet).isEqualTo(ImmutableSet.of(bbb, ddd));
    assertThat(memoizedInfoMap.get(ddd).depTemplateSet).isEqualTo(ImmutableSet.of(ddd, bbb));
    assertThat(memoizedInfoMap.get(ccc).depTemplateSet).isEqualTo(ImmutableSet.of(ccc, ddd, bbb));
    assertThat(memoizedInfoMap.get(aaa).depTemplateSet).isEqualTo(ImmutableSet.of(aaa, bbb, ccc, ddd));
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) TransitiveDepTemplatesInfo(com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo) Test(org.junit.Test)

Example 19 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class FindTransitiveDepTemplatesVisitorTest method testSimpleRecursion.

@Test
public void testSimpleRecursion() {
    // Tests direct recursion (cycle of 1) and indirect recursion with a cycle of 2.
    // aaa -> bbb, bbb -> {bbb, ccc}, ccc -> bbb.
    String fileContent = "" + "{namespace ns}\n" + "\n" + "/***/\n" + "{template .aaa}\n" + "  {call .bbb /} {$ij.boo} {$ij.foo}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .bbb}\n" + "  {$ij.boo} {$ij.goo} {call .bbb /} {call .ccc /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ccc}\n" + "  {$ij.boo} {call .bbb /} {$ij.moo}\n" + "{/template}\n";
    ParseResult result = SoyFileSetParserBuilder.forFileContents(fileContent).errorReporter(FAIL).parse();
    TemplateRegistry templateRegistry = result.registry();
    SoyFileSetNode soyTree = result.fileSet();
    TemplateNode aaa = soyTree.getChild(0).getChild(0);
    TemplateNode bbb = soyTree.getChild(0).getChild(1);
    TemplateNode ccc = soyTree.getChild(0).getChild(2);
    // Test with exec(aaa).
    // Exercises: processCalleeHelper case 2 (bbb -> bbb).
    // Exercises: processCalleeHelper case 3 (ccc -> bbb).
    // Exercises: processCalleeHelper case 5 with incorporateCalleeVisitInfo case 2 (bbb -> ccc).
    FindTransitiveDepTemplatesVisitor visitor = new FindTransitiveDepTemplatesVisitor(templateRegistry);
    Map<TemplateNode, TransitiveDepTemplatesInfo> memoizedInfoMap = visitor.templateToFinishedInfoMap;
    visitor.exec(aaa);
    assertThat(memoizedInfoMap).hasSize(3);
    assertThat(memoizedInfoMap.get(ccc).depTemplateSet).isEqualTo(ImmutableSet.of(ccc, bbb));
    assertThat(memoizedInfoMap.get(bbb).depTemplateSet).isEqualTo(ImmutableSet.of(bbb, ccc));
    assertThat(memoizedInfoMap.get(aaa).depTemplateSet).isEqualTo(ImmutableSet.of(aaa, bbb, ccc));
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) TransitiveDepTemplatesInfo(com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo) Test(org.junit.Test)

Example 20 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class HtmlRewritePassTest method testDynamicTagName.

@Test
public void testDynamicTagName() {
    TemplateNode node = runPass("{let $t : 'div' /}<{$t}>content</{$t}>");
    assertThatSourceString(node).isEqualTo("{let $t : 'div' /}<{$t}>content</{$t}>");
    // NOTE: the print nodes don't end up in the AST due to how TagName works, this is probably a
    // bad idea in the long run.  We should probably make TagName be a node.
    assertThatASTString(node).isEqualTo("" + "LET_VALUE_NODE\n" + "HTML_OPEN_TAG_NODE\n" + "  PRINT_NODE\n" + "RAW_TEXT_NODE\n" + "HTML_CLOSE_TAG_NODE\n" + "  PRINT_NODE\n" + "");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) Test(org.junit.Test)

Aggregations

TemplateNode (com.google.template.soy.soytree.TemplateNode)89 Test (org.junit.Test)59 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)35 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)19 ErrorReporter (com.google.template.soy.error.ErrorReporter)11 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)10 TransitiveDepTemplatesInfo (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo)9 RawTextNode (com.google.template.soy.soytree.RawTextNode)9 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)8 TemplateParam (com.google.template.soy.soytree.defn.TemplateParam)7 FunctionNode (com.google.template.soy.exprtree.FunctionNode)6 PrintNode (com.google.template.soy.soytree.PrintNode)5 TemplateDelegateNode (com.google.template.soy.soytree.TemplateDelegateNode)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 SourceLocation (com.google.template.soy.base.SourceLocation)4 StringNode (com.google.template.soy.exprtree.StringNode)4 MsgFallbackGroupNode (com.google.template.soy.soytree.MsgFallbackGroupNode)4 ImmutableList (com.google.common.collect.ImmutableList)3 VarRefNode (com.google.template.soy.exprtree.VarRefNode)3 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)3