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
|
3 | | // BSD-style license that can be found in the LICENSE file.
|
4 | |
|
5 | | library dart_style.src.error_listener;
|
6 | |
|
7 | | import 'package:analyzer/error/error.dart';
|
8 | | import 'package:analyzer/error/listener.dart';
|
9 | |
|
10 | | import 'exceptions.dart';
|
11 | |
|
12 | | /// A simple [AnalysisErrorListener] that just collects the reported errors.
|
13 | | class ErrorListener implements AnalysisErrorListener {
|
14 | | final _errors = <AnalysisError>[];
|
15 | |
|
16 | 1 | void onError(AnalysisError error) {
|
17 | | // Fasta produces some semantic errors, which we want to ignore so that
|
18 | | // users can format code containing static errors.
|
19 | 3 | if (error.errorCode.type != ErrorType.SYNTACTIC_ERROR) return;
|
20 | |
|
21 | 2 | _errors.add(error);
|
22 | | }
|
23 | |
|
24 | | /// Throws a [FormatterException] if any errors have been reported.
|
25 | 3 | void throwIfErrors() {
|
26 | 6 | if (_errors.isEmpty) return;
|
27 | |
|
28 | 2 | throw new FormatterException(_errors);
|
29 | | }
|
30 | | }
|