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


Java Node.addChildToFront方法代码示例

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


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

示例1: testParse

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testParse() {
  Node a = Node.newString(Token.NAME, "a");
  a.addChildToFront(Node.newString(Token.NAME, "b"));
  List<ParserResult> testCases = ImmutableList.of(
      new ParserResult(
          "3;",
          createScript(new Node(Token.EXPR_RESULT, Node.newNumber(3.0)))),
      new ParserResult(
          "var a = b;",
           createScript(new Node(Token.VAR, a))),
      new ParserResult(
          "\"hell\\\no\\ world\\\n\\\n!\"",
           createScript(new Node(Token.EXPR_RESULT,
           Node.newString(Token.STRING, "hello world!")))));

  for (ParserResult testCase : testCases) {
    assertNodeEquality(testCase.node, parse(testCase.code));
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:ParserTest.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: addAccessorPropName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Adds a string that can be used to reference properties by array []
 * notation.
 *
 * PROP_prototype = 'prototype';
 *
 * @param propName Name of property
 * @param root Root of output tree that function can be added to
 */
private void addAccessorPropName(String propName, Node root) {
  /*
   *  Target:

    var 1
      name PROP_length
          string length
   */
  Node propValue = Node.newString(Token.STRING, propName);
  Node propNameNode =
    Node.newString(Token.NAME, getArrayNotationNameFor(propName));
  propNameNode.addChildToFront(propValue);
  Node var = new Node(Token.VAR, propNameNode);
  root.addChildToFront(var);

  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:AliasExternals.java

示例4: addGlobalAliasNode

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Adds an alias variable for the global:
 *
 * var GLOBAL_window = window;
 *
 * @param globalName Name of global
 * @param root Root of output tree that function can be added to
 */
private void addGlobalAliasNode(String globalName, Node root) {
  /*
   *  Target:

    var 1
      name GLOBAL_window
          name window
   */
  Node globalValue = Node.newString(Token.NAME, globalName);
  Node globalNameNode =
    Node.newString(Token.NAME, "GLOBAL_" + globalName);
  globalNameNode.addChildToFront(globalValue);
  Node var = new Node(Token.VAR, globalNameNode);
  root.addChildToFront(var);

  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:AliasExternals.java

示例5: rewriteCallSites

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Rewrites object method call sites as calls to global functions
 * that take "this" as their first argument.
 *
 * Before:
 *   o.foo(a, b, c)
 *
 * After:
 *   foo(o, a, b, c)
 */
private void rewriteCallSites(SimpleDefinitionFinder defFinder,
                              Definition definition,
                              String newMethodName) {
  Collection<UseSite> useSites = defFinder.getUseSites(definition);
  for (UseSite site : useSites) {
    Node node = site.node;
    Node parent = node.getParent();

    Node objectNode = node.getFirstChild();
    node.removeChild(objectNode);
    parent.replaceChild(node, objectNode);
    parent.addChildToFront(Node.newString(Token.NAME, newMethodName));
    compiler.reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:DevirtualizePrototypeMethods.java

示例6: rewriteDefinition

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Rewrites method definitions as global functions that take "this"
 * as their first argument.
 *
 * Before:
 *   a.prototype.b = function(a, b, c) {...}
 *
 * After:
 *   var b = function(self, a, b, c) {...}
 */
private void rewriteDefinition(Node node, String newMethodName) {
  Node parent = node.getParent();
  Node functionNode = parent.getLastChild();
  Node expr = parent.getParent();
  Node block = expr.getParent();

  Node newNameNode = Node.newString(Token.NAME, newMethodName);
  parent.removeChild(functionNode);
  newNameNode.addChildToFront(functionNode);
  block.replaceChild(expr, new Node(Token.VAR, newNameNode));

  // add extra argument
  String self = newMethodName + "$self";
  Node argList = functionNode.getFirstChild().getNext();
  argList.addChildToFront(Node.newString(Token.NAME, self));

  // rewrite body
  Node body = functionNode.getLastChild();
  replaceReferencesToThis(body, self);

  // fix type
  fixFunctionType(functionNode);

  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:36,代码来源:DevirtualizePrototypeMethods.java

示例7: moveAllFollowing

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Move all the child nodes following start in srcParent to the end of
 * destParent's child list.
 * @param start The start point in the srcParent child list.
 * @param srcParent The parent node of start.
 * @param destParent The destination node.
 */
static private void moveAllFollowing(
    Node start, Node srcParent, Node destParent) {
  for (Node n = start.getNext(); n != null; n = start.getNext()) {
    boolean isFunctionDeclaration =
        NodeUtil.isFunctionDeclaration(n);

    srcParent.removeChild(n);

    if (isFunctionDeclaration) {
      destParent.addChildToFront(n);
    } else {
      destParent.addChildToBack(n);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:MinimizeExitPoints.java

示例8: normalizeLabels

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Limit the number of special cases where LABELs need to be handled. Only
 * BLOCK and loops are allowed to be labeled.  Loop labels must remain in
 * place as the named continues are not allowed for labeled blocks.
 */
private void normalizeLabels(Node n) {
  Preconditions.checkArgument(n.getType() == Token.LABEL);

  Node last = n.getLastChild();
  switch (last.getType()) {
    case Token.LABEL:
    case Token.BLOCK:
    case Token.FOR:
    case Token.WHILE:
    case Token.DO:
      return;
    default:
      Node block = new Node(Token.BLOCK);
      n.replaceChild(last, block);
      block.addChildToFront(last);
      reportCodeChange("LABEL normalization");
      return;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:Normalize.java

示例9: redeclareVarsInsideBranch

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Given a node tree, finds all the VAR declarations in that tree that are
 * not in an inner scope. Then adds a new VAR node at the top of the current
 * scope that redeclares them, if necessary.
 */
static void redeclareVarsInsideBranch(Node branch) {
  Collection<Node> vars = getVarsDeclaredInBranch(branch);
  if (vars.isEmpty()) {
    return;
  }

  Node parent = getAddingRoot(branch);
  for (Node nameNode : vars) {
    Node var = new Node(
        Token.VAR, Node.newString(Token.NAME, nameNode.getString()));
    copyNameAnnotations(nameNode, var.getFirstChild());
    parent.addChildToFront(var);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:NodeUtil.java

示例10: insertAliasDeclaration

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
/**
 * Adds alias function to codeRoot. See {@link #createAliasFunctionNode}).
 */
protected void insertAliasDeclaration(Node codeRoot) {
  codeRoot.addChildToFront(createAliasFunctionNode(getAliasName()));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:8,代码来源:AliasKeywords.java

示例11: process

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void process(Node externs, Node root) {
  NodeTraversal.traverse(compiler, root, this);
  for (Entry<JSModule, List<Node>> entry : functions.entrySet()) {
    JSModule module = entry.getKey();
    Node addingRoot = compiler.getNodeForCodeInsertion(module);
    for (Node n : Iterables.reverse(entry.getValue())) {
      addingRoot.addChildToFront(n);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:12,代码来源:MoveFunctionDeclarations.java

示例12: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.getType() != Token.RETURN) {
    return;
  }

  Node call = newReportFunctionExitNode();
  Node returnRhs = n.removeFirstChild();
  if (returnRhs != null) {
    call.addChildToBack(returnRhs);
  }
  n.addChildToFront(call);
  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:InstrumentFunctions.java

示例13: 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

示例14: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void visit(NodeTraversal t, Node node, Node parent) {
  Scope scope = t.getScope();
  if (node.getType() == Token.VAR) {
    compiler.reportCodeChange();

    if (targetError == null) {
      // the "correct" implementation
      parent.removeChild(node);
      for (Node child = node.getFirstChild();
           child != null; child = child.getNext()) {
        scope.undeclare(scope.getVar(child.getString()));
      }
    } else if (targetError == VARIABLE_COUNT_MISMATCH) {
      // A bad implementation where we forget to undeclare all vars.
      parent.removeChild(node);
      scope.undeclare(scope.getVar(node.getFirstChild().getString()));
    } else if (targetError == MISSING_VARIABLE) {
      // A bad implementation where we don't update the var name.
      node.getFirstChild().setString("z");
    } else if (targetError == MOVED_VARIABLE) {
      // A bad implementation where we take the var out of the tree.
      Node oldName = node.getFirstChild();
      oldName.detachFromParent();
      node.addChildToFront(Node.newString(Token.NAME, "x"));
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:SymbolTableTest.java

示例15: 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.addChildToFront方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。