OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Utility functions to test the code generation tools with the resolver. | 5 /// Utility functions to test the code generation tools with the resolver. |
6 // Note, this is just for simple tests, so we restricted the logic to only | 6 // Note, this is just for simple tests, so we restricted the logic to only |
7 // support root-relative imports. For more sophisticated stuff, you should be | 7 // support root-relative imports. For more sophisticated stuff, you should be |
8 // using the test helpers in `package:code_transformers`. | 8 // using the test helpers in `package:code_transformers`. |
9 library smoke.test.codegen.testing_resolver_utils; | 9 library smoke.test.codegen.testing_resolver_utils; |
10 | 10 |
11 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
13 import 'package:analyzer/src/generated/java_io.dart'; | 13 import 'package:analyzer/src/generated/java_io.dart'; |
14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
15 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 15 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
16 import 'package:code_transformers/src/dart_sdk.dart' show | 16 import 'package:code_transformers/tests.dart' show testingDartSdkDirectory; |
17 testingDartSdkDirectory; | |
18 | 17 |
19 class LibraryProvider { | 18 class LibraryProvider { |
20 final AnalysisContext _analyzer; | 19 final AnalysisContext _analyzer; |
21 final Map<String, Source> _allSources; | 20 final Map<String, Source> _allSources; |
22 LibraryProvider(this._analyzer, this._allSources); | 21 LibraryProvider(this._analyzer, this._allSources); |
23 LibraryElement libraryFor(String uri) => | 22 LibraryElement libraryFor(String uri) => |
24 _analyzer.computeLibraryElement(_allSources[uri]); | 23 _analyzer.computeLibraryElement(_allSources[uri]); |
25 } | 24 } |
26 | 25 |
27 LibraryProvider initAnalyzer(Map<String, String> contents) { | 26 LibraryProvider initAnalyzer(Map<String, String> contents) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // using the test helpers in `package:code_transformers`. | 88 // using the test helpers in `package:code_transformers`. |
90 Source resolveRelative(Uri uri) { | 89 Source resolveRelative(Uri uri) { |
91 if (uri.path.startsWith('/')) return allSources['${uri.path}']; | 90 if (uri.path.startsWith('/')) return allSources['${uri.path}']; |
92 throw new UnimplementedError('relative URIs not supported: $uri'); | 91 throw new UnimplementedError('relative URIs not supported: $uri'); |
93 } | 92 } |
94 | 93 |
95 void getContentsToReceiver(Source_ContentReceiver receiver) { | 94 void getContentsToReceiver(Source_ContentReceiver receiver) { |
96 receiver.accept(rawContents, modificationStamp); | 95 receiver.accept(rawContents, modificationStamp); |
97 } | 96 } |
98 } | 97 } |
OLD | NEW |