Package com.google.template.soy.soytree

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


    // ------ Not computable as Java expressions, so generate full code. ------

    for (SoyNode child : node.getChildren()) {

      if (child instanceof IfCondNode) {
        IfCondNode icn = (IfCondNode) child;

        JavaExpr condJavaExpr =
            translateToJavaExprVisitorFactory.create(localVarTranslations)
                .exec(icn.getExprUnion().getExpr());
        if (icn.getCommandName().equals("if")) {
          javaCodeBuilder.appendLine("if (", genCoerceBoolean(condJavaExpr), ") {");
        } else // "elseif" block
          javaCodeBuilder.appendLine("} else if (", genCoerceBoolean(condJavaExpr), ") {");
        }
View Full Code Here


    boolean hasElse = false;
    for (SoyNode child : node.getChildren()) {

      if (child instanceof IfCondNode) {
        IfCondNode icn = (IfCondNode) child;

        JavaExpr condJavaExpr =
            translateToJavaExprVisitorFactory.create(localVarTranslations)
                .exec(icn.getExprUnion().getExpr());
        javaExprTextSb.append('(').append(genCoerceBoolean(condJavaExpr)).append(") ? ");

        List<JavaExpr> condBlockJavaExprs = genJavaExprsVisitor.exec(icn);
        javaExprTextSb.append(
            genMaybeProtect(JavaExprUtils.concatJavaExprs(condBlockJavaExprs),
View Full Code Here

    //     children after it, if any. Can stop processing after doing this, because the new
    //     IfElseNode is now the last child.
    // (b) If the condition is constant false: Remove the child.
    for (SoyNode child : Lists.newArrayList(node.getChildren()) /*copy*/) {
      if (child instanceof IfCondNode) {
        IfCondNode condNode = (IfCondNode) child;

        ExprRootNode<?> condExpr = condNode.getExprUnion().getExpr();
        if (! isConstant(condExpr)) {
          continue// cannot simplify this child
        }

        if (getConstantOrNull(condExpr).toBoolean()) {
          // ------ Constant true. ------
          // Remove all children after this child.
          int condIndex = node.getChildIndex(condNode);
          for (int i = node.numChildren() - 1; i > condIndex; i--) {
            node.removeChild(i);
          }
          // Replace this child with a new IfElseNode.
          IfElseNode newElseNode = new IfElseNode(nodeIdGen.genId());
          newElseNode.addChildren(condNode.getChildren());
          node.replaceChild(condIndex, newElseNode);
          // Stop processing.
          break;

        } else {
View Full Code Here

    boolean hasElse = false;
    for (SoyNode child : node.getChildren()) {

      if (child instanceof IfCondNode) {
        IfCondNode icn = (IfCondNode) child;

        JsExpr condJsExpr = jsExprTranslator.translateToJsExpr(
            icn.getExprUnion().getExpr(), icn.getExprText(), localVarTranslations);
        jsExprTextSb.append('(').append(condJsExpr.getText()).append(") ? ");

        List<JsExpr> condBlockJsExprs = genJsExprsVisitor.exec(icn);
        jsExprTextSb.append(JsExprUtils.concatJsExprs(condBlockJsExprs).getText());
View Full Code Here

  @Override protected void visitIfNode(IfNode node) {

    for (SoyNode child : node.getChildren()) {

      if (child instanceof IfCondNode) {
        IfCondNode icn = (IfCondNode) child;
        if (eval(icn.getExprUnion().getExpr()).toBoolean()) {
          visit(icn);
          return;
        }

      } else if (child instanceof IfElseNode) {
View Full Code Here

    // ------ Not computable as JS expressions, so generate full code. ------

    for (SoyNode child : node.getChildren()) {

      if (child instanceof IfCondNode) {
        IfCondNode icn = (IfCondNode) child;

        JsExpr condJsExpr = jsExprTranslator.translateToJsExpr(
            icn.getExprUnion().getExpr(), icn.getExprText(), localVarTranslations);
        if (icn.getCommandName().equals("if")) {
          jsCodeBuilder.appendLine("if (", condJsExpr.getText(), ") {");
        } else // "elseif" block
          jsCodeBuilder.appendLine("} else if (", condJsExpr.getText(), ") {");
        }
View Full Code Here

    List<StandaloneNode> nodes = parseTemplateBody(templateBody);
    assertEquals(2, nodes.size());

    IfNode in0 = (IfNode) nodes.get(0);
    assertEquals(1, in0.numChildren());
    IfCondNode in0icn0 = (IfCondNode) in0.getChild(0);
    assertEquals("$zoo", in0icn0.getExprText());
    assertEquals(1, in0icn0.numChildren());
    assertEquals("$zoo", ((PrintNode) in0icn0.getChild(0)).getExprText());
    assertTrue(in0icn0.getExprUnion().getExpr().getChild(0) instanceof DataRefNode);

    IfNode in1 = (IfNode) nodes.get(1);
    assertEquals(3, in1.numChildren());
    IfCondNode in1icn0 = (IfCondNode) in1.getChild(0);
    assertEquals("$boo", in1icn0.getExprText());
    assertTrue(in1icn0.getExprUnion().getExpr().getChild(0) instanceof DataRefNode);
    IfCondNode in1icn1 = (IfCondNode) in1.getChild(1);
    assertEquals("$foo.goo > 2", in1icn1.getExprText());
    assertTrue(in1icn1.getExprUnion().getExpr().getChild(0) instanceof GreaterThanOpNode);
    assertEquals("", ((IfElseNode) in1.getChild(2)).getCommandText());
    assertEquals("{if $boo}Blah{elseif $foo.goo > 2}{$moo}{else}Blah {$moo}{/if}",
                 in1.toSourceString());
  }
View Full Code Here

    TemplateNode template = soyTree.getChild(0).getChild(0);
    PrintNode a = (PrintNode) template.getChild(0);
    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);
View Full Code Here

TOP

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

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.