Package com.google.dart.engine.ast

Examples of com.google.dart.engine.ast.CatchClause


    safelyVisit(node.getFinallyBlock());
    NodeList<CatchClause> catchClauses = node.getCatchClauses();
    int numOfCatchClauses = catchClauses.size();
    ArrayList<Type> visitedTypes = new ArrayList<Type>(numOfCatchClauses);
    for (int i = 0; i < numOfCatchClauses; i++) {
      CatchClause catchClause = catchClauses.get(i);
      if (catchClause.getOnKeyword() != null) {
        // on-catch clause found, verify that the exception type is not a subtype of a previous
        // on-catch exception type
        TypeName typeName = catchClause.getExceptionType();
        if (typeName != null && typeName.getType() != null) {
          Type currentType = typeName.getType();
          if (currentType.isObject()) {
            // Found catch clause clause that has Object as an exception type, this is equivalent to
            // having a catch clause that doesn't have an exception type, visit the block, but
            // generate an error on any following catch clauses (and don't visit them).
            safelyVisit(catchClause);
            if (i + 1 != numOfCatchClauses) {
              // this catch clause is not the last in the try statement
              CatchClause nextCatchClause = catchClauses.get(i + 1);
              CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
              int offset = nextCatchClause.getOffset();
              int length = lastCatchClause.getEnd() - offset;
              errorReporter.reportErrorForOffset(
                  HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
                  offset,
                  length);
              return null;
            }
          }
          for (Type type : visitedTypes) {
            if (currentType.isSubtypeOf(type)) {
              CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
              int offset = catchClause.getOffset();
              int length = lastCatchClause.getEnd() - offset;
              errorReporter.reportErrorForOffset(
                  HintCode.DEAD_CODE_ON_CATCH_SUBTYPE,
                  offset,
                  length,
                  currentType.getDisplayName(),
                  type.getDisplayName());
              return null;
            }
          }
          visitedTypes.add(currentType);
        }
        safelyVisit(catchClause);
      } else {
        // Found catch clause clause that doesn't have an exception type, visit the block, but
        // generate an error on any following catch clauses (and don't visit them).
        safelyVisit(catchClause);
        if (i + 1 != numOfCatchClauses) {
          // this catch clause is not the last in the try statement
          CatchClause nextCatchClause = catchClauses.get(i + 1);
          CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
          int offset = nextCatchClause.getOffset();
          int length = lastCatchClause.getEnd() - offset;
          errorReporter.reportErrorForOffset(
              HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
              offset,
              length);
          return null;
View Full Code Here


   * @return {@code true} if the given type name is used as the exception type in a catch clause
   */
  private boolean isTypeNameInCatchClause(TypeName typeName) {
    AstNode parent = typeName.getParent();
    if (parent instanceof CatchClause) {
      CatchClause catchClause = (CatchClause) parent;
      return catchClause.getExceptionType() == typeName;
    }
    return false;
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.ast.CatchClause

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.