Package com.google.template.soy.exprtree

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


      }
    }

    // ------ 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();
      }
View Full Code Here


    }

    // Case 2: There are more keys.
    SoyData value = value0;
    for (ExprNode child : node.getChildren()) {
      DataRefAccessNode accessNode = (DataRefAccessNode) child;

      // We expect 'value' to be a CollectionData during every iteration.
      if (! (value instanceof CollectionData)) {
        if (accessNode.isNullSafe()) {
          if (value == null || value instanceof UndefinedData || value instanceof NullData) {
            return NullData.INSTANCE;
          } else {
            throw new RenderException(
                "While evaluating \"" + node.toSourceString() + "\", encountered non-collection" +
                " just before accessing \"" + accessNode.toSourceString() + "\".");
          }
        } else {
          // This behavior is not ideal, but needed for compatibility with existing code.
          return UndefinedData.INSTANCE;
          // TODO: If feasible, find and fix existing instances, then enable this exception.
          //if (value == null || value instanceof UndefinedData) {
          //  throw new RenderException(
          //      "While evaluating \"" + node.toSourceString() + "\", encountered undefined LHS" +
          //      " just before accessing \"" + accessNode.toSourceString() + "\".");
          //}
          //value = UndefinedData.INSTANCE;
          //continue;
        }
      }

      // Extract either a string key or integer index from the child access node.
      String key = null;
      int index = -1;
      switch (accessNode.getKind()) {
        case DATA_REF_ACCESS_KEY_NODE:
          key = ((DataRefAccessKeyNode) accessNode).getKey();
          break;
        case DATA_REF_ACCESS_INDEX_NODE:
          index = ((DataRefAccessIndexNode) accessNode).getIndex();
          break;
        case DATA_REF_ACCESS_EXPR_NODE:
          SoyData keyData = visit(accessNode.getChild(0));
          if (keyData instanceof IntegerData) {
            index = ((IntegerData) keyData).getValue();
          } else {
            key = keyData.toString();
          }
          break;
        default:
          throw new AssertionError();
      }

      // Get the data at the extracted key or index.
      if (key != null) {
        value = ((CollectionData) value).getSingle(key);
      } else {
        if (! (value instanceof SoyListData)) {
          throw new RenderException(
              "While evaluating \"" + node.toSourceString() + "\", encountered non-list" +
              " just before accessing \"" + accessNode.toSourceString() + "\".");
        }
        value = ((SoyListData) value).get(index);
      }
    }
View Full Code Here

      }
    }

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

      if (accessNode.isNullSafe()) {
        // Note: In JavaScript, "x == null" is equivalent to "x === undefined || x === null".
        nullSafetyPrefix += "(" + refText + " == null) ? null : ";
      }

      switch (accessNode.getKind()) {
        case DATA_REF_ACCESS_KEY_NODE:
          refText += genCodeForKeyAccess(((DataRefAccessKeyNode) accessNode).getKey());
          break;
        case DATA_REF_ACCESS_INDEX_NODE:
          refText += "[" + ((DataRefAccessIndexNode) accessNode).getIndex() + "]";
          break;
        case DATA_REF_ACCESS_EXPR_NODE:
          JsExpr keyJsExpr = visit(accessNode.getChild(0));
          refText += "[" + keyJsExpr.getText() + "]";
          break;
        default:
          throw new AssertionError();
      }
View Full Code Here

TOP

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

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.