Examples of JavaExpr


Examples of com.google.template.soy.javasrc.restricted.JavaExpr

      refText = genGetDataSingleCallWithKey("this.$$ijData", firstKey);
      if (node.isNullSafeIjDataRef()) {
        nullSafetyPrefix = "(this.$$ijData == null) ? " + NULL_DATA_INSTANCE + " : ";
      }
    } else {
      JavaExpr translation = getLocalVarTranslation(firstKey);
      if (translation != null) {
        // Case 2: In-scope local var.
        refText = (translation.getPrecedence() == Integer.MAX_VALUE) ?
            translation.getText() : "(" + translation.getText() + ")";
      } else {
        // Case 3: Data reference.
        refText = genGetDataSingleCallWithKey("data", firstKey);
      }
    }

    // ------ Translate the rest of the keys, if any. ------
    for (ExprNode child : node.getChildren()) {
      DataRefAccessNode accessNode = (DataRefAccessNode) child;

      if (accessNode.isNullSafe()) {
        nullSafetyPrefix +=
            "(! " + genFunctionCall(UTILS_LIB + ".$$isNonnull", refText) + ") ? " +
            NULL_DATA_INSTANCE + " : ";
      }

      switch (accessNode.getKind()) {
        case DATA_REF_ACCESS_KEY_NODE:
          refText = genGetDataSingleCallWithKey(
              refText, ((DataRefAccessKeyNode) accessNode).getKey());
          break;
        case DATA_REF_ACCESS_INDEX_NODE:
          refText = genGetDataSingleCallWithKey(
              refText,
              Integer.toString(((DataRefAccessIndexNode) accessNode).getIndex()));
          break;
        case DATA_REF_ACCESS_EXPR_NODE:
          JavaExpr keyExpr = visit(accessNode.getChild(0));
          refText = genGetDataSingleCallWithKeyExpr(refText, keyExpr);
          break;
        default:
          throw new AssertionError();
      }
    }

    if (nullSafetyPrefix.length() == 0) {
      return new JavaExpr(refText, SoyData.class, Integer.MAX_VALUE);
    } else {
      return new JavaExpr(
          nullSafetyPrefix + refText, SoyData.class, Operator.CONDITIONAL.getPrecedence());
    }
  }
View Full Code Here

Examples of com.google.template.soy.javasrc.restricted.JavaExpr

  // Implementations for operators.


  @Override protected JavaExpr visitNegativeOpNode(NegativeOpNode node) {

    JavaExpr operand = visit(node.getChild(0));

    String integerComputation = genNewIntegerData(genUnaryOp("-", genIntegerValue(operand)));
    String floatComputation = genNewFloatData(genUnaryOp("-", genFloatValue(operand)));

    if (isAlwaysInteger(operand)) {
View Full Code Here

Examples of com.google.template.soy.javasrc.restricted.JavaExpr

  }


  @Override protected JavaExpr visitNotOpNode(NotOpNode node) {

    JavaExpr operand = visit(node.getChild(0));
    return convertBooleanResult(genNewBooleanData(genUnaryOp("!", genCoerceBoolean(operand))));
  }
View Full Code Here

Examples of com.google.template.soy.javasrc.restricted.JavaExpr

  }


  @Override protected JavaExpr visitDivideByOpNode(DivideByOpNode node) {

    JavaExpr operand0 = visit(node.getChild(0));
    JavaExpr operand1 = visit(node.getChild(1));

    // Note: Soy always performs floating-point division, even on two integers (like JavaScript).
    return convertFloatResult(genNewFloatData(genBinaryOp(
        "/", genNumberValue(operand0), genNumberValue(operand1))));
  }
View Full Code Here

Examples of com.google.template.soy.javasrc.restricted.JavaExpr

  }


  @Override protected JavaExpr visitModOpNode(ModOpNode node) {

    JavaExpr operand0 = visit(node.getChild(0));
    JavaExpr operand1 = visit(node.getChild(1));

    return convertIntegerResult(genNewIntegerData(genBinaryOp(
        "%", genIntegerValue(operand0), genIntegerValue(operand1))));
  }
View Full Code Here

Examples of com.google.template.soy.javasrc.restricted.JavaExpr

  }


  @Override protected JavaExpr visitPlusOpNode(PlusOpNode node) {

    JavaExpr operand0 = visit(node.getChild(0));
    JavaExpr operand1 = visit(node.getChild(1));

    String stringComputation = genNewStringData(genBinaryOp(
        "+", genCoerceString(operand0), genCoerceString(operand1)));
    String integerComputation = genNewIntegerData(genBinaryOp(
        "+", genIntegerValue(operand0), genIntegerValue(operand1)));
    String floatComputation = genNewFloatData(genBinaryOp(
        "+", genNumberValue(operand0), genNumberValue(operand1)));

    if (isAlwaysTwoIntegers(operand0, operand1)) {
      return convertIntegerResult(integerComputation);
    } else if (isAlwaysAtLeastOneString(operand0, operand1)) {
      return convertStringResult(stringComputation);
    } else if (isAlwaysTwoFloatsOrOneFloatOneInteger(operand0, operand1)) {
      return convertFloatResult(floatComputation);
    } else {
      return convertUnknownResult(genFunctionCall(
          UTILS_LIB + ".$$plus", operand0.getText(), operand1.getText()));
    }
  }
View Full Code Here

Examples of com.google.template.soy.javasrc.restricted.JavaExpr

  }


  @Override protected JavaExpr visitEqualOpNode(EqualOpNode node) {

    JavaExpr operand0 = visit(node.getChild(0));
    JavaExpr operand1 = visit(node.getChild(1));

    return convertBooleanResult(genNewBooleanData(
        genMaybeProtect(operand0, Integer.MAX_VALUE) + ".equals(" + operand1.getText() + ")"));
  }
View Full Code Here

Examples of com.google.template.soy.javasrc.restricted.JavaExpr

  }


  @Override protected JavaExpr visitNotEqualOpNode(NotEqualOpNode node) {

    JavaExpr operand0 = visit(node.getChild(0));
    JavaExpr operand1 = visit(node.getChild(1));

    return convertBooleanResult(genNewBooleanData(
        "! " + genMaybeProtect(operand0, Integer.MAX_VALUE) + ".equals(" +
        operand1.getText() + ")"));
  }
View Full Code Here

Examples of com.google.template.soy.javasrc.restricted.JavaExpr

  }


  @Override protected JavaExpr visitConditionalOpNode(ConditionalOpNode node) {

    JavaExpr operand0 = visit(node.getChild(0));
    JavaExpr operand1 = visit(node.getChild(1));
    JavaExpr operand2 = visit(node.getChild(2));

    Class<?> type1 = operand1.getType();
    Class<?> type2 = operand2.getType();
    // Set result type to nearest common ancestor of type1 and type2.
    Class<?> resultType = null;
    for (Class<?> type = type1; type != null; type = type.getSuperclass()) {
      if (type.isAssignableFrom(type2)) {
        resultType = type;
        break;
      }
    }
    if (resultType == null) {
      throw new AssertionError();
    }

    return new JavaExpr(
        genCoerceBoolean(operand0) + " ? " +
        genMaybeProtect(operand1, Operator.CONDITIONAL.getPrecedence() + 1) + " : " +
        genMaybeProtect(operand2, Operator.CONDITIONAL.getPrecedence() + 1),
        resultType, Operator.CONDITIONAL.getPrecedence());
  }
View Full Code Here

Examples of com.google.template.soy.javasrc.restricted.JavaExpr

  // -----------------------------------------------------------------------------------------------
  // Private helpers.


  private JavaExpr convertBooleanResult(String exprText) {
    return new JavaExpr(exprText, BooleanData.class, Integer.MAX_VALUE);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.