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


Java Node.getNext方法代码示例

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


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

示例1: getCallThisObject

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Analyze a call site and extract the node that will be act as
 * "this" inside the call, which is either the object part of the
 * qualified function name, the first argument to the call in the
 * case of ".call" and ".apply" or null if object is not specified
 * in either of those ways.
 *
 * @return node that will act as "this" for the call.
 */
private static Node getCallThisObject(Node callSite) {
  Node foo = callSite.getFirstChild();
  if (!NodeUtil.isGetProp(foo)) {

    // "this" is not specified explicitly; call modifies global "this".
    return null;
  }

  Node object = null;

  String propString = foo.getLastChild().getString();
  if (propString.equals("call") || propString.equals("apply")) {
    return foo.getNext();
  } else {
    return foo.getFirstChild();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:PureFunctionIdentifier.java

示例2: testCallLocation

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testCallLocation() {
  Node root = newParse(
      "\na.\n" +
      "b.\n" +
      "cccc(1);\n");

  Node exprStmt = root.getFirstChild();
  Node functionCall = exprStmt.getFirstChild();
  Node functionProp = functionCall.getFirstChild();
  Node firstNameComponent = functionProp.getFirstChild();
  Node lastNameComponent = firstNameComponent.getNext();

  assertNodePosition(3, 4, functionCall);
  // TODO(user) New Rhino doesn't keep the position of the dot handy.
  // New Rhino treats the location of the qualified name as the beginning of
  // the whole name.
  // assertNodePosition(1, 0, firstNameComponent);
  assertNodePosition(3, 0, lastNameComponent);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:IRFactoryTest.java

示例3: traverseAtScope

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Traverses a parse tree recursively with a scope, starting at that scope's
 * root.
 */
void traverseAtScope(Scope s) {
  Node n = s.getRootNode();
  if (n.getType() == Token.FUNCTION) {
    // We need to do some extra magic to make sure that the scope doesn't
    // get re-created when we dive into the function.
    sourceName = getSourceName(n);
    curNode = n;
    pushScope(s);

    Node args = n.getFirstChild().getNext();
    Node body = args.getNext();
    traverseBranch(args, n);
    traverseBranch(body, n);

    popScope();
  } else {
    traverseWithScope(n, s);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:NodeTraversal.java

示例4: testIfLocation

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testIfLocation() {
  Node root = newParse(
      "\nif\n" +
      "  (a == 3)\n" +
      "{\n" +
      "  b = 0;\n" +
      "}\n" +
      "  else\n" +
      "{\n" +
      "  c = 1;\n" +
      "}\n");

  Node ifStmt = root.getFirstChild();
  Node eqClause = ifStmt.getFirstChild();
  Node thenClause = eqClause.getNext();
  Node elseClause = thenClause.getNext();

  assertNodePosition(1, 0, ifStmt);
  assertNodePosition(2, 5, eqClause);
  assertNodePosition(3, 0, thenClause);
  assertNodePosition(7, 0, elseClause);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:IRFactoryTest.java

示例5: testLinenoFor

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testLinenoFor() {
  Node root = newParse(
      "\nfor(\n" +
      ";\n" +
      ";\n" +
      ") {\n" +
      "}\n");

  Node forNode = root.getFirstChild();
  Node initClause= forNode.getFirstChild();
  Node condClause = initClause.getNext();
  Node incrClause = condClause.getNext();

  assertNodePosition(1, 0, forNode);
  assertNodePosition(2, 0, initClause);
  assertNodePosition(3, 0, condClause);
  // TODO(user) Incorrectly gets charno position when EmptyExpression
  // has its absolute position on the carriage return.  For now, the
  // line number gets reported correctly (on the next line) but the
  // character position is -1, so the overall line/char pair in our tree
  // is -1.
  //assertNodePosition(4, 0, incrClause);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:IRFactoryTest.java

示例6: isPropertyTree

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Returns true if the provided node is a getprop for
 * which the left child is this or a valid property tree
 * and for which the right side is a string.
 */
private static boolean isPropertyTree(Node expectedGetprop) {
  if (expectedGetprop.getType() != Token.GETPROP) {
    return false;
  }

  Node leftChild = expectedGetprop.getFirstChild();
  if (leftChild.getType() != Token.THIS &&
      !isPropertyTree(leftChild)) {
    return false;
  }

  Node retVal = leftChild.getNext();
  if (NodeUtil.getStringValue(retVal) == null) {
    return false;
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:InlineGetters.java

示例7: testMultilineEqLocation

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testMultilineEqLocation() {
  Node  root = newParse(
      "\nif\n" +
      "    (((a == \n" +
      "  3) && \n" +
      "  (b == 2)) || \n" +
      " (c == 1)) {\n" +
      "}\n");
  Node ifStmt = root.getFirstChild();
  Node orTest = ifStmt.getFirstChild();
  Node andTest = orTest.getFirstChild();
  Node cTest = andTest.getNext();
  Node aTest = andTest.getFirstChild();
  Node bTest = aTest.getNext();

  assertNodePosition(1, 0, ifStmt);
  assertNodePosition(4, 12, orTest);
  assertNodePosition(3, 5, andTest);
  assertNodePosition(2, 9, aTest);
  assertNodePosition(4, 5, bTest);
  assertNodePosition(5, 4, cTest);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:IRFactoryTest.java

示例8: processProvideCall

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Handles a goog.provide call.
 */
private void processProvideCall(NodeTraversal t, Node n, Node parent) {
  Node left = n.getFirstChild();
  Node arg = left.getNext();
  if (verifyProvide(t, left, arg)) {
    String ns = arg.getString();
    if (providedNames.containsKey(ns)) {
      ProvidedName previouslyProvided = providedNames.get(ns);
      if (!previouslyProvided.isExplicitlyProvided()) {
        previouslyProvided.addProvide(parent, t.getModule(), true);
      } else {
        compiler.report(
            JSError.make(t, n, DUPLICATE_NAMESPACE_ERROR, ns));
      }
    } else {
      registerAnyProvidedPrefixes(ns, parent, t.getModule());
      providedNames.put(
          ns, new ProvidedName(ns, parent, t.getModule(), true));
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:ProcessClosurePrimitives.java

示例9: processShortCircuitExpression

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Processes an AND or OR expression.
 *
 * @return true to continue traversal, false otherwise
 */
boolean processShortCircuitExpression(Node node) {
  Preconditions.checkArgument(
      (node.getType() == Token.AND) || (node.getType() == Token.OR),
      "Expected: AND or OR, Got: " + Token.name(node.getType()));

  // keep whole expression if rhs of the branching expression
  // contains a call.
  Node left = node.getFirstChild();
  Node right = left.getNext();
  if (NodeUtil.mayHaveSideEffects(right)) {
    accumulator.keepSimplifiedShortCircuitExpression(node);
    return false;
  } else {
    return true;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:GatherSideEffectSubexpressionsCallback.java

示例10: visit

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

  Node objectName = n.getFirstChild();

  if (!ObjectPropertyStringPreprocess.EXTERN_OBJECT_PROPERTY_STRING.equals(
          objectName.getQualifiedName())) {
    return;
  }

  Node firstArgument = objectName.getNext();
  Node secondArgument = firstArgument.getNext();
  int secondArgumentType = secondArgument.getType();
  if (secondArgumentType == Token.GETPROP) {
    // Rewrite "new goog.testing.ObjectPropertyString(window, foo.bar)"
    // as "new goog.testing.ObjectPropertyString(foo, 'bar')".
    Node newChild = secondArgument.getFirstChild();
    secondArgument.removeChild(newChild);
    n.replaceChild(firstArgument, newChild);
    n.replaceChild(secondArgument,
        Node.newString(secondArgument.getFirstChild().getString()));
  } else if (secondArgumentType == Token.GETELEM) {
    // Rewrite "new goog.testing.ObjectPropertyString(window, foo[bar])"
    // as "new goog.testing.ObjectPropertyString(foo, bar)".
    Node newFirstArgument = secondArgument.getFirstChild();
    secondArgument.removeChild(newFirstArgument);
    Node newSecondArgument = secondArgument.getLastChild();
    secondArgument.removeChild(newSecondArgument);
    n.replaceChild(firstArgument, newFirstArgument);
    n.replaceChild(secondArgument, newSecondArgument);
  } else {
    // Rewrite "new goog.testing.ObjectPropertyString(window, foo)" as
    // "new goog.testing.ObjectPropertyString(window, 'foo')"
    n.replaceChild(secondArgument,
        Node.newString(secondArgument.getString()));
  }
  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:41,代码来源:ObjectPropertyStringPostprocess.java

示例11: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (parent == null) {
    return;
  }
  if (n.getType() == Token.FUNCTION || n.getType() == Token.SCRIPT) {
    return;
  }
  // Removes TRYs that had its CATCH removed and/or empty FINALLY.
  if (n.getType() == Token.TRY) {
    Node body = n.getFirstChild();
    Node catchOrFinallyBlock = body.getNext();
    Node finallyBlock = catchOrFinallyBlock.getNext();

    if (!catchOrFinallyBlock.hasChildren() &&
        (finallyBlock == null || !finallyBlock.hasChildren())) {
      n.removeChild(body);
      parent.replaceChild(n, body);
      compiler.reportCodeChange();
      n = body;
    }
  }
  GraphNode<Node, Branch> gNode = curCfg.getNode(n);
  if (gNode == null) { // Not in CFG.
    return;
  }
  if (gNode.getAnnotation() != GraphReachability.REACHABLE ||
      (removeNoOpStatements && !NodeUtil.mayHaveSideEffects(n))) {
    removeDeadExprStatementSafely(n, parent);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:32,代码来源:UnreachableCodeElimination.java

示例12: testLabelLocation

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testLabelLocation() {
  Node root = newParse(
      "\nfoo:\n" +
      "a = 1;\n" +
      "bar:\n" +
      "b = 2;\n");

  Node firstStmt = root.getFirstChild();
  Node secondStmt = firstStmt.getNext();

  assertNodePosition(1, 0, firstStmt);
  assertNodePosition(3, 0, secondStmt);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:IRFactoryTest.java

示例13: testFunctionParamLocation

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testFunctionParamLocation() {
  Node root = newParse(
      "\nfunction\n" +
      "     foo(a,\n" +
      "     b,\n" +
      "     c)\n" +
      "{}\n");

  Node function = root.getFirstChild();
  Node functionName = function.getFirstChild();
  Node params = functionName.getNext();
  Node param1 = params.getFirstChild();
  Node param2 = param1.getNext();
  Node param3 = param2.getNext();
  Node body = params.getNext();

  assertNodePosition(2, 5, function);
  assertNodePosition(2, 5, functionName);
  // params corresponds to the LP token.
  // Can't be on a separate line because of inferred
  // semicolons.
  assertNodePosition(2, 8, params);
  assertNodePosition(2, 9, param1);
  assertNodePosition(3, 5, param2);
  assertNodePosition(4, 5, param3);
  assertNodePosition(5, 0, body);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:IRFactoryTest.java

示例14: testSwitchLocation

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testSwitchLocation() {
  Node root = newParse(
      "\nswitch (a) {\n" +
      "  //{\n" +
      "   case 1:\n" +
      "     b++;\n" +
      "   case 2:\n" +
      "   default:\n" +
      "     b--;\n" +
      "  }\n");

  Node switchStmt = root.getFirstChild();
  Node switchVar = switchStmt.getFirstChild();
  Node firstCase = switchVar.getNext();
  Node caseArg = firstCase.getFirstChild();
  Node caseBody = caseArg.getNext();
  Node caseExprStmt = caseBody.getFirstChild();
  Node incrExpr = caseExprStmt.getFirstChild();
  Node incrVar = incrExpr.getFirstChild();
  Node secondCase = firstCase.getNext();
  Node defaultCase = secondCase.getNext();

  assertNodePosition(1, 0, switchStmt);
  assertNodePosition(1, 8, switchVar);
  assertNodePosition(3, 3, firstCase);
  assertNodePosition(3, 8, caseArg);
  assertNodePosition(3, 3, caseBody);
  assertNodePosition(4, 5, caseExprStmt);
  assertNodePosition(4, 5, incrExpr);
  assertNodePosition(4, 5, incrVar);
  assertNodePosition(5, 3, secondCase);
  assertNodePosition(6, 3, defaultCase);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:IRFactoryTest.java

示例15: testIsLabelName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testIsLabelName() {
  Compiler compiler = new Compiler();

  // Test removing the initializer.
  String code = "a:while(1) {a; continue a; break a; break;}";
  Node actual = parse(code);

  Node labelNode = actual.getFirstChild();
  assertTrue(labelNode.getType() == Token.LABEL);
  assertTrue(NodeUtil.isLabelName(labelNode.getFirstChild()));
  assertFalse(NodeUtil.isLabelName(labelNode.getLastChild()));

  Node whileNode = labelNode.getLastChild();
  assertTrue(whileNode.getType() == Token.WHILE);
  Node whileBlock = whileNode.getLastChild();
  assertTrue(whileBlock.getType() == Token.BLOCK);
  assertFalse(NodeUtil.isLabelName(whileBlock));

  Node firstStatement = whileBlock.getFirstChild();
  assertTrue(firstStatement.getType() == Token.EXPR_RESULT);
  Node variableReference = firstStatement.getFirstChild();
  assertTrue(variableReference.getType() == Token.NAME);
  assertFalse(NodeUtil.isLabelName(variableReference));

  Node continueStatement = firstStatement.getNext();
  assertTrue(continueStatement.getType() == Token.CONTINUE);
  assertTrue(NodeUtil.isLabelName(continueStatement.getFirstChild()));

  Node firstBreak = continueStatement.getNext();
  assertTrue(firstBreak.getType() == Token.BREAK);
  assertTrue(NodeUtil.isLabelName(firstBreak.getFirstChild()));

  Node secondBreak = firstBreak.getNext();
  assertTrue(secondBreak.getType() == Token.BREAK);
  assertFalse(secondBreak.hasChildren());
  assertFalse(NodeUtil.isLabelName(secondBreak.getFirstChild()));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:38,代码来源:NodeUtilTest.java


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