OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart2js.diagnostic_listener; | 5 library dart2js.diagnostic_listener; |
6 | 6 |
| 7 import '../options.dart' show |
| 8 DiagnosticOptions; |
7 import 'source_span.dart' show | 9 import 'source_span.dart' show |
8 SourceSpan; | 10 SourceSpan; |
9 import 'spannable.dart' show | 11 import 'spannable.dart' show |
10 Spannable; | 12 Spannable; |
11 import '../elements/elements.dart' show | 13 import '../elements/elements.dart' show |
12 Element; | 14 Element; |
13 import 'messages.dart'; | 15 import 'messages.dart'; |
14 | 16 |
15 class DiagnosticOptions { | |
16 /// Emit terse diagnostics without howToFix. | |
17 final bool terseDiagnostics; | |
18 | |
19 /// List of packages for which warnings and hints are reported. If `null`, | |
20 /// no package warnings or hints are reported. If empty, all warnings and | |
21 /// hints are reported. | |
22 final List<String> _shownPackageWarnings; | |
23 | |
24 /// If `true`, warnings are not reported. | |
25 final bool suppressWarnings; | |
26 | |
27 /// If `true`, warnings cause the compilation to fail. | |
28 final bool fatalWarnings; | |
29 | |
30 /// If `true`, hints are not reported. | |
31 final bool suppressHints; | |
32 | |
33 const DiagnosticOptions({ | |
34 this.suppressWarnings: false, | |
35 this.fatalWarnings: false, | |
36 this.suppressHints: false, | |
37 this.terseDiagnostics: false, | |
38 List<String> shownPackageWarnings: null}) | |
39 : _shownPackageWarnings = shownPackageWarnings; | |
40 | |
41 | |
42 /// Returns `true` if warnings and hints are shown for all packages. | |
43 bool get showAllPackageWarnings { | |
44 return _shownPackageWarnings != null && _shownPackageWarnings.isEmpty; | |
45 } | |
46 | |
47 /// Returns `true` if warnings and hints are hidden for all packages. | |
48 bool get hidePackageWarnings => _shownPackageWarnings == null; | |
49 | |
50 /// Returns `true` if warnings should be should for [uri]. | |
51 bool showPackageWarningsFor(Uri uri) { | |
52 if (showAllPackageWarnings) { | |
53 return true; | |
54 } | |
55 if (_shownPackageWarnings != null) { | |
56 return uri.scheme == 'package' && | |
57 _shownPackageWarnings.contains(uri.pathSegments.first); | |
58 } | |
59 return false; | |
60 } | |
61 } | |
62 | |
63 // TODO(johnniwinther): Rename and cleanup this interface. Add severity enum. | 17 // TODO(johnniwinther): Rename and cleanup this interface. Add severity enum. |
64 abstract class DiagnosticReporter { | 18 abstract class DiagnosticReporter { |
65 DiagnosticOptions get options => const DiagnosticOptions(); | 19 DiagnosticOptions get options; |
66 | 20 |
67 // TODO(karlklose): rename log to something like reportInfo. | 21 // TODO(karlklose): rename log to something like reportInfo. |
68 void log(message); | 22 void log(message); |
69 | 23 |
70 internalError(Spannable spannable, message); | 24 internalError(Spannable spannable, message); |
71 | 25 |
72 /// Creates a [SourceSpan] for [node] in scope of the current element. | 26 /// Creates a [SourceSpan] for [node] in scope of the current element. |
73 /// | 27 /// |
74 /// If [node] is a [Node] or [Token] we assert in checked mode that the | 28 /// If [node] is a [Node] or [Token] we assert in checked mode that the |
75 /// corresponding tokens can be found within the tokens of the current | 29 /// corresponding tokens can be found within the tokens of the current |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 [Map arguments = const {}]); | 78 [Map arguments = const {}]); |
125 } | 79 } |
126 | 80 |
127 class DiagnosticMessage { | 81 class DiagnosticMessage { |
128 final SourceSpan sourceSpan; | 82 final SourceSpan sourceSpan; |
129 final Spannable spannable; | 83 final Spannable spannable; |
130 final Message message; | 84 final Message message; |
131 | 85 |
132 DiagnosticMessage(this.sourceSpan, this.spannable, this.message); | 86 DiagnosticMessage(this.sourceSpan, this.spannable, this.message); |
133 } | 87 } |
OLD | NEW |