OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart2js.test.memory_source_file_helper; | 5 library dart2js.test.memory_source_file_helper; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 export 'dart:io' show Platform; | 8 export 'dart:io' show Platform; |
9 | 9 |
10 export 'package:compiler/implementation/apiimpl.dart' | 10 export 'package:compiler/src/apiimpl.dart' |
11 show Compiler; | 11 show Compiler; |
12 | 12 |
13 export 'package:compiler/implementation/filenames.dart' | 13 export 'package:compiler/src/filenames.dart' |
14 show currentDirectory; | 14 show currentDirectory; |
15 | 15 |
16 import 'package:compiler/implementation/source_file.dart' | 16 import 'package:compiler/src/source_file.dart' |
17 show StringSourceFile; | 17 show StringSourceFile; |
18 | 18 |
19 import 'package:compiler/implementation/source_file_provider.dart' | 19 import 'package:compiler/src/source_file_provider.dart' |
20 show SourceFileProvider; | 20 show SourceFileProvider; |
21 | 21 |
22 export 'package:compiler/implementation/source_file_provider.dart' | 22 export 'package:compiler/src/source_file_provider.dart' |
23 show SourceFileProvider, FormattingDiagnosticHandler; | 23 show SourceFileProvider, FormattingDiagnosticHandler; |
24 | 24 |
25 class MemorySourceFileProvider extends SourceFileProvider { | 25 class MemorySourceFileProvider extends SourceFileProvider { |
26 Map<String, String> memorySourceFiles; | 26 Map<String, String> memorySourceFiles; |
27 | 27 |
28 MemorySourceFileProvider(Map<String, String> this.memorySourceFiles); | 28 MemorySourceFileProvider(Map<String, String> this.memorySourceFiles); |
29 | 29 |
30 Future<String> readStringFromUri(Uri resourceUri) { | 30 Future<String> readStringFromUri(Uri resourceUri) { |
31 if (resourceUri.scheme != 'memory') { | 31 if (resourceUri.scheme != 'memory') { |
32 return super.readStringFromUri(resourceUri); | 32 return super.readStringFromUri(resourceUri); |
33 } | 33 } |
34 String source = memorySourceFiles[resourceUri.path]; | 34 String source = memorySourceFiles[resourceUri.path]; |
35 if (source == null) { | 35 if (source == null) { |
36 return new Future.error(new Exception('No such file $resourceUri')); | 36 return new Future.error(new Exception('No such file $resourceUri')); |
37 } | 37 } |
38 String resourceName = '$resourceUri'; | 38 String resourceName = '$resourceUri'; |
39 this.sourceFiles[resourceName] = new StringSourceFile(resourceName, source); | 39 this.sourceFiles[resourceName] = new StringSourceFile(resourceName, source); |
40 return new Future.value(source); | 40 return new Future.value(source); |
41 } | 41 } |
42 | 42 |
43 Future<String> call(Uri resourceUri) => readStringFromUri(resourceUri); | 43 Future<String> call(Uri resourceUri) => readStringFromUri(resourceUri); |
44 } | 44 } |
OLD | NEW |