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

The following examples show how to use com.google.javascript.rhino.Token#TRY . 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: Cardumen_00149_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 2
Source File: NodeUtil.java    From astor with GNU General Public License v2.0 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: 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 4
Source File: Closure_86_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:
      return true;
    default:
      return false;
  }
}
 
Example 5
Source File: Closure_94_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:
      return true;
    default:
      return false;
  }
}
 
Example 6
Source File: Closure_103_ControlFlowAnalysis_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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;
  }
}
 
Example 7
Source File: Cardumen_00200_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 8
Source File: 1_ControlFlowAnalysis.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
  }
}
 
Example 9
Source File: Closure_61_NodeUtil_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:
      return true;
    default:
      Preconditions.checkState(isControlStructure(parent));
      return false;
  }
}
 
Example 10
Source File: Closure_80_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:
      return true;
    default:
      return false;
  }
}
 
Example 11
Source File: Cardumen_0014_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 12
Source File: Closure_86_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:
      return true;
    default:
      Preconditions.checkState(isControlStructure(parent));
      return false;
  }
}
 
Example 13
Source File: Closure_75_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:
      return true;
    default:
      return false;
  }
}
 
Example 14
Source File: ReferenceCollectingCallback.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return true if this node marks the start of a new basic block
 */
private static boolean isBlockBoundary(Node n, Node parent) {
  if (parent != null) {
    switch (parent.getType()) {
      case Token.DO:
      case Token.FOR:
      case Token.TRY:
      case Token.WHILE:
      case Token.WITH:
        // NOTE: TRY has up to 3 child blocks:
        // TRY
        //   BLOCK
        //   BLOCK
        //     CATCH
        //   BLOCK
        // Note that there is an explicit CATCH token but no explicit
        // FINALLY token. For simplicity, we consider each BLOCK
        // a separate basic BLOCK.
        return true;
      case Token.AND:
      case Token.HOOK:
      case Token.IF:
      case Token.OR:
        // The first child of a conditional is not a boundary,
        // but all the rest of the children are.
        return n != parent.getFirstChild();

    }
  }

  return n.isCase();
}
 
Example 15
Source File: Closure_103_ControlFlowAnalysis_s.java    From coming with MIT License 5 votes vote down vote up
private void handleContinue(Node node) {
  String label = null;
  if (node.hasChildren()) {
    label = node.getFirstChild().getString();
  }
  Node cur;
  Node lastJump;
  // Similar to handBreak's logic with a few minor variation.
  Node parent = node.getParent();
  for (cur = node, lastJump = node;
      !isContinueTarget(cur, parent, label);
      cur = parent, parent = parent.getParent()) {
    if (cur.getType() == Token.TRY && NodeUtil.hasFinally(cur)) {
      if (lastJump == node) {
        createEdge(lastJump, Branch.UNCOND, cur.getLastChild());
      } else {
        finallyMap.put(lastJump, computeFallThrough(cur.getLastChild()));
      }
      lastJump = cur;
    }
    Preconditions.checkState(parent != null, "Cannot find continue target.");
  }
  Node iter = cur;
  if (cur.getChildCount() == 4) {
    iter = cur.getFirstChild().getNext().getNext();
  }

  if (lastJump == node) {
    createEdge(node, Branch.UNCOND, iter);
  } else {
    finallyMap.put(lastJump, iter);
  }
}
 
Example 16
Source File: Closure_60_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/** Whether the node is a CATCH container BLOCK. */
static boolean isTryCatchNodeContainer(Node n) {
  Node parent = n.getParent();
  return parent.getType() == Token.TRY
      && parent.getFirstChild().getNext() == n;
}
 
Example 17
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 18
Source File: Closure_94_NodeUtil_s.java    From coming with MIT License 4 votes vote down vote up
/** Whether the child node is the FINALLY block of a try. */
static boolean isTryFinallyNode(Node parent, Node child) {
  return parent.getType() == Token.TRY && parent.getChildCount() == 3
      && child == parent.getLastChild();
}
 
Example 19
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 20
Source File: Closure_103_ControlFlowAnalysis_s.java    From coming with MIT License 4 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.getType() == Token.BLOCK && parent != null &&
      parent.getType() == Token.TRY &&
      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.getType() == Token.FUNCTION) {
    child = child.getNext();
  }

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

  // Synthetic blocks
  if (parent != null) {
    switch (parent.getType()) {
      case Token.DEFAULT:
      case Token.CASE:
      case Token.TRY:
        break;
      default:
        if (node.getType() == Token.BLOCK && node.isSyntheticBlock()) {
          Node next = node.getLastChild();
          if (next != null) {
            createEdge(node, Branch.SYN_BLOCK, computeFallThrough(next));
          }
        }
        break;
    }
  }
}