| 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:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:uri'; | |
| 10 | 9 |
| 11 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; | 10 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
| 12 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; | 11 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; |
| 13 import '../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart'; | 12 import '../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart'; |
| 14 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; | 13 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; |
| 15 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; | 14 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; |
| 16 import '../../../sdk/lib/_internal/compiler/implementation/util/util.dart'; | 15 import '../../../sdk/lib/_internal/compiler/implementation/util/util.dart'; |
| 17 import 'parser_helper.dart'; | 16 import 'parser_helper.dart'; |
| 18 | 17 |
| 19 import '../../../sdk/lib/_internal/compiler/implementation/elements/modelx.dart' | 18 import '../../../sdk/lib/_internal/compiler/implementation/elements/modelx.dart' |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 */ | 236 */ |
| 238 void registerSource(Uri uri, String source) { | 237 void registerSource(Uri uri, String source) { |
| 239 sourceFiles[uri.toString()] = new MockFile(source); | 238 sourceFiles[uri.toString()] = new MockFile(source); |
| 240 } | 239 } |
| 241 | 240 |
| 242 /** | 241 /** |
| 243 * Used internally to create a library from a source text. The created library | 242 * Used internally to create a library from a source text. The created library |
| 244 * is fixed to export its top-level declarations. | 243 * is fixed to export its top-level declarations. |
| 245 */ | 244 */ |
| 246 LibraryElement createLibrary(String name, String source) { | 245 LibraryElement createLibrary(String name, String source) { |
| 247 Uri uri = new Uri.fromComponents(scheme: "dart", path: name); | 246 Uri uri = new Uri(scheme: "dart", path: name); |
| 248 var script = new Script(uri, new MockFile(source)); | 247 var script = new Script(uri, new MockFile(source)); |
| 249 var library = new LibraryElementX(script); | 248 var library = new LibraryElementX(script); |
| 250 parseScript(source, library); | 249 parseScript(source, library); |
| 251 library.setExports(library.localScope.values.toList()); | 250 library.setExports(library.localScope.values.toList()); |
| 252 registerSource(uri, source); | 251 registerSource(uri, source); |
| 253 libraries.putIfAbsent(uri.toString(), () => library); | 252 libraries.putIfAbsent(uri.toString(), () => library); |
| 254 return library; | 253 return library; |
| 255 } | 254 } |
| 256 | 255 |
| 257 void reportWarning(Node node, var message) { | 256 void reportWarning(Node node, var message) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 void importLibrary(LibraryElement target, LibraryElement imported, | 391 void importLibrary(LibraryElement target, LibraryElement imported, |
| 393 Compiler compiler) { | 392 Compiler compiler) { |
| 394 for (var element in imported.localMembers) { | 393 for (var element in imported.localMembers) { |
| 395 compiler.withCurrentElement(element, () { | 394 compiler.withCurrentElement(element, () { |
| 396 target.addToScope(element, compiler); | 395 target.addToScope(element, compiler); |
| 397 }); | 396 }); |
| 398 } | 397 } |
| 399 } | 398 } |
| 400 | 399 |
| 401 LibraryElement mockLibrary(Compiler compiler, String source) { | 400 LibraryElement mockLibrary(Compiler compiler, String source) { |
| 402 Uri uri = new Uri.fromComponents(scheme: "source"); | 401 Uri uri = new Uri(scheme: "source"); |
| 403 var library = new LibraryElementX(new Script(uri, new MockFile(source))); | 402 var library = new LibraryElementX(new Script(uri, new MockFile(source))); |
| 404 importLibrary(library, compiler.coreLibrary, compiler); | 403 importLibrary(library, compiler.coreLibrary, compiler); |
| 405 return library; | 404 return library; |
| 406 } | 405 } |
| 407 | 406 |
| 408 class CollectingTreeElements extends TreeElementMapping { | 407 class CollectingTreeElements extends TreeElementMapping { |
| 409 final Map<Node, Element> map = new LinkedHashMap<Node, Element>(); | 408 final Map<Node, Element> map = new LinkedHashMap<Node, Element>(); |
| 410 | 409 |
| 411 CollectingTreeElements(Element currentElement) : super(currentElement); | 410 CollectingTreeElements(Element currentElement) : super(currentElement); |
| 412 | 411 |
| 413 operator []=(Node node, Element element) { | 412 operator []=(Node node, Element element) { |
| 414 map[node] = element; | 413 map[node] = element; |
| 415 } | 414 } |
| 416 | 415 |
| 417 operator [](Node node) => map[node]; | 416 operator [](Node node) => map[node]; |
| 418 | 417 |
| 419 void remove(Node node) { | 418 void remove(Node node) { |
| 420 map.remove(node); | 419 map.remove(node); |
| 421 } | 420 } |
| 422 } | 421 } |
| 423 | 422 |
| 424 class MockDeferredLoadTask extends DeferredLoadTask { | 423 class MockDeferredLoadTask extends DeferredLoadTask { |
| 425 MockDeferredLoadTask(Compiler compiler) : super(compiler); | 424 MockDeferredLoadTask(Compiler compiler) : super(compiler); |
| 426 | 425 |
| 427 void registerMainApp(LibraryElement mainApp) { | 426 void registerMainApp(LibraryElement mainApp) { |
| 428 // Do nothing. | 427 // Do nothing. |
| 429 } | 428 } |
| 430 } | 429 } |
| OLD | NEW |