Package com.google.template.soy.soytree

Examples of com.google.template.soy.soytree.ForeachNonemptyNode


     * Do multiple inferences so we can make sure we get to a consistent context regardless of
     * how many times the loop is entered.
     */
    @Override protected void visitForeachNode(ForeachNode foreachNode) {
      List<SoyNode> foreachChildren = foreachNode.getChildren();
      ForeachNonemptyNode neNode = (ForeachNonemptyNode) foreachChildren.get(0);
      ForeachIfemptyNode ieNode;
      if (foreachChildren.size() == 2) {
        ieNode = (ForeachIfemptyNode) foreachChildren.get(1);
      } else if (foreachChildren.size() == 1) {
        ieNode = null;
      } else {
        throw new AssertionError();
      }
      try {
        Context afterBody = context;
        if (neNode != null) {
          afterBody = infer(neNode, context);
          // Make sure that repeated invocations of the body end up in the same state.
          Context elseContext = infer(neNode, afterBody);
          Context combined = Context.union(elseContext, afterBody);
          if (combined.isErrorContext()) {
            throw SoyAutoescapeException.createWithNode(
                "{foreach} body does not end in the same context after repeated entries : " +
                    neNode.toSourceString(),
                neNode);
          }
          afterBody = combined;
        }
        Context ifemptyContext;
View Full Code Here


    assertEquals("goo", fn0.getVarName());
    assertEquals("$goose", fn0.getExprText());
    assertEquals(0, ((DataRefNode) fn0.getExpr().getChild(0)).numChildren());
    assertEquals(1, fn0.numChildren());

    ForeachNonemptyNode fn0fnn0 = (ForeachNonemptyNode) fn0.getChild(0);
    assertEquals(2, fn0fnn0.numChildren());
    assertEquals("$goose.numKids", ((PrintNode) fn0fnn0.getChild(0)).getExprText());
    assertEquals(" goslings.\n", ((RawTextNode) fn0fnn0.getChild(1)).getRawText());

    ForeachNode fn1 = (ForeachNode) nodes.get(1);
    assertEquals("boo", fn1.getVarName());
    assertEquals("$foo.booze", fn1.getExprText());
    assertEquals(1, ((DataRefNode) fn1.getExpr().getChild(0)).numChildren());
    assertEquals(2, fn1.numChildren());

    ForeachNonemptyNode fn1fnn0 = (ForeachNonemptyNode) fn1.getChild(0);
    assertEquals("boo", fn1fnn0.getVarName());
    assertEquals("$foo.booze", fn1fnn0.getExprText());
    assertEquals("boo", fn1fnn0.getVarName());
    assertEquals(4, fn1fnn0.numChildren());
    IfNode fn1fnn0in = (IfNode) fn1fnn0.getChild(3);
    assertEquals(1, fn1fnn0in.numChildren());
    assertEquals("not isLast($boo)", ((IfCondNode) fn1fnn0in.getChild(0)).getExprText());

    ForeachIfemptyNode fn1fin1 = (ForeachIfemptyNode) fn1.getChild(1);
    assertEquals(1, fn1fin1.numChildren());
View Full Code Here

    PrintNode bc = (PrintNode) template.getChild(1);
    IfNode ifNode = (IfNode) template.getChild(2);
    IfCondNode ifCondNode = (IfCondNode) ifNode.getChild(0);
    PrintNode e = (PrintNode) ifCondNode.getChild(0);
    ForeachNode foreachNode = (ForeachNode) ifCondNode.getChild(1);
    ForeachNonemptyNode foreachNonemptyNode = (ForeachNonemptyNode) foreachNode.getChild(0);
    PrintNode f = (PrintNode) foreachNonemptyNode.getChild(0);
    PrintNode gh = (PrintNode) foreachNonemptyNode.getChild(1);
    PrintDirectiveNode ghPdn = gh.getChild(0);
    MsgNode msgNode = (MsgNode) foreachNonemptyNode.getChild(2);
    MsgPlaceholderNode iPh = (MsgPlaceholderNode) msgNode.getChild(0);
    PrintNode i = (PrintNode) iPh.getChild(0);
    MsgPlaceholderNode callPh = (MsgPlaceholderNode) msgNode.getChild(1);
    CallNode callNode = (CallNode) callPh.getChild(0);
    CallParamValueNode cpvn = (CallParamValueNode) callNode.getChild(0);
View Full Code Here

TOP

Related Classes of com.google.template.soy.soytree.ForeachNonemptyNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.