Package com.google.template.soy.exprtree

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



  public void testParseFunctionCall() throws Exception {

    ExprRootNode<?> expr = (new ExpressionParser("isFirst($x)")).parseExpression();
    FunctionNode isFirstFn = (FunctionNode) expr.getChild(0);
    assertEquals("isFirst", isFirstFn.getFunctionName());
    assertEquals(1, isFirstFn.numChildren());
    assertEquals("$x", ((DataRefNode) isFirstFn.getChild(0)).toSourceString());

    expr = (new ExpressionParser("round(3.14159, 2)")).parseExpression();
    FunctionNode roundFn = (FunctionNode) expr.getChild(0);
    assertEquals("round", roundFn.getFunctionName());
    assertEquals(2, roundFn.numChildren());
    assertEquals(3.14159, ((FloatNode) roundFn.getChild(0)).getValue());
    assertEquals(2, ((IntegerNode) roundFn.getChild(1)).getValue());
  }
View Full Code Here


      return;
    }

    // Check for the function node with the function "remainder()".
    if (exprRootNode.getChild(0) instanceof FunctionNode) {
      FunctionNode functionNode = (FunctionNode) exprRootNode.getChild(0);
      if (functionNode.getFunctionName().equals("remainder")) {

        if (currPluralNode == null) {
          // 'remainder' outside 'plural'. Bad!
          throw SoySyntaxExceptionUtils.createWithNode(
              "The special function 'remainder' is for use in plural messages" +
                  " (tag " + node.toSourceString() + ").",
              node);
        }
        // 'remainder' with no parameters or more than one parameter. Bad!
        if (functionNode.numChildren() != 1) {
          throw SoySyntaxExceptionUtils.createWithNode(
              "The function 'remainder' has to have exactly one argument" +
                  " (tag " + node.toSourceString() + ").",
              node);
        }
        // 'remainder' with a different expression than the enclosing 'plural'. Bad!
        if (! functionNode.getChild(0).toSourceString().equals(
                  currPluralNode.getExpr().toSourceString())) {
          throw SoySyntaxExceptionUtils.createWithNode(
              "The parameter to 'remainder' has to be the same as the 'plural' variable" +
                  " (tag " + node.toSourceString() + ").",
              node);
View Full Code Here

      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();
      condOpNode.addChild(isNonnullFnNode);
      condOpNode.addChild(operand0b);
      condOpNode.addChild(operand1);
View Full Code Here

TOP

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

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.