Examples of JavaExpr


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

      // Case 1: The code style is 'concat' and the whole template body can be represented as Java
      // expressions. We specially handle this case because we don't want to generate the variable
      // 'output' at all. We simply concatenate the Java expressions and return the result.

      List<JavaExpr> templateBodyJavaExprs = genJavaExprsVisitor.exec(node);
      JavaExpr templateBodyJavaExpr = JavaExprUtils.concatJavaExprs(templateBodyJavaExprs);
      javaCodeBuilder.appendLine("return ", templateBodyJavaExpr.getText(), ";");

    } else {
      // Case 2: Normal case.

      javaCodeBuilder.pushOutputVar("output");
View Full Code Here

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

  @Override protected void visitLetValueNode(LetValueNode node) {

    String generatedVarName = node.getUniqueVarName();

    // Generate code to define the local var.
    JavaExpr valueJavaExpr =
        translateToJavaExprVisitorFactory.create(localVarTranslations).exec(node.getValueExpr());
    javaCodeBuilder.appendLine(
        "final com.google.template.soy.data.SoyData ", generatedVarName, " = ",
        valueJavaExpr.getText(), ";");

    // Add a mapping for generating future references to this local var.
    localVarTranslations.peek().put(
        node.getVarName(), new JavaExpr(generatedVarName, SoyData.class, Integer.MAX_VALUE));
  }
View Full Code Here

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

          "String ", generatedVarName, " = ", generatedVarName, "_sb.toString();");
    }

    // Add a mapping for generating future references to this local var.
    localVarTranslations.peek().put(
        node.getVarName(), new JavaExpr(generatedVarName, SoyData.class, Integer.MAX_VALUE));
  }
View Full Code Here

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

    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
View Full Code Here

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

  @Override protected void visitSwitchNode(SwitchNode node) {

    TranslateToJavaExprVisitor ttjev =
        translateToJavaExprVisitorFactory.create(localVarTranslations);

    JavaExpr switchValueJavaExpr = ttjev.exec(node.getExpr());
    String switchValueVarName = "switchValue" + node.getId();
    javaCodeBuilder.appendLine(
        "com.google.template.soy.data.SoyData ", switchValueVarName, " = ",
        switchValueJavaExpr.getText(), ";");

    boolean isFirstCase = true;
    for (SoyNode child : node.getChildren()) {

      if (child instanceof SwitchCaseNode) {
        SwitchCaseNode scn = (SwitchCaseNode) child;

        StringBuilder conditionExprText = new StringBuilder();
        boolean isFirstCaseValue = true;
        for (ExprNode caseExpr : scn.getExprList()) {
          JavaExpr caseJavaExpr = ttjev.exec(caseExpr);
          if (isFirstCaseValue) {
            isFirstCaseValue = false;
          } else {
            conditionExprText.append(" || ");
          }
          conditionExprText.append(switchValueVarName).append(".equals(")
              .append(caseJavaExpr.getText()).append(')');
        }

        if (isFirstCase) {
          isFirstCase = false;
          javaCodeBuilder.appendLine("if (", conditionExprText.toString(), ") {");
View Full Code Here

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

    String nodeId = Integer.toString(node.getId());
    String listVarName = baseVarName + "List" + nodeId;
    String listLenVarName = baseVarName + "ListLen" + nodeId;

    // Define list var and list-len var.
    JavaExpr dataRefJavaExpr =
        translateToJavaExprVisitorFactory.create(localVarTranslations).exec(node.getExpr());
    javaCodeBuilder.appendLine(
        "com.google.template.soy.data.SoyListData ", listVarName,
        " = (com.google.template.soy.data.SoyListData) ", dataRefJavaExpr.getText(), ";");
    javaCodeBuilder.appendLine("int ", listLenVarName, " = ", listVarName, ".length();");

    // If has 'ifempty' node, add the wrapper 'if' statement.
    boolean hasIfemptyNode = node.numChildren() == 2;
    if (hasIfemptyNode) {
View Full Code Here

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

    // Add a new localVarTranslations frame and populate it with the translations from this node.
    Map<String, JavaExpr> newLocalVarTranslationsFrame = Maps.newHashMap();
    newLocalVarTranslationsFrame.put(
        baseVarName,
        new JavaExpr(dataVarName,
                     SoyData.class, Integer.MAX_VALUE));
    newLocalVarTranslationsFrame.put(
        baseVarName + "__isFirst",
        new JavaExpr("com.google.template.soy.data.restricted.BooleanData.forValue(" +
                     indexVarName + " == 0)",
                     BooleanData.class, Integer.MAX_VALUE));
    newLocalVarTranslationsFrame.put(
        baseVarName + "__isLast",
        new JavaExpr("com.google.template.soy.data.restricted.BooleanData.forValue(" +
                     indexVarName + " == " + listLenVarName + " - 1)",
                     BooleanData.class, Integer.MAX_VALUE));
    newLocalVarTranslationsFrame.put(
        baseVarName + "__index",
        new JavaExpr("com.google.template.soy.data.restricted.IntegerData.forValue(" +
                     indexVarName + ")",
                     IntegerData.class, Integer.MAX_VALUE));
    localVarTranslations.push(newLocalVarTranslationsFrame);

    // Generate the code for the loop body.
View Full Code Here

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

    // Add a new localVarTranslations frame and populate it with the translations from this node.
    Map<String, JavaExpr> newLocalVarTranslationsFrame = Maps.newHashMap();
    newLocalVarTranslationsFrame.put(
        varName,
        new JavaExpr("com.google.template.soy.data.restricted.IntegerData.forValue(" +
                     varName + nodeId + ")",
                     IntegerData.class, Integer.MAX_VALUE));
    localVarTranslations.push(newLocalVarTranslationsFrame);

    // Generate the code for the loop body.
View Full Code Here

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

    if (javaSrcOptions.getCodeStyle() == CodeStyle.STRINGBUILDER) {
      // For 'stringbuilder' code style, pass the current output var to collect the call's output.
      if (! (node instanceof CallBasicNode)) {
        throw new UnsupportedOperationException("Delegates are not supported in JavaSrc backend.");
      }
      JavaExpr objToPass = genCallCodeUtils.genObjToPass(node, localVarTranslations);
      javaCodeBuilder.indent()
          .append(((CallBasicNode) node).getCalleeName().replace('.', '$'))
          .append("(", objToPass.getText(), ", ").appendOutputVarName().append(");\n");

    } else {
      // For 'concat' code style, we simply add the call's result to the current output var.
      JavaExpr callExpr = genCallCodeUtils.genCallExpr(node, localVarTranslations);
      javaCodeBuilder.addToOutputVar(ImmutableList.of(callExpr));
    }
  }
View Full Code Here

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

  // -----------------------------------------------------------------------------------------------
  // Implementations for primitives.


  @Override protected JavaExpr visitNullNode(NullNode node) {
    return new JavaExpr(NULL_DATA_INSTANCE, NullData.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.