| 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 var script = new Script(uri, new MockFile(source)); | 332 var script = new Script(uri, new MockFile(source)); |
| 333 var library = new LibraryElementX(script); | 333 var library = new LibraryElementX(script); |
| 334 library.libraryTag = new LibraryName(null, null, null); | 334 library.libraryTag = new LibraryName(null, null, null); |
| 335 parseScript(source, library); | 335 parseScript(source, library); |
| 336 library.setExports(library.localScope.values.toList()); | 336 library.setExports(library.localScope.values.toList()); |
| 337 registerSource(uri, source); | 337 registerSource(uri, source); |
| 338 libraries.putIfAbsent(uri.toString(), () => library); | 338 libraries.putIfAbsent(uri.toString(), () => library); |
| 339 return library; | 339 return library; |
| 340 } | 340 } |
| 341 | 341 |
| 342 void reportWarning(Spannable node, var message) { | 342 // TODO(johnniwinther): Remove this when we don't filter certain type checker |
| 343 if (message is! Message) message = message.message; | 343 // warnings. |
| 344 warnings.add(new WarningMessage(node, message)); | 344 void reportWarning(Spannable node, MessageKind errorCode, |
| 345 reportDiagnostic(spanFromSpannable(node), | 345 [Map arguments = const {}]) { |
| 346 'Warning: $message', api.Diagnostic.WARNING); | 346 reportDiagnostic(node, |
| 347 } | 347 errorCode.error(arguments, terseDiagnostics), |
| 348 | 348 api.Diagnostic.WARNING); |
| 349 void reportError(Spannable node, | |
| 350 MessageKind errorCode, | |
| 351 [Map arguments = const {}]) { | |
| 352 Message message = errorCode.message(arguments); | |
| 353 errors.add(new WarningMessage(node, message)); | |
| 354 reportDiagnostic(spanFromSpannable(node), '$message', api.Diagnostic.ERROR); | |
| 355 } | |
| 356 | |
| 357 void reportInfo(Spannable node, | |
| 358 MessageKind errorCode, | |
| 359 [Map arguments = const {}]) { | |
| 360 Message message = errorCode.message(arguments); | |
| 361 infos.add(new WarningMessage(node, message)); | |
| 362 reportDiagnostic(spanFromSpannable(node), '$message', api.Diagnostic.INFO); | |
| 363 } | |
| 364 | |
| 365 void reportHint(Spannable node, | |
| 366 MessageKind errorCode, | |
| 367 [Map arguments = const {}]) { | |
| 368 Message message = errorCode.message(arguments); | |
| 369 hints.add(new WarningMessage(node, message)); | |
| 370 reportDiagnostic(spanFromSpannable(node), '$message', api.Diagnostic.HINT); | |
| 371 } | 349 } |
| 372 | 350 |
| 373 void reportFatalError(Spannable node, | 351 void reportFatalError(Spannable node, |
| 374 MessageKind errorCode, | 352 MessageKind errorCode, |
| 375 [Map arguments = const {}]) { | 353 [Map arguments = const {}]) { |
| 376 reportError(node, errorCode, arguments); | 354 reportError(node, errorCode, arguments); |
| 377 } | 355 } |
| 378 | 356 |
| 379 void reportMessage(SourceSpan span, var message, api.Diagnostic kind) { | 357 void reportDiagnostic(Spannable node, |
| 380 var diagnostic = new WarningMessage(null, message.message); | 358 Diagnostic message, |
| 359 api.Diagnostic kind) { |
| 360 var diagnostic = new WarningMessage(node, message.message); |
| 381 if (kind == api.Diagnostic.ERROR) { | 361 if (kind == api.Diagnostic.ERROR) { |
| 382 errors.add(diagnostic); | 362 errors.add(diagnostic); |
| 383 } else if (kind == api.Diagnostic.WARNING) { | 363 } else if (kind == api.Diagnostic.WARNING) { |
| 384 warnings.add(diagnostic); | 364 warnings.add(diagnostic); |
| 385 } else if (kind == api.Diagnostic.INFO) { | 365 } else if (kind == api.Diagnostic.INFO) { |
| 386 infos.add(diagnostic); | 366 infos.add(diagnostic); |
| 387 } else if (kind == api.Diagnostic.HINT) { | 367 } else if (kind == api.Diagnostic.HINT) { |
| 388 hints.add(diagnostic); | 368 hints.add(diagnostic); |
| 389 } | 369 } |
| 390 reportDiagnostic(span, "$message", kind); | |
| 391 } | |
| 392 | |
| 393 void reportDiagnostic(SourceSpan span, String message, api.Diagnostic kind) { | |
| 394 if (diagnosticHandler != null) { | 370 if (diagnosticHandler != null) { |
| 371 SourceSpan span = spanFromSpannable(node); |
| 395 if (span != null) { | 372 if (span != null) { |
| 396 diagnosticHandler(span.uri, span.begin, span.end, message, kind); | 373 diagnosticHandler(span.uri, span.begin, span.end, '$message', kind); |
| 397 } else { | 374 } else { |
| 398 diagnosticHandler(null, null, null, message, kind); | 375 diagnosticHandler(null, null, null, '$message', kind); |
| 399 } | 376 } |
| 400 } | 377 } |
| 401 } | 378 } |
| 402 | 379 |
| 403 bool get compilationFailed => !errors.isEmpty; | 380 bool get compilationFailed => !errors.isEmpty; |
| 404 | 381 |
| 405 void clearMessages() { | 382 void clearMessages() { |
| 406 warnings = []; | 383 warnings = []; |
| 407 errors = []; | 384 errors = []; |
| 408 hints = []; | 385 hints = []; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 } else { | 565 } else { |
| 589 sourceFile = compiler.sourceFiles[uri.toString()]; | 566 sourceFile = compiler.sourceFiles[uri.toString()]; |
| 590 } | 567 } |
| 591 if (sourceFile != null && begin != null && end != null) { | 568 if (sourceFile != null && begin != null && end != null) { |
| 592 print(sourceFile.getLocationMessage(message, begin, end, true, (x) => x)); | 569 print(sourceFile.getLocationMessage(message, begin, end, true, (x) => x)); |
| 593 } else { | 570 } else { |
| 594 print(message); | 571 print(message); |
| 595 } | 572 } |
| 596 }; | 573 }; |
| 597 } | 574 } |
| OLD | NEW |