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

The following examples show how to use com.google.javascript.rhino.Token#CATCH . 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: Closure_94_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 2
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 3
Source File: Closure_60_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 4
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 5
Source File: Closure_61_NodeUtil_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as synactically similar to
 * "var x = 0;".
 *
 * @param node The node
 * @return True if n is an L-value.
 */
static boolean isLValue(Node node) {
  int nType = node.getType();
  Preconditions.checkArgument(nType == Token.NAME || nType == Token.GETPROP ||
      nType == Token.GETELEM);
  Node parent = node.getParent();
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == node)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == node)
      || NodeUtil.isVar(parent)
      || (parent.getType() == Token.FUNCTION &&
          parent.getFirstChild() == node)
      || parent.getType() == Token.DEC
      || parent.getType() == Token.INC
      || parent.getType() == Token.LP
      || parent.getType() == Token.CATCH;
}
 
Example 6
Source File: Closure_60_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 7
Source File: Closure_60_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 8
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 9
Source File: Closure_96_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Visits a NAME node.
 *
 * @param t The node traversal object that supplies context, such as the
 * scope chain to use in name lookups as well as error reporting.
 * @param n The node being visited.
 * @param parent The parent of the node n.
 * @return whether the node is typeable or not
 */
boolean visitName(NodeTraversal t, Node n, Node parent) {
  // At this stage, we need to determine whether this is a leaf
  // node in an expression (which therefore needs to have a type
  // assigned for it) versus some other decorative node that we
  // can safely ignore.  Function names, arguments (children of LP nodes) and
  // variable declarations are ignored.
  // TODO(user): remove this short-circuiting in favor of a
  // pre order traversal of the FUNCTION, CATCH, LP and VAR nodes.
  int parentNodeType = parent.getType();
  if (parentNodeType == Token.FUNCTION ||
      parentNodeType == Token.CATCH ||
      parentNodeType == Token.LP ||
      parentNodeType == Token.VAR) {
    return false;
  }

  JSType type = n.getJSType();
  if (type == null) {
    type = getNativeType(UNKNOWN_TYPE);
    Var var = t.getScope().getVar(n.getString());
    if (var != null) {
      JSType varType = var.getType();
      if (varType != null) {
        type = varType;
      }
    }
  }
  ensureTyped(t, n, type);
  return true;
}
 
Example 10
Source File: Closure_66_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Visits a NAME node.
 *
 * @param t The node traversal object that supplies context, such as the
 * scope chain to use in name lookups as well as error reporting.
 * @param n The node being visited.
 * @param parent The parent of the node n.
 * @return whether the node is typeable or not
 */
boolean visitName(NodeTraversal t, Node n, Node parent) {
  // At this stage, we need to determine whether this is a leaf
  // node in an expression (which therefore needs to have a type
  // assigned for it) versus some other decorative node that we
  // can safely ignore.  Function names, arguments (children of LP nodes) and
  // variable declarations are ignored.
  // TODO(user): remove this short-circuiting in favor of a
  // pre order traversal of the FUNCTION, CATCH, LP and VAR nodes.
  int parentNodeType = parent.getType();
  if (parentNodeType == Token.FUNCTION ||
      parentNodeType == Token.CATCH ||
      parentNodeType == Token.LP ||
      parentNodeType == Token.VAR) {
    return false;
  }

  JSType type = n.getJSType();
  if (type == null) {
    type = getNativeType(UNKNOWN_TYPE);
    Var var = t.getScope().getVar(n.getString());
    if (var != null) {
      JSType varType = var.getType();
      if (varType != null) {
        type = varType;
      }
    }
  }
  ensureTyped(t, n, type);
  return true;
}
 
Example 11
Source File: AliasStrings.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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:
      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;
}
 
Example 12
Source File: Closure_85_UnreachableCodeElimination_t.java    From coming with MIT License 5 votes vote down vote up
private void removeDeadExprStatementSafely(Node n) {
  Node parent = n.getParent();
  if (n.getType() == Token.EMPTY ||
      (n.getType() == Token.BLOCK && !n.hasChildren())) {
    // Not always trivial to remove, let FoldContants work its magic later.
    return;
  }

  switch (n.getType()) {
    // Removing an unreachable DO node is messy because it means we still have
    // to execute one iteration. If the DO's body has breaks in the middle, it
    // can get even more trickier and code size might actually increase.
    case Token.DO:
      return;

    case Token.BLOCK:
      // BLOCKs are used in several ways including wrapping CATCH blocks in TRYs
      if (parent.getType() == Token.TRY) {
        if (NodeUtil.isTryCatchNodeContainer(n)) {
          return;
        }
      }
      break;

    case Token.CATCH:
      Node tryNode = parent.getParent();
      NodeUtil.maybeAddFinally(tryNode);
      break;
  }

  NodeUtil.redeclareVarsInsideBranch(n);
  compiler.reportCodeChange();
  if (logger.isLoggable(Level.FINE)) {
    logger.fine("Removing " + n.toString());
  }
  NodeUtil.removeChild(n.getParent(), n);
}
 
Example 13
Source File: Closure_69_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Visits a NAME node.
 *
 * @param t The node traversal object that supplies context, such as the
 * scope chain to use in name lookups as well as error reporting.
 * @param n The node being visited.
 * @param parent The parent of the node n.
 * @return whether the node is typeable or not
 */
boolean visitName(NodeTraversal t, Node n, Node parent) {
  // At this stage, we need to determine whether this is a leaf
  // node in an expression (which therefore needs to have a type
  // assigned for it) versus some other decorative node that we
  // can safely ignore.  Function names, arguments (children of LP nodes) and
  // variable declarations are ignored.
  // TODO(user): remove this short-circuiting in favor of a
  // pre order traversal of the FUNCTION, CATCH, LP and VAR nodes.
  int parentNodeType = parent.getType();
  if (parentNodeType == Token.FUNCTION ||
      parentNodeType == Token.CATCH ||
      parentNodeType == Token.LP ||
      parentNodeType == Token.VAR) {
    return false;
  }

  JSType type = n.getJSType();
  if (type == null) {
    type = getNativeType(UNKNOWN_TYPE);
    Var var = t.getScope().getVar(n.getString());
    if (var != null) {
      JSType varType = var.getType();
      if (varType != null) {
        type = varType;
      }
    }
  }
  ensureTyped(t, n, type);
  return true;
}
 
Example 14
Source File: Closure_103_ControlFlowAnalysis_t.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:
      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: Closure_70_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  attachLiteralTypes(t, n);

  switch (n.getType()) {
    case Token.CALL:
      checkForClassDefiningCalls(t, n, parent);
      break;

    case Token.FUNCTION:
      if (t.getInput() == null || !t.getInput().isExtern()) {
        nonExternFunctions.add(n);
      }

      // Hoisted functions are handled during pre-traversal.
      if (!NodeUtil.isHoistedFunctionDeclaration(n)) {
        defineFunctionLiteral(n, parent);
      }
      break;

    case Token.ASSIGN:
      // Handle initialization of properties.
      Node firstChild = n.getFirstChild();
      if (firstChild.getType() == Token.GETPROP &&
          firstChild.isQualifiedName()) {
        maybeDeclareQualifiedName(t, n.getJSDocInfo(),
            firstChild, n, firstChild.getNext());
      }
      break;

    case Token.CATCH:
      defineCatch(n, parent);
      break;

    case Token.VAR:
      defineVar(n, parent);
      break;

    case Token.GETPROP:
      // Handle stubbed properties.
      if (parent.getType() == Token.EXPR_RESULT &&
          n.isQualifiedName()) {
        maybeDeclareQualifiedName(t, n.getJSDocInfo(), n, parent, null);
      }
      break;
  }
}
 
Example 16
Source File: Closure_43_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  inputId = t.getInputId();
  attachLiteralTypes(t, n);

  switch (n.getType()) {
    case Token.CALL:
      checkForClassDefiningCalls(t, n, parent);
      checkForCallingConventionDefiningCalls(n, delegateCallingConventions);
      break;

    case Token.FUNCTION:
      if (t.getInput() == null || !t.getInput().isExtern()) {
        nonExternFunctions.add(n);
      }

      // Hoisted functions are handled during pre-traversal.
      if (!NodeUtil.isHoistedFunctionDeclaration(n)) {
        defineFunctionLiteral(n, parent);
      }
      break;

    case Token.ASSIGN:
      // Handle initialization of properties.
      Node firstChild = n.getFirstChild();
      if (firstChild.isGetProp() &&
          firstChild.isQualifiedName()) {
        maybeDeclareQualifiedName(t, n.getJSDocInfo(),
            firstChild, n, firstChild.getNext());
      }
      break;

    case Token.CATCH:
      defineCatch(n, parent);
      break;

    case Token.VAR:
      defineVar(n, parent);
      break;

    case Token.GETPROP:
      // Handle stubbed properties.
      if (parent.isExprResult() &&
          n.isQualifiedName()) {
        maybeDeclareQualifiedName(t, n.getJSDocInfo(), n, parent, null);
      }
      break;
  }

  // Analyze any @lends object literals in this statement.
}
 
Example 17
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 18
Source File: Closure_54_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  inputId = t.getInputId();
  attachLiteralTypes(t, n);

  switch (n.getType()) {
    case Token.CALL:
      checkForClassDefiningCalls(t, n, parent);
      checkForCallingConventionDefiningCalls(n, delegateCallingConventions);
      break;

    case Token.FUNCTION:
      if (t.getInput() == null || !t.getInput().isExtern()) {
        nonExternFunctions.add(n);
      }

      // Hoisted functions are handled during pre-traversal.
      if (!NodeUtil.isHoistedFunctionDeclaration(n)) {
        defineFunctionLiteral(n, parent);
      }
      break;

    case Token.ASSIGN:
      // Handle initialization of properties.
      Node firstChild = n.getFirstChild();
      if (firstChild.getType() == Token.GETPROP &&
          firstChild.isQualifiedName()) {
        maybeDeclareQualifiedName(t, n.getJSDocInfo(),
            firstChild, n, firstChild.getNext());
      }
      break;

    case Token.CATCH:
      defineCatch(n, parent);
      break;

    case Token.VAR:
      defineVar(n, parent);
      break;

    case Token.GETPROP:
      // Handle stubbed properties.
      if (parent.getType() == Token.EXPR_RESULT &&
          n.isQualifiedName()) {
        maybeDeclareQualifiedName(t, n.getJSDocInfo(), n, parent, null);
      }
      break;
  }
}
 
Example 19
Source File: Closure_94_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @return Whether BLOCK (from a TRY node) contains a CATCH.
 * @see NodeUtil#getCatchBlock
 */
static boolean hasCatchHandler(Node n) {
  Preconditions.checkArgument(n.getType() == Token.BLOCK);
  return n.hasChildren() && n.getFirstChild().getType() == Token.CATCH;
}
 
Example 20
Source File: 1_NodeUtil.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return Whether BLOCK (from a TRY node) contains a CATCH.
 * @see NodeUtil#getCatchBlock
 */
static boolean hasCatchHandler(Node n) {
  Preconditions.checkArgument(n.getType() == Token.BLOCK);
  return n.hasChildren() && n.getFirstChild().getType() == Token.CATCH;
}