Package com.google.template.soy.exprtree

Examples of com.google.template.soy.exprtree.ExprNode


    BlockNode parent = node.getParent();
    if (parent instanceof MsgBlockNode) {
      return// don't replace this node
    }

    ExprNode expr = node.getExprUnion().getExpr().getChild(0);
    if (!(expr instanceof FunctionNode)) {
      return// don't replace this node
    }

    if (!bidiGlobalDir.isStaticValue()) {
View Full Code Here


  /**
   * Private helper to check the rewrite of one expression.
   */
  private void assertRewrite(String origSrc, String expectedRewrittenSrc) throws Exception {

    ExprNode expr = (new ExpressionParser(origSrc)).parseExpression();
    (new RewriteNullCoalescingOpInExprVisitor()).exec(expr);
    String rewrittenSrc = expr.toSourceString();
    assertEquals(expectedRewrittenSrc, rewrittenSrc);
  }
View Full Code Here

      }
      String name = matcher.group(1);
      String valueText = matcher.group(2).trim();

      try {
        ExprNode valueExpr = (new ExpressionParser(valueText)).parseExpression().getChild(0);

        // Handle negative numbers as a special case.
        // TODO: Consider changing parser to actually parse negative numbers as primitives.
        if (valueExpr instanceof NegativeOpNode) {
          ExprNode childExpr = ((NegativeOpNode) valueExpr).getChild(0);
          if (childExpr instanceof IntegerNode) {
            compileTimeGlobalsBuilder.put(
                name, IntegerData.forValue(-((IntegerNode) childExpr).getValue()));
            continue;
          } else if (childExpr instanceof FloatNode) {
View Full Code Here

        // Check that the expression is a valid reference.
        boolean isInvalidExpr = false;
        if (newPrintNode.getExprUnion().getExpr() == null) {
          isInvalidExpr = true;
        } else {
          ExprNode exprNode = newPrintNode.getExprUnion().getExpr().getChild(0);
          if (! (exprNode instanceof DataRefNode || exprNode instanceof GlobalNode)) {
            isInvalidExpr = true;
          }
        }
        if (isInvalidExpr) {
View Full Code Here

    @Override protected void visitNullCoalescingOpNode(NullCoalescingOpNode node) {

      visitChildrenAllowingConcurrentModification(node);

      ExprNode operand0a = node.getChild(0);
      ExprNode operand0b = operand0a.clone();
      ExprNode operand1 = node.getChild(1);

      FunctionNode isNonnullFnNode = new FunctionNode("isNonnull");
      isNonnullFnNode.addChild(operand0a);

      ConditionalOpNode condOpNode = new ConditionalOpNode();
View Full Code Here

    if (exprRoot == null) {
      return null;
    }

    ExprNode expr = exprRoot.getChild(0);
    switch (expr.getKind()) {
      case NULL_NODE: return NullData.INSTANCE;
      case BOOLEAN_NODE: return BooleanData.forValue(((BooleanNode) expr).getValue());
      case INTEGER_NODE: return IntegerData.forValue(((IntegerNode) expr).getValue());
      case FLOAT_NODE: return FloatData.forValue(((FloatNode) expr).getValue());
      case STRING_NODE: return StringData.forValue(((StringNode) expr).getValue());
View Full Code Here

   * @param fallbackBaseName The fallback base name.
   * @return The base placeholder (or plural/select var) name for the given expression.
   */
  static String genBaseNameFromExpr(ExprRootNode<?> exprRoot, String fallbackBaseName) {

    ExprNode exprNode = exprRoot.getChild(0);

    if (exprNode instanceof DataRefNode) {
      DataRefNode dataRefNode = (DataRefNode) exprNode;

      if (dataRefNode.numChildren() > 0) {
        ExprNode lastChild = dataRefNode.getChild(dataRefNode.numChildren() - 1);
        // Only handle if last child is a key. Else, fall through.
        if (lastChild instanceof DataRefAccessKeyNode) {
          return BaseUtils.convertToUpperUnderscore(((DataRefAccessKeyNode) lastChild).getKey());
        }
      } else {
View Full Code Here

  @Override protected void visitDataRefNode(DataRefNode node) {

    boolean allExprsAreConstant = true;
    for (ExprNode child : node.getChildren()) {
      if (child instanceof DataRefAccessExprNode) {
        ExprNode expr = ((DataRefAccessExprNode) child).getChild(0);
        visit(expr);
        if (! (expr instanceof ConstantNode)) {
          allExprsAreConstant = false;
        }
      }
View Full Code Here

    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)*/ {
View Full Code Here

    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)*/ {
View Full Code Here

TOP

Related Classes of com.google.template.soy.exprtree.ExprNode

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.