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


Java Node.addChildAfter方法代码示例

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


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

示例1: tryMergeBlock

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Merge a block with its parent block.
 * @return Whether the block was removed.
 */
static boolean tryMergeBlock(Node block) {
  Preconditions.checkState(block.getType() == Token.BLOCK);
  Node parent = block.getParent();
  // Try to remove the block if its parent is a block/script or if its
  // parent is label and it has exactly one child.
  if (NodeUtil.isStatementBlock(parent)) {
    Node previous = block;
    while (block.hasChildren()) {
      Node child = block.removeFirstChild();
      parent.addChildAfter(child, previous);
      previous = child;
    }
    parent.removeChild(block);
    return true;
  } else if (parent.getType() == Token.LABEL && block.hasOneChild()) {
    parent.replaceChild(block, block.removeFirstChild());
    return true;
  } else {
    return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:NodeUtil.java

示例2: split

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void split(Node n) {
  Node c = n.getFirstChild();
  Node before = null;
  while (c != null) {
    Node next = c.getNext();
    if (shouldSplit.apply(c)) {
      Node placeHolder = placeHolderProvider.get();
      if (before == null) {
        forest.add(n.removeFirstChild());
        n.addChildToFront(placeHolder);
      } else {
        n.addChildAfter(placeHolder, c);
        n.removeChildAfter(before);
        forest.add(c);
      }
      recordSplitPoint(placeHolder, before, c);
      before = placeHolder;
    } else {
      split(c);
      before = c;
    }
    c = next;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:AstParallelizer.java

示例3: tryRemoveRepeatedStatements

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Try to remove duplicate statements from IF blocks. For example:
 *
 * if (a) {
 *   x = 1;
 *   return true;
 * } else {
 *   x = 2;
 *   return true;
 * }
 *
 * becomes:
 *
 * if (a) {
 *   x = 1;
 * } else {
 *   x = 2;
 * }
 * return true;
 *
 * @param n The IF node to examine.
 */
private void tryRemoveRepeatedStatements(NodeTraversal t, Node n) {
  Preconditions.checkState(n.getType() == Token.IF);

  Node parent = n.getParent();
  if (!NodeUtil.isStatementBlock(parent)) {
    // If the immediate parent is something like a label, we
    // can't move the statement, so bail.
    return;
  }

  Node cond = n.getFirstChild();
  Node trueBranch = cond.getNext();
  Node falseBranch = trueBranch.getNext();
  Preconditions.checkNotNull(trueBranch);
  Preconditions.checkNotNull(falseBranch);

  while (true) {
    Node lastTrue = trueBranch.getLastChild();
    Node lastFalse = falseBranch.getLastChild();
    if (lastTrue == null || lastFalse == null
        || !compiler.areNodesEqualForInlining(lastTrue, lastFalse)) {
      break;
    }
    lastTrue.detachFromParent();
    lastFalse.detachFromParent();
    parent.addChildAfter(lastTrue, n);
    t.getCompiler().reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:52,代码来源:FoldConstants.java

示例4: exportTestFunction

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void exportTestFunction(String testFunctionName, Node node,
    Node scriptNode) {

  Node call = new Node(Token.CALL, NodeUtil.newQualifiedNameNode(
      exportSymbolFunction, node, testFunctionName));
  call.addChildToBack(Node.newString(testFunctionName));
  call.addChildToBack(NodeUtil.newQualifiedNameNode(
      testFunctionName, node, testFunctionName));

  Node expression = new Node(Token.EXPR_RESULT, call);

  scriptNode.addChildAfter(expression, node);
  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:ExportTestFunctions.java

示例5: addStubsForUndeclaredProperties

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Adds global variable "stubs" for any properties of a global name that are
 * only set in a local scope or read but never set.
 *
 * @param n An object representing a global name (e.g. "a", "a.b.c")
 * @param alias The flattened name of the object whose properties we are
 *     adding stubs for (e.g. "a$b$c")
 * @param parent The node to which new global variables should be added
 *     as children
 * @param addAfter The child of after which new
 *     variables should be added (may be null)
 * @return The number of variables added
 */
private int addStubsForUndeclaredProperties(
    Name n, String alias, Node parent, Node addAfter) {
  Preconditions.checkArgument(NodeUtil.isStatementBlock(parent));
  int numStubs = 0;
  if (n.props != null) {
    for (Name p : n.props) {
      if (p.needsToBeStubbed()) {
        String propAlias = appendPropForAlias(alias, p.name);
        Node nameNode = Node.newString(Token.NAME, propAlias);
        Node newVar = new Node(Token.VAR, nameNode);
        if (addAfter == null) {
          parent.addChildToFront(newVar);
        } else {
          parent.addChildAfter(newVar, addAfter);
          addAfter = newVar;
        }
        numStubs++;
        compiler.reportCodeChange();

        // Determine if this is a constant var by checking the first
        // reference to it. Don't check the declaration, as it might be null.
        if (p.refs.get(0).node.getLastChild().getBooleanProp(
              Node.IS_CONSTANT_NAME)) {
          nameNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
        }
      }
    }
  }
  return numStubs;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:44,代码来源:CollapseProperties.java

示例6: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.WHILE:
      if (CONVERT_WHILE_TO_FOR) {
        Node expr = n.getFirstChild();
        n.setType(Token.FOR);
        n.addChildBefore(new Node(Token.EMPTY), expr);
        n.addChildAfter(new Node(Token.EMPTY), expr);
        reportCodeChange("WHILE node");
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:Normalize.java

示例7: addToFront

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * @param after The child node to insert the newChild after, or null if
 *     newChild should be added to the front of parent's child list.
 * @return The inserted child node.
 */
private Node addToFront(Node parent, Node newChild, Node after) {
  if (after == null) {
    parent.addChildToFront(newChild);
  } else {
    parent.addChildAfter(newChild, after);
  }
  return newChild;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:Normalize.java


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