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


Java Token.THROW属性代码示例

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


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

示例1: nodeTypeMayHaveSideEffects

/**
 * Returns true if the current node's type implies side effects.
 *
 * This is a non-recursive version of the may have side effects
 * check; used to check wherever the current node's type is one of
 * the reason's why a subtree has side effects.
 */
static boolean nodeTypeMayHaveSideEffects(Node n) {
  if (NodeUtil.isAssignmentOp(n)) {
    return true;
  }

  switch(n.getType()) {
    case Token.CALL:
    case Token.DELPROP:
    case Token.NEW:
    case Token.DEC:
    case Token.INC:
    case Token.THROW:
      return true;
    case Token.NAME:
      // A variable definition.
      return n.hasChildren();
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:NodeUtil.java

示例2: mayThrowException

/**
 * Determines if the subtree might throw an exception.
 */
private static boolean mayThrowException(Node n) {
  switch (n.getType()) {
    case Token.CALL:
    case Token.GETPROP:
    case Token.GETELEM:
    case Token.THROW:
    case Token.NEW:
    case Token.ASSIGN:
    case Token.INC:
    case Token.DEC:
    case Token.INSTANCEOF:
      return true;
    case Token.FUNCTION:
      return false;
  }
  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && mayThrowException(c)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:ControlFlowAnalysis.java

示例3: isInThrowExpression

/**
 * Is the {@link Node} currently within a 'throw' expression?
 */
private static boolean isInThrowExpression(Node n) {
  // Look up the traversal stack to find a THROW node
  for (Node ancestor : n.getAncestors()) {
    switch (ancestor.getType()) {
      case Token.THROW:
        return true;
      case Token.IF:
      case Token.WHILE:
      case Token.DO:
      case Token.FOR:
      case Token.SWITCH:
      case Token.CASE:
      case Token.DEFAULT:
      case Token.BLOCK:
      case Token.SCRIPT:
      case Token.FUNCTION:
      case Token.TRY:
      case Token.CATCH:
      case Token.RETURN:
      case Token.EXPR_RESULT:
        // early exit - these nodes types can't be within a THROW
        return false;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:AliasStrings.java

示例4: createAliasFunctionNode

/**
 * Creates a function node that takes a single argument, the object to
 * throw. The function throws the object.
 */
private static Node createAliasFunctionNode(String aliasName) {
  Node parameterName = Node.newString(Token.NAME, "t");
  List<Node> parameters = Lists.newArrayList(parameterName.cloneNode());
  Node throwStatement = new Node(Token.THROW, parameterName);
  Node body = new Node(Token.BLOCK, throwStatement);
  return NodeUtil.newFunctionNode(aliasName, parameters, body, -1, -1);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:11,代码来源:AliasKeywords.java

示例5: testNewFunctionNode

public void testNewFunctionNode() {
  Node expected = parse("function foo(p1, p2, p3) { throw 2; }");
  Node body = new Node(Token.BLOCK, new Node(Token.THROW, Node.newNumber(2)));
  List<Node> params = Lists.newArrayList(Node.newString(Token.NAME, "p1"),
                                         Node.newString(Token.NAME, "p2"),
                                         Node.newString(Token.NAME, "p3"));
  FunctionNode function = NodeUtil.newFunctionNode(
      "foo", params, body, -1, -1);
  ScriptOrFnNode actual = new ScriptOrFnNode(Token.SCRIPT);
  actual.addChildToFront(function);
  String difference = expected.checkTreeEquals(actual);
  if (difference != null) {
    assertTrue("Nodes do not match:\n" + difference, false);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:NodeUtilTest.java

示例6: ThrowAliasSpecification

ThrowAliasSpecification(String aliasName) {
  super(aliasName, Token.THROW);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:3,代码来源:AliasKeywords.java

示例7: visit

@Override
public void visit(NodeTraversal traversal, Node node, Node parent) {

  if (inExterns) {
    return;
  }

  if (!NodeUtil.nodeTypeMayHaveSideEffects(node)) {
    return;
  }

  if (NodeUtil.isCall(node) || NodeUtil.isNew(node)) {
    allFunctionCalls.add(node);
  }

  Node enclosingFunction = traversal.getEnclosingFunction();
  if (enclosingFunction != null) {
    FunctionInformation sideEffectInfo =
        functionSideEffectMap.get(enclosingFunction);
    Preconditions.checkNotNull(sideEffectInfo);

    if (NodeUtil.isAssignmentOp(node)) {
      visitAssignmentOrUnaryOperatorLhs(
          sideEffectInfo, traversal.getScope(), node.getFirstChild());
    } else {
      switch(node.getType()) {
        case Token.CALL:
        case Token.NEW:
          visitCall(sideEffectInfo, node);
          break;
        case Token.DELPROP:
        case Token.DEC:
        case Token.INC:
          visitAssignmentOrUnaryOperatorLhs(
              sideEffectInfo, traversal.getScope(), node.getFirstChild());
          break;
        case Token.NAME:

          // Variable definition are not side effects.
          // Just check that the name appears in the context of a
          // variable declaration.
          Preconditions.checkArgument(
              NodeUtil.isVarDeclaration(node));
          break;
        case Token.THROW:
          visitThrow(sideEffectInfo);
          break;
        default:
          throw new IllegalArgumentException(
              "Unhandled side effect node type " +
              Token.name(node.getType()));
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:55,代码来源:PureFunctionIdentifier.java

示例8: processThrowStatement

@Override
Node processThrowStatement(ThrowStatement statementNode) {
  return new Node(Token.THROW,
      transform(statementNode.getExpression()));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:5,代码来源:IRFactory.java

示例9: shouldTraverse

@Override
public boolean shouldTraverse(
    NodeTraversal nodeTraversal, Node n, Node parent) {
  astPosition.put(n, astPositionCounter++);

  switch (n.getType()) {
    case Token.FUNCTION:
      if (shouldTraverseFunctions || n == cfg.getEntry().getValue()) {
        exceptionHandler.push(n);
        return true;
      }
      return false;
    case Token.TRY:
      exceptionHandler.push(n);
      return true;
  }

  /*
   * We are going to stop the traversal depending on what the node's parent
   * is.
   *
   * We are only interested in adding edges between nodes that change control
   * flow. The most obvious ones are loops and IF-ELSE's. A statement
   * transfers control to its next sibling.
   *
   * In case of an expression tree, there is no control flow within the tree
   * even when there are short circuited operators and conditionals. When we
   * are doing data flow analysis, we will simply synthesize lattices up the
   * expression tree by finding the meet at each expression node.
   *
   * For example: within a Token.SWITCH, the expression in question does not
   * change the control flow and need not to be considered.
   */
  if (parent != null) {
    switch (parent.getType()) {
      case Token.FOR:
        // Only traverse the body of the for loop.
        return n == parent.getLastChild();

      // Skip the conditions.
      case Token.IF:
      case Token.WHILE:
      case Token.WITH:
        return n != parent.getFirstChild();
      case Token.DO:
        return n != parent.getFirstChild().getNext();
      // Only traverse the body of the cases
      case Token.SWITCH:
      case Token.CASE:
      case Token.CATCH:
      case Token.LABEL:
        return n != parent.getFirstChild();
      case Token.FUNCTION:
        return n == parent.getFirstChild().getNext().getNext();
      case Token.CONTINUE:
      case Token.BREAK:
      case Token.EXPR_RESULT:
      case Token.VAR:
      case Token.RETURN:
      case Token.THROW:
        return false;
      case Token.TRY:
        /* Just before we are about to visit the second child of the TRY node,
         * we know that we will be visiting either the CATCH or the FINALLY.
         * In other words, we know that the post order traversal of the TRY
         * block has been finished, no more exceptions can be caught by the
         * handler at this TRY block and should be taken out of the stack.
         */
        if (n == parent.getFirstChild().getNext()) {
          Preconditions.checkState(exceptionHandler.peek() == parent);
          exceptionHandler.pop();
        }
    }
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:76,代码来源:ControlFlowAnalysis.java

示例10: visit

@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.IF:
      handleIf(n);
      return;
    case Token.WHILE:
      handleWhile(n);
      return;
    case Token.DO:
      handleDo(n);
      return;
    case Token.FOR:
      handleFor(n);
      return;
    case Token.SWITCH:
      handleSwitch(n);
      return;
    case Token.CASE:
      handleCase(n);
      return;
    case Token.DEFAULT:
      handleDefault(n);
      return;
    case Token.BLOCK:
    case Token.SCRIPT:
      handleStmtList(n);
      return;
    case Token.FUNCTION:
      handleFunction(n);
      return;
    case Token.EXPR_RESULT:
      handleExpr(n);
      return;
    case Token.THROW:
      handleThrow(n);
      return;
    case Token.TRY:
      handleTry(n);
      return;
    case Token.CATCH:
      handleCatch(n);
      return;
    case Token.BREAK:
      handleBreak(n);
      return;
    case Token.CONTINUE:
      handleContinue(n);
      return;
    case Token.RETURN:
      handleReturn(n);
      return;
    case Token.WITH:
      handleWith(n);
      return;
    case Token.LABEL:
      return;
    default:
      handleStmt(n);
      return;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:62,代码来源:ControlFlowAnalysis.java


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