| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; | 6 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; |
| 7 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; | 7 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; |
| 8 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; | 8 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; |
| 9 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; | 9 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; |
| 10 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; | 10 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; |
| 11 import "mock_compiler.dart"; | 11 import "mock_compiler.dart"; |
| 12 import "parser_helper.dart"; | 12 import "parser_helper.dart"; |
| 13 | 13 |
| 14 class CallbackMockCompiler extends MockCompiler { | 14 class CallbackMockCompiler extends MockCompiler { |
| 15 CallbackMockCompiler(); | 15 CallbackMockCompiler(); |
| 16 | 16 |
| 17 var onError; | 17 var onError; |
| 18 var onWarning; | 18 var onWarning; |
| 19 | 19 |
| 20 setOnError(var f) => onError = f; | 20 setOnError(var f) => onError = f; |
| 21 setOnWarning(var f) => onWarning = f; | 21 setOnWarning(var f) => onWarning = f; |
| 22 | 22 |
| 23 void reportWarning(Node node, var message) { | 23 void reportWarning(Spannable node, |
| 24 if (onWarning != null) onWarning(this, node, message); | 24 MessageKind errorCode, |
| 25 super.reportWarning(node, message); | 25 [Map arguments = const {}]) { |
| 26 if (onWarning != null) onWarning(this, node, errorCode.error(arguments)); |
| 27 super.reportWarning(node, errorCode, arguments); |
| 26 } | 28 } |
| 27 | 29 |
| 28 void reportError(Spannable node, | 30 void reportError(Spannable node, |
| 29 MessageKind errorCode, | 31 MessageKind errorCode, |
| 30 [Map arguments = const {}]) { | 32 [Map arguments = const {}]) { |
| 31 if (onError != null) onError(this, node, errorCode.error(arguments)); | 33 if (onError != null) onError(this, node, errorCode.error(arguments)); |
| 32 super.reportError(node, errorCode, arguments); | 34 super.reportError(node, errorCode, arguments); |
| 33 } | 35 } |
| 34 } | 36 } |
| 35 | 37 |
| 36 testErrorHandling() { | 38 testErrorHandling() { |
| 37 // Test that compiler.currentElement is set correctly when | 39 // Test that compiler.currentElement is set correctly when |
| 38 // reporting errors/warnings. | 40 // reporting errors/warnings. |
| 39 CallbackMockCompiler compiler = new CallbackMockCompiler(); | 41 CallbackMockCompiler compiler = new CallbackMockCompiler(); |
| 40 ResolverVisitor visitor = compiler.resolverVisitor(); | 42 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 41 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}'); | 43 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}'); |
| 42 FunctionElement foo = compiler.mainApp.find('foo'); | 44 FunctionElement foo = compiler.mainApp.find('foo'); |
| 43 compiler.setOnWarning( | 45 compiler.setOnWarning( |
| 44 (c, n, m) => Expect.equals(foo, compiler.currentElement)); | 46 (c, n, m) => Expect.equals(foo, compiler.currentElement)); |
| 45 foo.computeType(compiler); | 47 foo.computeType(compiler); |
| 46 Expect.equals(1, compiler.warnings.length); | 48 Expect.equals(1, compiler.warnings.length); |
| 47 } | 49 } |
| 48 | 50 |
| 49 main() { | 51 main() { |
| 50 testErrorHandling(); | 52 testErrorHandling(); |
| 51 } | 53 } |
| OLD | NEW |