Package com.google.template.soy.soytree.SoyNode

Examples of com.google.template.soy.soytree.SoyNode.BlockNode


    if (node.getSyntaxVersion() != SoyNode.SyntaxVersion.V2) {
      return;
    }

    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()) {
      return// don't replace this node
    }

    String fnName = ((FunctionNode) expr).getFunctionName();
    String rawText;
    if (fnName.equals(BIDI_MARK_FN_NAME)) {
      rawText = (bidiGlobalDir.getStaticValue() < 0) ? "\\u200F" /*RLM*/ : "\\u200E" /*LRM*/;
    } else if (fnName.equals(BIDI_START_EDGE_FN_NAME)) {
      rawText = (bidiGlobalDir.getStaticValue() < 0) ? "right" : "left";
    } else if (fnName.equals(BIDI_END_EDGE_FN_NAME)) {
      rawText = (bidiGlobalDir.getStaticValue() < 0) ? "left" : "right";
    } else {
      return// don't replace this node
    }

    for (PrintDirectiveNode directiveNode : node.getChildren()) {
      if (! CoreDirectiveUtils.isCoreDirective(directiveNode)) {
        return// don't replace this node
      }
    }

    // Replace this node with a RawTextNode.
    parent.replaceChild(node, new RawTextNode(nodeIdGen.genId(), rawText));
    madeReplacement = true;
  }
View Full Code Here



  @Override protected void visitCssNode(CssNode node) {

    // Remove this CssNode. Save the index because we'll need it for inserting the new nodes.
    BlockNode parent = node.getParent();
    int indexInParent = parent.getChildIndex(node);
    parent.removeChild(indexInParent);

    // If this CssNode has componentName, add a PrintNode (with '|id' directive) to print it.
    ExprRootNode<?> componentNameExpr = node.getComponentNameExpr();
    if (componentNameExpr != null) {
      PrintNode pn =
          new PrintNode(nodeIdGen.genId(), false, new ExprUnion(componentNameExpr), null);
      pn.addChild(new PrintDirectiveNode(nodeIdGen.genId(), "|id", ""));
      parent.addChild(indexInParent, pn);
      indexInParent += 1;
    }

    // Add a RawTextNode for the selectorText. Also includes preceding dash ("-") if there is a
    // preceding componentName.
    String selectorText = node.getSelectorText();
    if (cssRenamingMap != null) {
      String mappedText = cssRenamingMap.get(selectorText);
      if (mappedText != null) {
        selectorText = mappedText;
      }
    }
    if (componentNameExpr != null) {
      selectorText = "-" + selectorText;
    }
    parent.addChild(indexInParent, new RawTextNode(nodeIdGen.genId(), selectorText));
  }
View Full Code Here

    if (node.getSyntaxVersion() != SyntaxVersion.V2) {
      return;
    }

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

    if (! isConstant(node.getExprUnion().getExpr())) {
      return// don't prerender
    }

    for (PrintDirectiveNode directive : node.getChildren()) {
      for (ExprRootNode<?> arg : directive.getArgs()) {
        if (! isConstant(arg)) {
          return// don't prerender
        }
      }
    }

    StringBuilder prerenderOutputSb = new StringBuilder();
    try {
      prerenderVisitorFactory.create(prerenderOutputSb, templateRegistry, new SoyMapData(), null)
          .exec(node);
    } catch (RenderException pe) {
      return// cannot prerender for some other reason not checked above
    }

    // Replace this node with a RawTextNode.
    parent.replaceChild(node, new RawTextNode(nodeIdGen.genId(), prerenderOutputSb.toString()));
  }
View Full Code Here

    }

    if (! (node instanceof BlockNode)) {
      return;
    }
    BlockNode nodeAsBlock = (BlockNode) node;

    // Check whether there are any consecutive RawTextNode children.
    boolean hasConsecRawTextNodes = false;
    for (int i = 0; i <= nodeAsBlock.numChildren() - 2; i++) {
      if (nodeAsBlock.getChild(i) instanceof RawTextNode &&
          nodeAsBlock.getChild(i + 1) instanceof RawTextNode) {
        hasConsecRawTextNodes = true;
        break;
      }
    }
    // If there aren't any consecutive RawTextNode children, we're done.
    if (! hasConsecRawTextNodes) {
      return;
    }

    // Rebuild the list of children, combining consecutive RawTextNodes into one.
    List<StandaloneNode> copyOfOrigChildren = Lists.newArrayList(nodeAsBlock.getChildren());
    nodeAsBlock.clearChildren();

    List<RawTextNode> consecutiveRawTextNodes = Lists.newArrayList();
    for (StandaloneNode origChild : copyOfOrigChildren) {

      if (origChild instanceof RawTextNode) {
        consecutiveRawTextNodes.add((RawTextNode) origChild);

      } else {
        // First add the preceding consecutive RawTextNodes, if any.
        addConsecutiveRawTextNodesAsOneNodeHelper(nodeAsBlock, consecutiveRawTextNodes);
        consecutiveRawTextNodes.clear();
        // Then add the current new child.
        nodeAsBlock.addChild(origChild);
      }
    }

    // Add the final group of consecutive RawTextNodes, if any.
    addConsecutiveRawTextNodesAsOneNodeHelper(nodeAsBlock, consecutiveRawTextNodes);
View Full Code Here

   * @param replacementNodes The list of nodes to put in place of the original node.
   */
  private static void replaceNodeWithList(
      StandaloneNode origNode, List<? extends StandaloneNode> replacementNodes) {

    BlockNode parent = origNode.getParent();
    int indexInParent = parent.getChildIndex(origNode);
    parent.removeChild(indexInParent);
    parent.addChildren(indexInParent, replacementNodes);
  }
View Full Code Here

    }

    if (! (node instanceof BlockNode)) {
      return;
    }
    BlockNode nodeAsBlock = (BlockNode) node;

    // Check whether there are any consecutive RawTextNode children.
    boolean hasConsecRawTextNodes = false;
    for (int i = 0; i <= nodeAsBlock.numChildren() - 2; i++) {
      if (nodeAsBlock.getChild(i) instanceof RawTextNode &&
          nodeAsBlock.getChild(i+1) instanceof RawTextNode) {
        hasConsecRawTextNodes = true;
        break;
      }
    }
    // If there aren't any consecutive RawTextNode children, we're done.
    if (!hasConsecRawTextNodes) {
      return;
    }

    // Rebuild the list of children, combining consecutive RawTextNodes into one.
    List<StandaloneNode> copyOfOrigChildren = Lists.newArrayList(nodeAsBlock.getChildren());
    nodeAsBlock.clearChildren();

    List<RawTextNode> consecutiveRawTextNodes = Lists.newArrayList();
    for (StandaloneNode origChild : copyOfOrigChildren) {

      if (origChild instanceof RawTextNode) {
        consecutiveRawTextNodes.add((RawTextNode) origChild);

      } else {
        // First add the preceding consecutive RawTextNodes, if any.
        addConsecutiveRawTextNodesAsOneNodeHelper(nodeAsBlock, consecutiveRawTextNodes);
        consecutiveRawTextNodes.clear();
        // Then add the current new child.
        nodeAsBlock.addChild(origChild);
      }
    }

    // Add the final group of consecutive RawTextNodes, if any.
    addConsecutiveRawTextNodesAsOneNodeHelper(nodeAsBlock, consecutiveRawTextNodes);
View Full Code Here


  @SuppressWarnings("unchecked"// casts with generics
  private void moveGoogMsgNodeEarlierHelper(GoogMsgNode googMsgNode, List<SoyNode> allDependees) {

    BlockNode newParent;
    int indexUnderNewParent;

    SoyNode nearestDependee = allDependees.get(0);
    if (nearestDependee instanceof LocalVarInlineNode) {
      newParent = (BlockNode) nearestDependee.getParent();
      indexUnderNewParent = newParent.getChildIndex((LocalVarInlineNode) nearestDependee) + 1;
    } else if (nearestDependee instanceof BlockNode) {
      newParent = (BlockNode) nearestDependee;
      indexUnderNewParent = 0;
    } else {
      throw new AssertionError();
    }

    // Advance the index under the new parent past any GoogMsgNodes already at that location. Also,
    // if we end up finding the exact GoogMsgNode that we're currently trying to move, then we're
    // done because it's already at the location we want to move it to.
    List<StandaloneNode> siblings = newParent.getChildren();
    while (indexUnderNewParent < siblings.size() &&
           siblings.get(indexUnderNewParent) instanceof GoogMsgNode) {
      if (googMsgNode == siblings.get(indexUnderNewParent)) {
        // Same exact node, so we're done.
        return;
      }
      indexUnderNewParent++;
    }

    // Move the node.
    googMsgNode.getParent().removeChild(googMsgNode);
    newParent.addChild(indexUnderNewParent, googMsgNode);
  }
View Full Code Here

    if (node.getSyntaxVersion() != SoyNode.SyntaxVersion.V2) {
      return;
    }

    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()) {
      return// don't replace this node
    }

    String fnName = ((FunctionNode) expr).getFunctionName();
    String rawText;
    if (fnName.equals(BIDI_MARK_FN_NAME)) {
      rawText = (bidiGlobalDir.getStaticValue() < 0) ? "\\u200F" /*RLM*/ : "\\u200E" /*LRM*/;
    } else if (fnName.equals(BIDI_START_EDGE_FN_NAME)) {
      rawText = (bidiGlobalDir.getStaticValue() < 0) ? "right" : "left";
    } else if (fnName.equals(BIDI_END_EDGE_FN_NAME)) {
      rawText = (bidiGlobalDir.getStaticValue() < 0) ? "left" : "right";
    } else {
      return// don't replace this node
    }

    for (PrintDirectiveNode directiveNode : node.getChildren()) {
      if (! CoreDirectiveUtils.isCoreDirective(directiveNode)) {
        return// don't replace this node
      }
    }

    // Replace this node with a RawTextNode.
    parent.replaceChild(node, new RawTextNode(nodeIdGen.genId(), rawText));
    madeReplacement = true;
  }
View Full Code Here

    GoogMsgNode googMsgNode = new GoogMsgNode(googMsgNodeId, msgNode, googMsgVarName);
    GoogMsgRefNode googMsgRefNode =
        new GoogMsgRefNode(nodeIdGen.genId(), googMsgNode.getRenderedGoogMsgVarName());

    BlockNode parent = msgNode.getParent();
    int msgNodeIndex = parent.getChildIndex(msgNode);
    parent.replaceChild(msgNodeIndex, googMsgNode);
    parent.addChild(msgNodeIndex + 1, googMsgRefNode);
  }
View Full Code Here

        }
      }
    }

    // Replace this MsgNode with the replacement nodes.
    BlockNode parent = node.getParent();
    int indexInParent = parent.getChildIndex(node);
    parent.removeChild(indexInParent);
    parent.addChildren(indexInParent, currMsgReplacementNodes);
    currMsgReplacementNodes = null;
  }
View Full Code Here

TOP

Related Classes of com.google.template.soy.soytree.SoyNode.BlockNode

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.