Index: pkg/code_transformers/lib/src/resolvers.dart |
=================================================================== |
--- pkg/code_transformers/lib/src/resolvers.dart (revision 37373) |
+++ pkg/code_transformers/lib/src/resolvers.dart (working copy) |
@@ -7,9 +7,13 @@ |
import 'dart:async'; |
import 'package:barback/barback.dart'; |
+import 'package:analyzer/src/generated/sdk.dart' show DartSdk; |
+import 'package:analyzer/src/generated/source.dart' show DartUriResolver; |
+ |
import 'entry_point.dart'; |
import 'resolver.dart'; |
import 'resolver_impl.dart'; |
+import 'dart_sdk.dart' hide dartSdkDirectory; |
/// Barback-based code resolvers which maintains up-to-date resolved ASTs for |
/// the specified code entry points. |
@@ -21,10 +25,23 @@ |
/// the same Resolvers object to minimize re-parsing the AST. |
class Resolvers { |
final Map<AssetId, Resolver> _resolvers = {}; |
- final String dartSdkDirectory; |
+ final DartSdk dartSdk; |
+ final DartUriResolver dartUriResolver; |
- Resolvers(this.dartSdkDirectory); |
+ Resolvers.fromSdk(this.dartSdk, this.dartUriResolver); |
+ factory Resolvers(dartSdkDirectory) { |
+ var sdk = new DirectoryBasedDartSdkProxy(dartSdkDirectory); |
+ var uriResolver = new DartUriResolverProxy(sdk); |
+ return new Resolvers.fromSdk(sdk, uriResolver); |
+ } |
+ |
+ factory Resolvers.fromMock(Map<String, String> sources, |
+ {bool reportMissing: false}) { |
+ var sdk = new MockDartSdk(sources, reportMissing: reportMissing); |
+ return new Resolvers.fromSdk(sdk, sdk.resolver); |
+ } |
+ |
/// Get a resolver for [transform]. If provided, this resolves the code |
/// starting from each of the assets in [entryPoints]. If not, this resolves |
/// the code starting from `transform.primaryInput.id` by default. |
@@ -35,7 +52,7 @@ |
Future<Resolver> get(Transform transform, [List<AssetId> entryPoints]) { |
var id = transform.primaryInput.id; |
var resolver = _resolvers.putIfAbsent(id, |
- () => new ResolverImpl(dartSdkDirectory)); |
+ () => new ResolverImpl(dartSdk, dartUriResolver)); |
return resolver.resolve(transform, entryPoints); |
} |
} |