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


Java Token.SWITCH属性代码示例

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


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

示例1: isControlStructure

/**
 * Determines whether the given node is a FOR, DO, WHILE, WITH, or IF node.
 */
static boolean isControlStructure(Node n) {
  switch (n.getType()) {
    case Token.FOR:
    case Token.DO:
    case Token.WHILE:
    case Token.WITH:
    case Token.IF:
    case Token.LABEL:
    case Token.TRY:
    case Token.CATCH:
    case Token.SWITCH:
    case Token.CASE:
    case Token.DEFAULT:
      return true;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:NodeUtil.java

示例2: isControlStructureCodeBlock

/**
 * Determines whether the given node is code node for FOR, DO,
 * WHILE, WITH, or IF node.
 */
static boolean isControlStructureCodeBlock(Node parent, Node n) {
  switch (parent.getType()) {
    case Token.FOR:
    case Token.WHILE:
    case Token.LABEL:
    case Token.WITH:
      return parent.getLastChild() == n;
    case Token.DO:
      return parent.getFirstChild() == n;
    case Token.IF:
      return parent.getFirstChild() != n;
    case Token.TRY:
      return parent.getFirstChild() == n || parent.getLastChild() == n;
    case Token.CATCH:
      return parent.getLastChild() == n;
    case Token.SWITCH:
    case Token.CASE:
      return parent.getFirstChild() != n;
    case Token.DEFAULT:
      return true;
    default:
      Preconditions.checkState(isControlStructure(parent));
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:NodeUtil.java

示例3: updateAssignAllowedStack

/**
 * Determines whether assignment to a define should be allowed
 * in the subtree of the given node, and if not, records that fact.
 *
 * @param n The node whose subtree we're about to enter or exit.
 * @param entering True if we're entering the subtree, false otherwise.
 */
private void updateAssignAllowedStack(Node n, boolean entering) {
  switch (n.getType()) {
    case Token.CASE:
    case Token.FOR:
    case Token.FUNCTION:
    case Token.HOOK:
    case Token.IF:
    case Token.SWITCH:
    case Token.WHILE:
      if (entering) {
        assignAllowed.push(0);
      } else {
        assignAllowed.remove();
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:ProcessDefines.java

示例4: normalizeBlocks

/**
 * Add blocks to IF, WHILE, DO, etc.
 */
private void normalizeBlocks(Node n) {
  if (NodeUtil.isControlStructure(n)
      && n.getType() != Token.LABEL
      && n.getType() != Token.SWITCH) {
    for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
      if (NodeUtil.isControlStructureCodeBlock(n,c) &&
          c.getType() != Token.BLOCK) {
        Node newBlock = new Node(Token.BLOCK);
        n.replaceChild(c, newBlock);
        if (c.getType() != Token.EMPTY) {
          newBlock.addChildrenToFront(c);
        } else {
          newBlock.setWasEmptyNode(true);
        }
        c = newBlock;
        reportChange();
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:PrepareAst.java

示例5: isBreakStructure

/**
 * Determines whether the given node can be terminated with a BREAK node.
 */
static boolean isBreakStructure(Node n, boolean labeled) {
  switch (n.getType()) {
    case Token.FOR:
    case Token.DO:
    case Token.WHILE:
    case Token.SWITCH:
      return true;
    case Token.BLOCK:
    case Token.IF:
    case Token.TRY:
      return labeled;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:ControlFlowAnalysis.java

示例6: hasConditionalAncestor

/**
 * return true if the node has any form of conditional in its ancestry
 * TODO(nicksantos) keep track of the conditionals in the ancestory, so
 * that we don't have to recrawl it.
 */
private boolean hasConditionalAncestor(Node n) {
  for (Node ancestor : n.getAncestors()) {
    switch (ancestor.getType()) {
      case Token.DO:
      case Token.FOR:
      case Token.HOOK:
      case Token.IF:
      case Token.SWITCH:
      case Token.WHILE:
        return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:CrossModuleCodeMotion.java

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

示例8: findExpressionRoot

/**
 * @return The statement containing the expression. null if subExpression
 *     is not contain by in by a Node where inlining is known to be possible.
 *     For example, a WHILE node condition expression.
 */
static Node findExpressionRoot(Node subExpression) {
  Node child = subExpression;
  for (Node parent : child.getAncestors()) {
    int parentType = parent.getType();
    switch (parentType) {
      // Supported expression roots:
      // SWITCH and IF can have multiple children, but the CASE, DEFAULT,
      // or BLOCK will be encountered first for any of the children other
      // than the condition.
      case Token.EXPR_RESULT:
      case Token.IF:
      case Token.SWITCH:
      case Token.RETURN:
      case Token.VAR:
        Preconditions.checkState(child == parent.getFirstChild());
        return parent;
      // Any of these indicate an unsupported expression:
      case Token.SCRIPT:
      case Token.BLOCK:
      case Token.LABEL:
      case Token.CASE:
      case Token.DEFAULT:
        return null;
    }
    child = parent;
  }

  throw new IllegalStateException("Unexpected AST structure.");
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:ExpressionDecomposer.java

示例9: tryRemoveDeadAssignments

/**
 * Try to remove useless assignments from a control flow graph that has been
 * annotated with liveness information.
 *
 * @param t The node traversal.
 * @param cfg The control flow graph of the program annotated with liveness
 *        information.
 */
private void tryRemoveDeadAssignments(NodeTraversal t,
    ControlFlowGraph<Node> cfg) {
  List<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes();

  for (DiGraphNode<Node, Branch> cfgNode : nodes) {
    FlowState<LiveVariableLattice> state =
        cfgNode.getAnnotation();
    Node n = cfgNode.getValue();
    if (n == null) {
      continue;
    }
    switch (n.getType()) {
      case Token.IF:
      case Token.WHILE:
      case Token.DO:
        tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state);
        continue;
      case Token.FOR:
        if (!NodeUtil.isForIn(n)) {
          tryRemoveAssignment(
              t, NodeUtil.getConditionExpression(n), state);
        }
        continue;
      case Token.SWITCH:
      case Token.CASE:
      case Token.RETURN:
        if (n.hasChildren()) {
          tryRemoveAssignment(t, n.getFirstChild(), state);
        }
        continue;
      // TODO(user): case Token.VAR: Remove var a=1;a=2;.....
    }
    
    tryRemoveAssignment(t, n, state);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:44,代码来源:DeadAssignmentsElimination.java

示例10: processSwitchStatement

@Override
Node processSwitchStatement(SwitchStatement statementNode) {
  Node node = new Node(Token.SWITCH,
      transform(statementNode.getExpression()));
  for (AstNode child : statementNode.getCases()) {
    node.addChildToBack(transform(child));
  }
  return node;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:9,代码来源:IRFactory.java

示例11: isEnteringNewCfgNode

/**
 * @return True if n should be represented by a new CFG node in the control
 * flow graph.
 */
public static boolean isEnteringNewCfgNode(Node n) {
  Node parent = n.getParent();
  switch (parent.getType()) {
    case Token.BLOCK:
    case Token.SCRIPT:
    case Token.TRY:
    case Token.FINALLY:
      return true;
    case Token.FUNCTION:
      // A function node represents the start of a function where the name
      // is bleed into the local scope and parameters has been assigned
      // to the formal argument names. The node includes the name of the
      // function and the LP list since we assume the whole set up process
      // is atomic without change in control flow. The next change of
      // control is going into the function's body represent by the second
      // child.
      return n != parent.getFirstChild().getNext();
    case Token.WHILE:
    case Token.DO:
    case Token.IF:
      // Theses control structure is represented by its node that holds the
      // condition. Each of them is a branch node based on its condition.
      return NodeUtil.getConditionExpression(parent) != n;
      
    case Token.FOR:
      // The FOR(;;) node differs from other control structure in that
      // it has a initialization and a increment statement. Those
      // two statements have its corresponding CFG nodes to represent them.
      // The FOR node represents the condition check for each iteration.
      // That way the following:
      // for(var x = 0; x < 10; x++) { } has a graph that is isomorphic to
      // var x = 0; while(x<10) {  x++; }
      if (NodeUtil.isForIn(parent)) {
        return n == parent.getLastChild(); 
      } else {
        return NodeUtil.getConditionExpression(parent) != n;
      }
    case Token.SWITCH:
    case Token.CASE:
    case Token.CATCH:
    case Token.WITH:
      return n != parent.getFirstChild();
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:50,代码来源:ControlFlowGraph.java

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

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