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


Java Node.cloneNode方法代码示例

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


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

示例1: keepSimplifiedShortCircuitExpression

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void keepSimplifiedShortCircuitExpression(Node original) {
  Preconditions.checkArgument(
      (original.getType() == Token.AND) || (original.getType() == Token.OR),
      "Expected: AND or OR, Got: " + Token.name(original.getType()));
  Node left = original.getFirstChild();
  Node right = left.getNext();
  Node simplifiedRight = simplifyShortCircuitBranch(right);

  Node simplified = original.cloneNode();
  simplified.addChildToBack(left.cloneTree());
  simplified.addChildToBack(simplifiedRight);
  replacements.add(simplified);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:GatherSideEffectSubexpressionsCallback.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: 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


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