| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library engine.error; | 5 library engine.error; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart' show AstNode; | 9 import 'ast.dart' show AstNode; |
| 10 import 'element.dart'; | 10 import 'element.dart'; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 /** | 21 /** |
| 22 * An empty array of errors used when no errors are expected. | 22 * An empty array of errors used when no errors are expected. |
| 23 */ | 23 */ |
| 24 static const List<AnalysisError> NO_ERRORS = const <AnalysisError>[]; | 24 static const List<AnalysisError> NO_ERRORS = const <AnalysisError>[]; |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * A [Comparator] that sorts by the name of the file that the [AnalysisError] | 27 * A [Comparator] that sorts by the name of the file that the [AnalysisError] |
| 28 * was found. | 28 * was found. |
| 29 */ | 29 */ |
| 30 static Comparator<AnalysisError> FILE_COMPARATOR = (AnalysisError o1, | 30 static Comparator<AnalysisError> FILE_COMPARATOR = (AnalysisError o1, |
| 31 AnalysisError o2) => o1.source.shortName.compareTo(o2.source.shortName); | 31 AnalysisError o2) => |
| 32 o1.source.shortName.compareTo(o2.source.shortName); |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * A [Comparator] that sorts error codes first by their severity (errors | 35 * A [Comparator] that sorts error codes first by their severity (errors |
| 35 * first, warnings second), and then by the the error code type. | 36 * first, warnings second), and then by the the error code type. |
| 36 */ | 37 */ |
| 37 static Comparator<AnalysisError> ERROR_CODE_COMPARATOR = (AnalysisError o1, | 38 static Comparator<AnalysisError> ERROR_CODE_COMPARATOR = |
| 38 AnalysisError o2) { | 39 (AnalysisError o1, AnalysisError o2) { |
| 39 ErrorCode errorCode1 = o1.errorCode; | 40 ErrorCode errorCode1 = o1.errorCode; |
| 40 ErrorCode errorCode2 = o2.errorCode; | 41 ErrorCode errorCode2 = o2.errorCode; |
| 41 ErrorSeverity errorSeverity1 = errorCode1.errorSeverity; | 42 ErrorSeverity errorSeverity1 = errorCode1.errorSeverity; |
| 42 ErrorSeverity errorSeverity2 = errorCode2.errorSeverity; | 43 ErrorSeverity errorSeverity2 = errorCode2.errorSeverity; |
| 43 if (errorSeverity1 == errorSeverity2) { | 44 if (errorSeverity1 == errorSeverity2) { |
| 44 ErrorType errorType1 = errorCode1.type; | 45 ErrorType errorType1 = errorCode1.type; |
| 45 ErrorType errorType2 = errorCode2.type; | 46 ErrorType errorType2 = errorCode2.type; |
| 46 return errorType1.compareTo(errorType2); | 47 return errorType1.compareTo(errorType2); |
| 47 } else { | 48 } else { |
| 48 return errorSeverity2.compareTo(errorSeverity1); | 49 return errorSeverity2.compareTo(errorSeverity1); |
| (...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 * * The static type of <i>e</i> is an enumerated typed with elements | 1554 * * The static type of <i>e</i> is an enumerated typed with elements |
| 1554 * <i>id<sub>1</sub></i>, …, <i>id<sub>n</sub></i>. | 1555 * <i>id<sub>1</sub></i>, …, <i>id<sub>n</sub></i>. |
| 1555 * * The sets {<i>e<sub>1</sub></i>, …, <i>e<sub>k</sub></i>} and | 1556 * * The sets {<i>e<sub>1</sub></i>, …, <i>e<sub>k</sub></i>} and |
| 1556 * {<i>id<sub>1</sub></i>, …, <i>id<sub>n</sub></i>} are not the | 1557 * {<i>id<sub>1</sub></i>, …, <i>id<sub>n</sub></i>} are not the |
| 1557 * same. | 1558 * same. |
| 1558 * | 1559 * |
| 1559 * Parameters: | 1560 * Parameters: |
| 1560 * 0: the name of the constant that is missing | 1561 * 0: the name of the constant that is missing |
| 1561 */ | 1562 */ |
| 1562 static const CompileTimeErrorCode MISSING_ENUM_CONSTANT_IN_SWITCH = | 1563 static const CompileTimeErrorCode MISSING_ENUM_CONSTANT_IN_SWITCH = |
| 1563 const CompileTimeErrorCode('MISSING_ENUM_CONSTANT_IN_SWITCH', | 1564 const CompileTimeErrorCode( |
| 1565 'MISSING_ENUM_CONSTANT_IN_SWITCH', |
| 1564 "Missing case clause for '{0}'", | 1566 "Missing case clause for '{0}'", |
| 1565 "Add a case clause for the missing constant or add a default clause.")
; | 1567 "Add a case clause for the missing constant or add a default clause.")
; |
| 1566 | 1568 |
| 1567 /** | 1569 /** |
| 1568 * 9 Mixins: It is a compile-time error if a declared or derived mixin | 1570 * 9 Mixins: It is a compile-time error if a declared or derived mixin |
| 1569 * explicitly declares a constructor. | 1571 * explicitly declares a constructor. |
| 1570 * | 1572 * |
| 1571 * Parameters: | 1573 * Parameters: |
| 1572 * 0: the name of the mixin that is invalid | 1574 * 0: the name of the mixin that is invalid |
| 1573 */ | 1575 */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1589 "This class cannot mixin the deferred class '{0}'"); | 1591 "This class cannot mixin the deferred class '{0}'"); |
| 1590 | 1592 |
| 1591 /** | 1593 /** |
| 1592 * Not yet in the spec, but consistent with VM behavior. It is a | 1594 * Not yet in the spec, but consistent with VM behavior. It is a |
| 1593 * compile-time error if all of the constructors of a mixin's base class have | 1595 * compile-time error if all of the constructors of a mixin's base class have |
| 1594 * at least one optional parameter (since only constructors that lack | 1596 * at least one optional parameter (since only constructors that lack |
| 1595 * optional parameters can be forwarded to the mixin). See | 1597 * optional parameters can be forwarded to the mixin). See |
| 1596 * https://code.google.com/p/dart/issues/detail?id=15101#c4 | 1598 * https://code.google.com/p/dart/issues/detail?id=15101#c4 |
| 1597 */ | 1599 */ |
| 1598 static const CompileTimeErrorCode MIXIN_HAS_NO_CONSTRUCTORS = | 1600 static const CompileTimeErrorCode MIXIN_HAS_NO_CONSTRUCTORS = |
| 1599 const CompileTimeErrorCode('MIXIN_HAS_NO_CONSTRUCTORS', | 1601 const CompileTimeErrorCode( |
| 1602 'MIXIN_HAS_NO_CONSTRUCTORS', |
| 1600 "This mixin application is invalid because all of the constructors " | 1603 "This mixin application is invalid because all of the constructors " |
| 1601 "in the base class '{0}' have optional parameters."); | 1604 "in the base class '{0}' have optional parameters."); |
| 1602 | 1605 |
| 1603 /** | 1606 /** |
| 1604 * 9 Mixins: It is a compile-time error if a mixin is derived from a class | 1607 * 9 Mixins: It is a compile-time error if a mixin is derived from a class |
| 1605 * whose superclass is not Object. | 1608 * whose superclass is not Object. |
| 1606 * | 1609 * |
| 1607 * Parameters: | 1610 * Parameters: |
| 1608 * 0: the name of the mixin that is invalid | 1611 * 0: the name of the mixin that is invalid |
| 1609 */ | 1612 */ |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2346 : super(name, message, correction); | 2349 : super(name, message, correction); |
| 2347 | 2350 |
| 2348 @override | 2351 @override |
| 2349 ErrorSeverity get errorSeverity => ErrorType.COMPILE_TIME_ERROR.severity; | 2352 ErrorSeverity get errorSeverity => ErrorType.COMPILE_TIME_ERROR.severity; |
| 2350 | 2353 |
| 2351 @override | 2354 @override |
| 2352 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; | 2355 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; |
| 2353 } | 2356 } |
| 2354 | 2357 |
| 2355 /** | 2358 /** |
| 2359 * An error listener that can be enabled or disabled while executing a function. |
| 2360 */ |
| 2361 class DisablableErrorListener implements AnalysisErrorListener { |
| 2362 /** |
| 2363 * The listener to which errors will be reported if this listener is enabled. |
| 2364 */ |
| 2365 final AnalysisErrorListener baseListener; |
| 2366 |
| 2367 /** |
| 2368 * A flag indicating whether this listener is currently enabled. |
| 2369 */ |
| 2370 bool enabled = true; |
| 2371 |
| 2372 /** |
| 2373 * Initialize a newly created listener to report errors to the given |
| 2374 * [baseListener]. |
| 2375 */ |
| 2376 DisablableErrorListener(this.baseListener); |
| 2377 |
| 2378 /** |
| 2379 * Disable the processing of errors while evaluating the given [function]. |
| 2380 * Return the value returned by the function. |
| 2381 */ |
| 2382 dynamic disableWhile(dynamic function()) { |
| 2383 bool wasEnabled = enabled; |
| 2384 try { |
| 2385 enabled = false; |
| 2386 return function(); |
| 2387 } finally { |
| 2388 enabled = wasEnabled; |
| 2389 } |
| 2390 } |
| 2391 |
| 2392 /** |
| 2393 * Disable the processing of errors while evaluating the given [function]. |
| 2394 * Return the value returned by the function. |
| 2395 */ |
| 2396 dynamic enableWhile(dynamic function()) { |
| 2397 bool wasEnabled = enabled; |
| 2398 try { |
| 2399 enabled = true; |
| 2400 return function(); |
| 2401 } finally { |
| 2402 enabled = wasEnabled; |
| 2403 } |
| 2404 } |
| 2405 |
| 2406 @override |
| 2407 void onError(AnalysisError error) { |
| 2408 if (enabled) { |
| 2409 baseListener.onError(error); |
| 2410 } |
| 2411 } |
| 2412 } |
| 2413 |
| 2414 /** |
| 2356 * An error code associated with an [AnalysisError]. | 2415 * An error code associated with an [AnalysisError]. |
| 2357 * | 2416 * |
| 2358 * Generally, we want to provide messages that consist of three sentences. From | 2417 * Generally, we want to provide messages that consist of three sentences. From |
| 2359 * the user's perspective these sentences should explain: | 2418 * the user's perspective these sentences should explain: |
| 2360 * 1. what is wrong, | 2419 * 1. what is wrong, |
| 2361 * 2. why is it wrong, and | 2420 * 2. why is it wrong, and |
| 2362 * 3. how do I fix it. | 2421 * 3. how do I fix it. |
| 2363 * However, we combine the first two in the [message] and the last in the | 2422 * However, we combine the first two in the [message] and the last in the |
| 2364 * [correction]. | 2423 * [correction]. |
| 2365 */ | 2424 */ |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2878 | 2937 |
| 2879 /** | 2938 /** |
| 2880 * Generate a hint for methods or functions that have a return type, but do | 2939 * Generate a hint for methods or functions that have a return type, but do |
| 2881 * not have a non-void return statement on all branches. At the end of methods | 2940 * not have a non-void return statement on all branches. At the end of methods |
| 2882 * or functions with no return, Dart implicitly returns `null`, avoiding these | 2941 * or functions with no return, Dart implicitly returns `null`, avoiding these |
| 2883 * implicit returns is considered a best practice. | 2942 * implicit returns is considered a best practice. |
| 2884 * | 2943 * |
| 2885 * Parameters: | 2944 * Parameters: |
| 2886 * 0: the name of the declared return type | 2945 * 0: the name of the declared return type |
| 2887 */ | 2946 */ |
| 2888 static const HintCode MISSING_RETURN = const HintCode('MISSING_RETURN', | 2947 static const HintCode MISSING_RETURN = const HintCode( |
| 2948 'MISSING_RETURN', |
| 2889 "This function declares a return type of '{0}', but does not end with a re
turn statement", | 2949 "This function declares a return type of '{0}', but does not end with a re
turn statement", |
| 2890 "Either add a return statement or change the return type to 'void'"); | 2950 "Either add a return statement or change the return type to 'void'"); |
| 2891 | 2951 |
| 2892 /** | 2952 /** |
| 2893 * A getter with the override annotation does not override an existing getter. | 2953 * A getter with the override annotation does not override an existing getter. |
| 2894 */ | 2954 */ |
| 2895 static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode( | 2955 static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode( |
| 2896 'OVERRIDE_ON_NON_OVERRIDING_GETTER', | 2956 'OVERRIDE_ON_NON_OVERRIDING_GETTER', |
| 2897 "Getter does not override an inherited getter"); | 2957 "Getter does not override an inherited getter"); |
| 2898 | 2958 |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3721 * 2. If <i>N</i> is referenced as a function, getter or setter, a | 3781 * 2. If <i>N</i> is referenced as a function, getter or setter, a |
| 3722 * <i>NoSuchMethodError</i> is raised. | 3782 * <i>NoSuchMethodError</i> is raised. |
| 3723 * 3. If <i>N</i> is referenced as a type, it is treated as a malformed type. | 3783 * 3. If <i>N</i> is referenced as a type, it is treated as a malformed type. |
| 3724 * | 3784 * |
| 3725 * Parameters: | 3785 * Parameters: |
| 3726 * 0: the name of the ambiguous type | 3786 * 0: the name of the ambiguous type |
| 3727 * 1: the name of the first library that the type is found | 3787 * 1: the name of the first library that the type is found |
| 3728 * 2: the name of the second library that the type is found | 3788 * 2: the name of the second library that the type is found |
| 3729 */ | 3789 */ |
| 3730 static const StaticWarningCode AMBIGUOUS_IMPORT = const StaticWarningCode( | 3790 static const StaticWarningCode AMBIGUOUS_IMPORT = const StaticWarningCode( |
| 3731 'AMBIGUOUS_IMPORT', "The name '{0}' is defined in the libraries {1}", | 3791 'AMBIGUOUS_IMPORT', |
| 3792 "The name '{0}' is defined in the libraries {1}", |
| 3732 "Consider using 'as prefix' for one of the import directives " | 3793 "Consider using 'as prefix' for one of the import directives " |
| 3733 "or hiding the name from all but one of the imports."); | 3794 "or hiding the name from all but one of the imports."); |
| 3734 | 3795 |
| 3735 /** | 3796 /** |
| 3736 * 12.11.1 New: It is a static warning if the static type of <i>a<sub>i</sub>, | 3797 * 12.11.1 New: It is a static warning if the static type of <i>a<sub>i</sub>, |
| 3737 * 1 <= i <= n+ k</i> may not be assigned to the type of the | 3798 * 1 <= i <= n+ k</i> may not be assigned to the type of the |
| 3738 * corresponding formal parameter of the constructor <i>T.id</i> (respectively | 3799 * corresponding formal parameter of the constructor <i>T.id</i> (respectively |
| 3739 * <i>T</i>). | 3800 * <i>T</i>). |
| 3740 * | 3801 * |
| 3741 * 12.11.2 Const: It is a static warning if the static type of | 3802 * 12.11.2 Const: It is a static warning if the static type of |
| (...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4938 * Initialize a newly created error code to have the given [name]. | 4999 * Initialize a newly created error code to have the given [name]. |
| 4939 */ | 5000 */ |
| 4940 const TodoCode(String name) : super(name, "{0}"); | 5001 const TodoCode(String name) : super(name, "{0}"); |
| 4941 | 5002 |
| 4942 @override | 5003 @override |
| 4943 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; | 5004 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; |
| 4944 | 5005 |
| 4945 @override | 5006 @override |
| 4946 ErrorType get type => ErrorType.TODO; | 5007 ErrorType get type => ErrorType.TODO; |
| 4947 } | 5008 } |
| OLD | NEW |