| 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 'package:analyzer/src/generated/ast.dart' show AstNode; | 9 import 'package:analyzer/src/generated/ast.dart' show AstNode; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 : super(name, message, correction); | 2469 : super(name, message, correction); |
| 2470 | 2470 |
| 2471 @override | 2471 @override |
| 2472 ErrorSeverity get errorSeverity => ErrorType.COMPILE_TIME_ERROR.severity; | 2472 ErrorSeverity get errorSeverity => ErrorType.COMPILE_TIME_ERROR.severity; |
| 2473 | 2473 |
| 2474 @override | 2474 @override |
| 2475 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; | 2475 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; |
| 2476 } | 2476 } |
| 2477 | 2477 |
| 2478 /** | 2478 /** |
| 2479 * An error listener that can be enabled or disabled while executing a function. | |
| 2480 */ | |
| 2481 class DisablableErrorListener implements AnalysisErrorListener { | |
| 2482 /** | |
| 2483 * The listener to which errors will be reported if this listener is enabled. | |
| 2484 */ | |
| 2485 final AnalysisErrorListener baseListener; | |
| 2486 | |
| 2487 /** | |
| 2488 * A flag indicating whether this listener is currently enabled. | |
| 2489 */ | |
| 2490 bool enabled = true; | |
| 2491 | |
| 2492 /** | |
| 2493 * Initialize a newly created listener to report errors to the given | |
| 2494 * [baseListener]. | |
| 2495 */ | |
| 2496 DisablableErrorListener(this.baseListener); | |
| 2497 | |
| 2498 /** | |
| 2499 * Disable the processing of errors while evaluating the given [function]. | |
| 2500 * Return the value returned by the function. | |
| 2501 */ | |
| 2502 dynamic disableWhile(dynamic function()) { | |
| 2503 bool wasEnabled = enabled; | |
| 2504 try { | |
| 2505 enabled = false; | |
| 2506 return function(); | |
| 2507 } finally { | |
| 2508 enabled = wasEnabled; | |
| 2509 } | |
| 2510 } | |
| 2511 | |
| 2512 /** | |
| 2513 * Disable the processing of errors while evaluating the given [function]. | |
| 2514 * Return the value returned by the function. | |
| 2515 */ | |
| 2516 dynamic enableWhile(dynamic function()) { | |
| 2517 bool wasEnabled = enabled; | |
| 2518 try { | |
| 2519 enabled = true; | |
| 2520 return function(); | |
| 2521 } finally { | |
| 2522 enabled = wasEnabled; | |
| 2523 } | |
| 2524 } | |
| 2525 | |
| 2526 @override | |
| 2527 void onError(AnalysisError error) { | |
| 2528 if (enabled) { | |
| 2529 baseListener.onError(error); | |
| 2530 } | |
| 2531 } | |
| 2532 } | |
| 2533 | |
| 2534 /** | |
| 2535 * An error code associated with an [AnalysisError]. | 2479 * An error code associated with an [AnalysisError]. |
| 2536 * | 2480 * |
| 2537 * Generally, we want to provide messages that consist of three sentences. From | 2481 * Generally, we want to provide messages that consist of three sentences. From |
| 2538 * the user's perspective these sentences should explain: | 2482 * the user's perspective these sentences should explain: |
| 2539 * 1. what is wrong, | 2483 * 1. what is wrong, |
| 2540 * 2. why is it wrong, and | 2484 * 2. why is it wrong, and |
| 2541 * 3. how do I fix it. | 2485 * 3. how do I fix it. |
| 2542 * However, we combine the first two in the [message] and the last in the | 2486 * However, we combine the first two in the [message] and the last in the |
| 2543 * [correction]. | 2487 * [correction]. |
| 2544 */ | 2488 */ |
| (...skipping 3128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5673 * Initialize a newly created error code to have the given [name]. | 5617 * Initialize a newly created error code to have the given [name]. |
| 5674 */ | 5618 */ |
| 5675 const TodoCode(String name) : super(name, "{0}"); | 5619 const TodoCode(String name) : super(name, "{0}"); |
| 5676 | 5620 |
| 5677 @override | 5621 @override |
| 5678 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; | 5622 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; |
| 5679 | 5623 |
| 5680 @override | 5624 @override |
| 5681 ErrorType get type => ErrorType.TODO; | 5625 ErrorType get type => ErrorType.TODO; |
| 5682 } | 5626 } |
| OLD | NEW |