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 mock_compiler; | 5 library mock_compiler; |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:collection'; | 9 import 'dart:collection'; |
10 | 10 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 String override = librariesOverride(uri); | 187 String override = librariesOverride(uri); |
188 if (override != null) { | 188 if (override != null) { |
189 source = override; | 189 source = override; |
190 } | 190 } |
191 } | 191 } |
192 sourceFiles[uri.toString()] = new MockFile(source); | 192 sourceFiles[uri.toString()] = new MockFile(source); |
193 } | 193 } |
194 | 194 |
195 // TODO(johnniwinther): Remove this when we don't filter certain type checker | 195 // TODO(johnniwinther): Remove this when we don't filter certain type checker |
196 // warnings. | 196 // warnings. |
197 void reportWarning(Spannable node, MessageKind messageKind, | 197 void reportWarning( |
198 [Map arguments = const {}]) { | 198 DiagnosticMessage message, |
199 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind]; | 199 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { |
200 reportDiagnostic(node, | 200 reportDiagnostic(message, infos, api.Diagnostic.WARNING); |
201 template.message(arguments, terseDiagnostics), | |
202 api.Diagnostic.WARNING); | |
203 } | 201 } |
204 | 202 |
205 void reportDiagnostic(Spannable node, | 203 void reportDiagnostic(DiagnosticMessage message, |
206 Message message, | 204 List<DiagnosticMessage> infoMessages, |
207 api.Diagnostic kind) { | 205 api.Diagnostic kind) { |
208 var diagnostic = new WarningMessage(node, message); | 206 |
209 if (kind == api.Diagnostic.CRASH) { | 207 void processMessage(DiagnosticMessage message, api.Diagnostic kind) { |
210 crashes.add(diagnostic); | 208 var diagnostic = new WarningMessage(message.spannable, message.message); |
211 } else if (kind == api.Diagnostic.ERROR) { | 209 if (kind == api.Diagnostic.CRASH) { |
212 errors.add(diagnostic); | 210 crashes.add(diagnostic); |
213 } else if (kind == api.Diagnostic.WARNING) { | 211 } else if (kind == api.Diagnostic.ERROR) { |
214 warnings.add(diagnostic); | 212 errors.add(diagnostic); |
215 } else if (kind == api.Diagnostic.INFO) { | 213 } else if (kind == api.Diagnostic.WARNING) { |
216 infos.add(diagnostic); | 214 warnings.add(diagnostic); |
217 } else if (kind == api.Diagnostic.HINT) { | 215 } else if (kind == api.Diagnostic.INFO) { |
218 hints.add(diagnostic); | 216 infos.add(diagnostic); |
219 } | 217 } else if (kind == api.Diagnostic.HINT) { |
220 if (diagnosticHandler != null) { | 218 hints.add(diagnostic); |
221 SourceSpan span = spanFromSpannable(node); | 219 } |
222 if (span != null) { | 220 if (diagnosticHandler != null) { |
223 diagnosticHandler(span.uri, span.begin, span.end, '$message', kind); | 221 SourceSpan span = message.sourceSpan; |
224 } else { | 222 if (span != null) { |
225 diagnosticHandler(null, null, null, '$message', kind); | 223 diagnosticHandler(span.uri, span.begin, span.end, '$message', kind); |
| 224 } else { |
| 225 diagnosticHandler(null, null, null, '$message', kind); |
| 226 } |
226 } | 227 } |
227 } | 228 } |
| 229 |
| 230 processMessage(message, kind); |
| 231 infoMessages.forEach((i) => processMessage(i, api.Diagnostic.INFO)); |
228 } | 232 } |
229 | 233 |
230 bool get compilationFailed => !crashes.isEmpty || !errors.isEmpty; | 234 bool get compilationFailed => !crashes.isEmpty || !errors.isEmpty; |
231 | 235 |
232 void clearMessages() { | 236 void clearMessages() { |
233 warnings = []; | 237 warnings = []; |
234 errors = []; | 238 errors = []; |
235 hints = []; | 239 hints = []; |
236 infos = []; | 240 infos = []; |
237 crashes = []; | 241 crashes = []; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 trustTypeAnnotations: trustTypeAnnotations, | 467 trustTypeAnnotations: trustTypeAnnotations, |
464 enableTypeAssertions: enableTypeAssertions, | 468 enableTypeAssertions: enableTypeAssertions, |
465 enableUserAssertions: enableUserAssertions, | 469 enableUserAssertions: enableUserAssertions, |
466 expectedErrors: expectedErrors, | 470 expectedErrors: expectedErrors, |
467 expectedWarnings: expectedWarnings, | 471 expectedWarnings: expectedWarnings, |
468 outputProvider: outputProvider); | 472 outputProvider: outputProvider); |
469 compiler.registerSource(uri, code); | 473 compiler.registerSource(uri, code); |
470 compiler.diagnosticHandler = createHandler(compiler, code); | 474 compiler.diagnosticHandler = createHandler(compiler, code); |
471 return compiler; | 475 return compiler; |
472 } | 476 } |
OLD | NEW |