| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:compiler/compiler.dart' as api; | 10 import 'package:compiler/compiler.dart' as api; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 /// Initialize the mock compiler with an empty main library. | 142 /// Initialize the mock compiler with an empty main library. |
| 143 Future<Uri> init([String mainSource = ""]) { | 143 Future<Uri> init([String mainSource = ""]) { |
| 144 Uri uri = new Uri(scheme: "mock"); | 144 Uri uri = new Uri(scheme: "mock"); |
| 145 registerSource(uri, mainSource); | 145 registerSource(uri, mainSource); |
| 146 return libraryLoader.loadLibrary(uri).then((LibraryElement library) { | 146 return libraryLoader.loadLibrary(uri).then((LibraryElement library) { |
| 147 mainApp = library; | 147 mainApp = library; |
| 148 // We need to make sure the Object class is resolved. When registering a | 148 // We need to make sure the Object class is resolved. When registering a |
| 149 // dynamic invocation the ArgumentTypesRegistry eventually iterates over | 149 // dynamic invocation the ArgumentTypesRegistry eventually iterates over |
| 150 // the interfaces of the Object class which would be 'null' if the class | 150 // the interfaces of the Object class which would be 'null' if the class |
| 151 // wasn't resolved. | 151 // wasn't resolved. |
| 152 commonElements.objectClass.ensureResolved(resolution); | 152 ClassElement objectClass = commonElements.objectClass; |
| 153 objectClass.ensureResolved(resolution); |
| 153 }).then((_) => uri); | 154 }).then((_) => uri); |
| 154 } | 155 } |
| 155 | 156 |
| 156 Future run(Uri uri, [String mainSource = ""]) { | 157 Future run(Uri uri, [String mainSource = ""]) { |
| 157 return init(mainSource).then((Uri mainUri) { | 158 return init(mainSource).then((Uri mainUri) { |
| 158 return super.run(uri == null ? mainUri : uri); | 159 return super.run(uri == null ? mainUri : uri); |
| 159 }).then((result) { | 160 }).then((result) { |
| 160 if (expectedErrors != null && | 161 if (expectedErrors != null && |
| 161 expectedErrors != diagnosticCollector.errors.length) { | 162 expectedErrors != diagnosticCollector.errors.length) { |
| 162 throw "unexpected error during compilation " | 163 throw "unexpected error during compilation " |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 trustTypeAnnotations: trustTypeAnnotations, | 392 trustTypeAnnotations: trustTypeAnnotations, |
| 392 enableTypeAssertions: enableTypeAssertions, | 393 enableTypeAssertions: enableTypeAssertions, |
| 393 enableUserAssertions: enableUserAssertions, | 394 enableUserAssertions: enableUserAssertions, |
| 394 expectedErrors: expectedErrors, | 395 expectedErrors: expectedErrors, |
| 395 expectedWarnings: expectedWarnings, | 396 expectedWarnings: expectedWarnings, |
| 396 outputProvider: outputProvider); | 397 outputProvider: outputProvider); |
| 397 compiler.registerSource(uri, code); | 398 compiler.registerSource(uri, code); |
| 398 compiler.diagnosticHandler = createHandler(compiler, code); | 399 compiler.diagnosticHandler = createHandler(compiler, code); |
| 399 return compiler; | 400 return compiler; |
| 400 } | 401 } |
| OLD | NEW |