Java Code Examples for com.google.javascript.rhino.Token#DEFAULT_CASE

The following examples show how to use com.google.javascript.rhino.Token#DEFAULT_CASE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: jMutRepair_003_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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_CASE:
      return true;
    default:
      return false;
  }
}
 
Example 2
Source File: Closure_10_NodeUtil_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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_CASE:
      return true;
    default:
      return false;
  }
}
 
Example 3
Source File: jMutRepair_003_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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_CASE:
      return true;
    default:
      Preconditions.checkState(isControlStructure(parent));
      return false;
  }
}
 
Example 4
Source File: Closure_10_NodeUtil_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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_CASE:
      return true;
    default:
      return false;
  }
}
 
Example 5
Source File: Cardumen_0087_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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_CASE:
      return true;
    default:
      return false;
  }
}
 
Example 6
Source File: jKali_003_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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_CASE:
      return true;
    default:
      Preconditions.checkState(isControlStructure(parent));
      return false;
  }
}
 
Example 7
Source File: Cardumen_0014_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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_CASE:
      return true;
    default:
      Preconditions.checkState(isControlStructure(parent));
      return false;
  }
}
 
Example 8
Source File: Closure_10_NodeUtil_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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_CASE:
      return true;
    default:
      Preconditions.checkState(isControlStructure(parent));
      return false;
  }
}
 
Example 9
Source File: ControlFlowAnalysis.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void handleStmtList(Node node) {
  Node parent = node.getParent();
  // Special case, don't add a block of empty CATCH block to the graph.
  if (node.isBlock() && parent != null &&
      parent.isTry() &&
      NodeUtil.getCatchBlock(parent) == node &&
      !NodeUtil.hasCatchHandler(node)) {
    return;
  }

  // A block transfer control to its first child if it is not empty.
  Node child = node.getFirstChild();

  // Function declarations are skipped since control doesn't go into that
  // function (unless it is called)
  while (child != null && child.isFunction()) {
    child = child.getNext();
  }

  if (child != null) {
    createEdge(node, Branch.UNCOND, computeFallThrough(child));
  } else {
    createEdge(node, Branch.UNCOND, computeFollowNode(node, this));
  }

  // Synthetic blocks
  if (parent != null) {
    switch (parent.getType()) {
      case Token.DEFAULT_CASE:
      case Token.CASE:
      case Token.TRY:
        break;
      default:
        if (node.isBlock() && node.isSyntheticBlock()) {
          createEdge(node, Branch.SYN_BLOCK, computeFollowNode(node, this));
        }
        break;
    }
  }
}
 
Example 10
Source File: jKali_003_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param n The expression to check.
 * @return Whether the expression is unconditionally executed only once in the
 *     containing execution scope.
 */
static boolean isExecutedExactlyOnce(Node n) {
  inspect: do {
    Node parent = n.getParent();
    switch (parent.getType()) {
      case Token.IF:
      case Token.HOOK:
      case Token.AND:
      case Token.OR:
        if (parent.getFirstChild() != n) {
          return false;
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.FOR:
        if (NodeUtil.isForIn(parent)) {
          if (parent.getChildAtIndex(1) != n) {
            return false;
          }
        } else {
          if (parent.getFirstChild() != n) {
            return false;
          }
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.WHILE:
      case Token.DO:
        return false;
      case Token.TRY:
        // Consider all code under a try/catch to be conditionally executed.
        if (!hasFinally(parent) || parent.getLastChild() != n) {
          return false;
        }
        continue inspect;
      case Token.CASE:
      case Token.DEFAULT_CASE:
        return false;
      case Token.SCRIPT:
      case Token.FUNCTION:
        // Done, we've reached the scope root.
        break inspect;
    }
  } while ((n = n.getParent()) != null);
  return true;
}
 
Example 11
Source File: 1_ControlFlowAnalysis.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
@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_CASE:
      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;
  }
}
 
Example 12
Source File: Cardumen_0014_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param n The expression to check.
 * @return Whether the expression is unconditionally executed only once in the
 *     containing execution scope.
 */
static boolean isExecutedExactlyOnce(Node n) {
  inspect: do {
    Node parent = n.getParent();
    switch (parent.getType()) {
      case Token.IF:
      case Token.HOOK:
      case Token.AND:
      case Token.OR:
        if (parent.getFirstChild() != n) {
          return false;
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.FOR:
        if (NodeUtil.isForIn(parent)) {
          if (parent.getChildAtIndex(1) != n) {
            return false;
          }
        } else {
          if (parent.getFirstChild() != n) {
            return false;
          }
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.WHILE:
      case Token.DO:
        return false;
      case Token.TRY:
        // Consider all code under a try/catch to be conditionally executed.
        if (!hasFinally(parent) || parent.getLastChild() != n) {
          return false;
        }
        continue inspect;
      case Token.CASE:
      case Token.DEFAULT_CASE:
        return false;
      case Token.SCRIPT:
      case Token.FUNCTION:
        // Done, we've reached the scope root.
        break inspect;
    }
  } while ((n = n.getParent()) != null);
  return true;
}
 
Example 13
Source File: ControlFlowAnalysis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@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_CASE:
      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;
  }
}
 
Example 14
Source File: Closure_14_ControlFlowAnalysis_s.java    From coming with MIT License 4 votes vote down vote up
@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_CASE:
      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;
  }
}
 
Example 15
Source File: NodeUtil.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param n The expression to check.
 * @return Whether the expression is unconditionally executed only once in the
 *     containing execution scope.
 */
static boolean isExecutedExactlyOnce(Node n) {
  inspect: do {
    Node parent = n.getParent();
    switch (parent.getType()) {
      case Token.IF:
      case Token.HOOK:
      case Token.AND:
      case Token.OR:
        if (parent.getFirstChild() != n) {
          return false;
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.FOR:
        if (NodeUtil.isForIn(parent)) {
          if (parent.getChildAtIndex(1) != n) {
            return false;
          }
        } else {
          if (parent.getFirstChild() != n) {
            return false;
          }
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.WHILE:
      case Token.DO:
        return false;
      case Token.TRY:
        // Consider all code under a try/catch to be conditionally executed.
        if (!hasFinally(parent) || parent.getLastChild() != n) {
          return false;
        }
        continue inspect;
      case Token.CASE:
      case Token.DEFAULT_CASE:
        return false;
      case Token.SCRIPT:
      case Token.FUNCTION:
        // Done, we've reached the scope root.
        break inspect;
    }
  } while ((n = n.getParent()) != null);
  return true;
}
 
Example 16
Source File: Cardumen_0087_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param n The expression to check.
 * @return Whether the expression is unconditionally executed only once in the
 *     containing execution scope.
 */
static boolean isExecutedExactlyOnce(Node n) {
  inspect: do {
    Node parent = n.getParent();
    switch (parent.getType()) {
      case Token.IF:
      case Token.HOOK:
      case Token.AND:
      case Token.OR:
        if (parent.getFirstChild() != n) {
          return false;
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.FOR:
        if (NodeUtil.isForIn(parent)) {
          if (parent.getChildAtIndex(1) != n) {
            return false;
          }
        } else {
          if (parent.getFirstChild() != n) {
            return false;
          }
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.WHILE:
      case Token.DO:
        return false;
      case Token.TRY:
        // Consider all code under a try/catch to be conditionally executed.
        if (!hasFinally(parent) || parent.getLastChild() != n) {
          return false;
        }
        continue inspect;
      case Token.CASE:
      case Token.DEFAULT_CASE:
        return false;
      case Token.SCRIPT:
      case Token.FUNCTION:
        // Done, we've reached the scope root.
        break inspect;
    }
  } while ((n = n.getParent()) != null);
  return true;
}
 
Example 17
Source File: jMutRepair_003_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param n The expression to check.
 * @return Whether the expression is unconditionally executed only once in the
 *     containing execution scope.
 */
static boolean isExecutedExactlyOnce(Node n) {
  inspect: do {
    Node parent = n.getParent();
    switch (parent.getType()) {
      case Token.IF:
      case Token.HOOK:
      case Token.AND:
      case Token.OR:
        if (parent.getFirstChild() != n) {
          return false;
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.FOR:
        if (NodeUtil.isForIn(parent)) {
          if (parent.getChildAtIndex(1) != n) {
            return false;
          }
        } else {
          if (parent.getFirstChild() != n) {
            return false;
          }
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.WHILE:
      case Token.DO:
        return false;
      case Token.TRY:
        // Consider all code under a try/catch to be conditionally executed.
        if (!hasFinally(parent) || parent.getLastChild() != n) {
          return false;
        }
        continue inspect;
      case Token.CASE:
      case Token.DEFAULT_CASE:
        return false;
      case Token.SCRIPT:
      case Token.FUNCTION:
        // Done, we've reached the scope root.
        break inspect;
    }
  } while ((n = n.getParent()) != null);
  return true;
}
 
Example 18
Source File: Cardumen_00200_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param n The expression to check.
 * @return Whether the expression is unconditionally executed only once in the
 *     containing execution scope.
 */
static boolean isExecutedExactlyOnce(Node n) {
  inspect: do {
    Node parent = n.getParent();
    switch (parent.getType()) {
      case Token.IF:
      case Token.HOOK:
      case Token.AND:
      case Token.OR:
        if (parent.getFirstChild() != n) {
          return false;
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.FOR:
        if (NodeUtil.isForIn(parent)) {
          if (parent.getChildAtIndex(1) != n) {
            return false;
          }
        } else {
          if (parent.getFirstChild() != n) {
            return false;
          }
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.WHILE:
      case Token.DO:
        return false;
      case Token.TRY:
        // Consider all code under a try/catch to be conditionally executed.
        if (!hasFinally(parent) || parent.getLastChild() != n) {
          return false;
        }
        continue inspect;
      case Token.CASE:
      case Token.DEFAULT_CASE:
        return false;
      case Token.SCRIPT:
      case Token.FUNCTION:
        // Done, we've reached the scope root.
        break inspect;
    }
  } while ((n = n.getParent()) != null);
  return true;
}
 
Example 19
Source File: Cardumen_00200_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param n The expression to check.
 * @return Whether the expression is unconditionally executed only once in the
 *     containing execution scope.
 */
static boolean isExecutedExactlyOnce(Node n) {
  inspect: do {
    Node parent = n.getParent();
    switch (parent.getType()) {
      case Token.IF:
      case Token.HOOK:
      case Token.AND:
      case Token.OR:
        if (parent.getFirstChild() != n) {
          return false;
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.FOR:
        if (NodeUtil.isForIn(parent)) {
          if (parent.getChildAtIndex(1) != n) {
            return false;
          }
        } else {
          if (parent.getFirstChild() != n) {
            return false;
          }
        }
        // other ancestors may be conditional
        continue inspect;
      case Token.WHILE:
      case Token.DO:
        return false;
      case Token.TRY:
        // Consider all code under a try/catch to be conditionally executed.
        if (!hasFinally(parent) || parent.getLastChild() != n) {
          return false;
        }
        continue inspect;
      case Token.CASE:
      case Token.DEFAULT_CASE:
        return false;
      case Token.SCRIPT:
      case Token.FUNCTION:
        // Done, we've reached the scope root.
        break inspect;
    }
  } while ((n = n.getParent()) != null);
  return true;
}
 
Example 20
Source File: 1_ControlFlowAnalysis.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
@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_CASE:
      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;
  }
}