Package com.google.template.soy.data

Examples of com.google.template.soy.data.SoyData


    // Recurse.
    visitChildren(node);

    // Can simplify if either child is constant. We assume no side-effects.
    SoyData operand0 = getConstantOrNull(node.getChild(0));
    SoyData operand1 = getConstantOrNull(node.getChild(1));
    if (operand0 == null && operand1 == null) {
      return// cannot simplify
    }

    ExprNode replacementNode;
    if (operand0 != null && operand1 != null) {
      replacementNode = new BooleanNode(operand0.toBoolean() && operand1.toBoolean());
    } else if (operand0 != null) {
      replacementNode = operand0.toBoolean() ? node.getChild(1) : new BooleanNode(false);
    } else /*(operand1 != null)*/ {
      replacementNode = operand1.toBoolean() ? node.getChild(0) : new BooleanNode(false);
    }

    node.getParent().replaceChild(node, replacementNode);
  }
View Full Code Here


  }


  @Override protected SoyData visitGreaterThanOrEqualOpNode(GreaterThanOrEqualOpNode node) {

    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) {
      return convertResult(operand0.integerValue() >= operand1.integerValue());
    } else {
      return convertResult(operand0.numberValue() >= operand1.numberValue());
    }
  }
View Full Code Here

    // Recurse.
    visitChildren(node);

    // Can simplify if either child is constant. We assume no side-effects.
    SoyData operand0 = getConstantOrNull(node.getChild(0));
    SoyData operand1 = getConstantOrNull(node.getChild(1));
    if (operand0 == null && operand1 == null) {
      return// cannot simplify
    }

    ExprNode replacementNode;
    if (operand0 != null && operand1 != null) {
      replacementNode = new BooleanNode(operand0.toBoolean() || operand1.toBoolean());
    } else if (operand0 != null) {
      replacementNode = operand0.toBoolean() ? new BooleanNode(true) : node.getChild(1);
    } else /*(operand1 != null)*/ {
      replacementNode = operand1.toBoolean() ? new BooleanNode(true) : node.getChild(0);
    }

    node.getParent().replaceChild(node, replacementNode);
  }
View Full Code Here

  }


  @Override protected SoyData visitEqualOpNode(EqualOpNode node) {

    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    return convertResult(operand0.equals(operand1));
  }
View Full Code Here

    // Recurse.
    visitChildren(node);

    // Can simplify if operand0 is constant. We assume no side-effects.
    SoyData operand0 = getConstantOrNull(node.getChild(0));
    if (operand0 == null) {
      return// cannot simplify
    }

    ExprNode replacementNode = operand0.toBoolean() ? node.getChild(1) : node.getChild(2);
    node.getParent().replaceChild(node, replacementNode);
  }
View Full Code Here

  }


  @Override protected SoyData visitNotEqualOpNode(NotEqualOpNode node) {

    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    return convertResult(!operand0.equals(operand1));
  }
View Full Code Here


  @Override protected SoyData visitAndOpNode(AndOpNode node) {

    // Note: Short-circuit evaluation.
    SoyData operand0 = visit(node.getChild(0));
    if (!operand0.toBoolean()) {
      return convertResult(false);
    } else {
      SoyData operand1 = visit(node.getChild(1));
      return convertResult(operand1.toBoolean());
    }
  }
View Full Code Here

    // (a) the expression uses a bidi function that needs bidiGlobalDir to be in scope, but the
    //     apiCallScope is not currently active,
    // (b) the expression uses an external function (Soy V1 syntax),
    // (c) other cases I haven't thought up.

    SoyData preevalResult;
    try {
      preevalResult = preevalVisitor.exec(node);
    } catch (RenderException e) {
      return// failed to preevaluate
    }
View Full Code Here


  @Override protected SoyData visitOrOpNode(OrOpNode node) {

    // Note: Short-circuit evaluation.
    SoyData operand0 = visit(node.getChild(0));
    if (operand0.toBoolean()) {
      return convertResult(true);
    } else {
      SoyData operand1 = visit(node.getChild(1));
      return convertResult(operand1.toBoolean());
    }
  }
View Full Code Here


  @Override protected SoyData visitConditionalOpNode(ConditionalOpNode node) {

    // Note: We only evaluate the part that we need.
    SoyData operand0 = visit(node.getChild(0));
    if (operand0.toBoolean()) {
      return visit(node.getChild(1));
    } else {
      return visit(node.getChild(2));
    }
  }
View Full Code Here

TOP

Related Classes of com.google.template.soy.data.SoyData

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.