当前位置: 首页>>代码示例>>Java>>正文


Java Node.addChildrenToBack方法代码示例

本文整理汇总了Java中com.google.javascript.rhino.Node.addChildrenToBack方法的典型用法代码示例。如果您正苦于以下问题:Java Node.addChildrenToBack方法的具体用法?Java Node.addChildrenToBack怎么用?Java Node.addChildrenToBack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.rhino.Node的用法示例。


在下文中一共展示了Node.addChildrenToBack方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newVarNode

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Create a VAR node containing the given name and initial value expression.
 */
static Node newVarNode(String name, Node value) {
  Node nodeName = Node.newString(Token.NAME, name);
  if (value != null) {
    nodeName.addChildrenToBack(value);
  }
  Node var = new Node(Token.VAR, nodeName);

  return var;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:NodeUtil.java

示例2: extractExpression

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * @param expr The expression to extract.
 * @param injectionPoint The node before which to added the extracted
 *     expression.
 * @return The extract statement node.
 */
private Node extractExpression(Node expr, Node injectionPoint) {
  Node parent = expr.getParent();
  // The temp value is known to be constant.
  String tempName = getTempConstantValueName();

  // Replace the expression with the temporary name.
  Node replacementValueNode = Node.newString(Token.NAME, tempName);
  parent.replaceChild(expr, replacementValueNode);

  // Re-add the expression in the declaration of the temporary name.
  Node tempNameNode = Node.newString(Token.NAME, tempName);
  tempNameNode.addChildrenToBack(expr);
  Node tempVarNode = new Node(Token.VAR, tempNameNode);

  Node injectionPointParent = injectionPoint.getParent();
  injectionPointParent.addChildBefore(tempVarNode, injectionPoint);

  // If it is ASSIGN_XXX we need to assign it back to the original value.
  // Note that calling the temp constant is a lie in this case, but we do know
  // that it is not modified until after the exposed expression.
  if (NodeUtil.isAssignmentOp(parent) && !NodeUtil.isAssign(parent)) {
    Node gParent = parent.getParent();
    Node assignBack = new Node(Token.ASSIGN,
        expr.cloneTree(),
        tempNameNode.cloneNode());
    if (NodeUtil.isExpressionNode(gParent)) {
      gParent.getParent().addChildAfter(
          NodeUtil.newExpr(assignBack), gParent);
    } else {
      // TODO(user): Use comma here sucks. We might close some accuracy
      // in flow sensitive passes but as far as I know it is unavoidable.
      Node comma = new Node(Token.COMMA);
      gParent.replaceChild(parent, comma);
      comma.addChildrenToFront(assignBack);
      comma.addChildrenToFront(parent);
    }
  }
  return tempVarNode;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:46,代码来源:ExpressionDecomposer.java

示例3: addDummyAssignment

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Example:
 *   a = (void) 0;
 */
private static void addDummyAssignment(Node node, String resultName) {
  Preconditions.checkArgument(node.getType() == Token.BLOCK);

  // A result is needed create a dummy value.
  Node retVal = NodeUtil.newUndefinedNode();
  Node resultNode = createAssignStatementNode(resultName, retVal);

  node.addChildrenToBack(resultNode);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:FunctionToBlockMutator.java

示例4: applyCollapses

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void applyCollapses() {
  for (Collapse collapse : collapses) {
    Node first = collapse.firstVarNode;
    while (first.getNext() != null &&
        first.getNext().getType() == Token.VAR) {
      Node next = collapse.parent.removeChildAfter(first);

      // Move all children of the next var node into the first one.
      first.addChildrenToBack(next.removeChildren());
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:CollapseVariableDeclarations.java

示例5: createPostOrderAlphabet

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** 
 * Returns a Node tree with the post-order traversal a b c d e f g h i j k l m
 * and the in-order traversal m d a b c h e f g l i j k:
 * 
 *                                   m
 *                         ,---------|---------.
 *                         d         h         l
 *                      ,--|--.   ,--|--.   ,--|--.
 *                      a  b  c   e  f  g   i  j  k
 * 
 */
private static Node createPostOrderAlphabet() {
  Node a = Node.newString("a");
  Node b = Node.newString("b");
  Node c = Node.newString("c");
  Node d = Node.newString("d");
  Node e = Node.newString("e");
  Node f = Node.newString("f");
  Node g = Node.newString("g");
  Node h = Node.newString("h");
  Node i = Node.newString("i");
  Node j = Node.newString("j");
  Node k = Node.newString("k");
  Node l = Node.newString("l");
  Node m = Node.newString("m");
  
  d.addChildToBack(a);
  d.addChildToBack(b);
  d.addChildToBack(c);
  
  h.addChildrenToBack(e);
  h.addChildrenToBack(f);
  h.addChildrenToBack(g);
  
  l.addChildToBack(i);
  l.addChildToBack(j);
  l.addChildToBack(k);
  
  m.addChildToBack(d);
  m.addChildToBack(h);
  m.addChildToBack(l);
  
  return m;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:45,代码来源:CombinedCompilerPassTest.java

示例6: rewriteCallExpression

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Rewrite the call so "this" is preserved.
 *   a.b(c);
 * becomes:
 *   var temp1 = a;
 *   var temp0 = temp1.b;
 *   temp0.call(temp1,c);
 *
 * @return The replacement node.
 */
private Node rewriteCallExpression(Node call, DecompositionState state) {
  Preconditions.checkArgument(call.getType() == Token.CALL);
  Node first = call.getFirstChild();
  Preconditions.checkArgument(NodeUtil.isGet(first));

  // Extracts the expression representing the function to call. For example:
  //   "a['b'].c" from "a['b'].c()"
  Node getVarNode = extractExpression(
      first, state.extractBeforeStatement);
  state.extractBeforeStatement = getVarNode;

  // Extracts the object reference to be used as "this". For example:
  //   "a['b']" from "a['b'].c"
  Node getExprNode = getVarNode.getFirstChild().getFirstChild();
  Preconditions.checkArgument(NodeUtil.isGet(getExprNode));
  Node thisVarNode = extractExpression(
      getExprNode.getFirstChild(), state.extractBeforeStatement);
  state.extractBeforeStatement = thisVarNode;

  // Rewrite the CALL expression.
  Node thisNameNode = thisVarNode.getFirstChild();
  Node functionNameNode = getVarNode.getFirstChild();

  // CALL
  //   GETPROP
  //     functionName
  //     "call"
  //   thisName
  //   original-parameter1
  //   original-parameter2
  //   ...
  Node newCall = new Node(Token.CALL,
      new Node(Token.GETPROP,
          functionNameNode.cloneNode(),
          Node.newString("call")),
      thisNameNode.cloneNode(), call.getLineno(), call.getCharno());

  // Throw away the call name
  call.removeFirstChild();
  if (call.hasChildren()) {
    // Add the call parameters to the new call.
    newCall.addChildrenToBack(call.removeChildren());
  }

  // Replace the call.
  Node callParent = call.getParent();
  callParent.replaceChild(call, newCall);

  return newCall;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:61,代码来源:ExpressionDecomposer.java

示例7: replaceReturns

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 *  Convert returns to assignments and breaks, as needed.
 *  For example, with a lableName of 'foo':
 *    {
 *      return a;
 *    }
 *  becomes:
 *    foo: {
 *      a;
 *      break foo;
 *    }
 *  or
 *    foo: {
 *      resultName = a;
 *      break foo;
 *    }
 *
 * @param resultMustBeSet Whether the result must always be set to a value.
 * @return The node containing the transformed block, this may be different
 *     than the passed in node 'block'.
 */
private static Node replaceReturns(
    Node block, String resultName, String labelName,
    boolean resultMustBeSet) {
  Preconditions.checkNotNull(block);
  Preconditions.checkNotNull(labelName);

  Node root = block;

  boolean hasReturnAtExit = false;
  int returnCount = NodeUtil.getNodeTypeReferenceCount(block, Token.RETURN);
  if (returnCount > 0) {
    hasReturnAtExit = hasReturnAtExit(block);
    // TODO(johnlenz): Simpler not to special case this,
    // and let it be optimized later.
    if (hasReturnAtExit) {
      convertLastReturnToStatement(block, resultName);
      returnCount--;
    }

    if (returnCount > 0) {
      // A label and breaks are needed.

      // Add the breaks
      replaceReturnWithBreak(block, null, resultName, labelName);

      // Add label
      Node label = new Node(Token.LABEL);
      Node name = Node.newString(Token.NAME, labelName);
      label.addChildToFront(name);
      label.addChildToBack(block);

      Node newRoot = new Node(Token.BLOCK);
      newRoot.addChildrenToBack(label);

      // The label is now the root.
      root = newRoot;
    }
  }

  // If there wasn't an return at the end of the function block, and we need
  // a result, add one to the block.
  if (resultMustBeSet && !hasReturnAtExit && resultName != null) {
    addDummyAssignment(block, resultName);
  }

  return root;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:69,代码来源:FunctionToBlockMutator.java


注:本文中的com.google.javascript.rhino.Node.addChildrenToBack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。