Index: pkg/code_transformers/lib/src/resolvers.dart |
diff --git a/pkg/code_transformers/lib/src/resolvers.dart b/pkg/code_transformers/lib/src/resolvers.dart |
index 4b768d4f075be64b850900b8352d73f446ed0910..f807a0ab91ff123b763662038bcb037420ad8888 100644 |
--- a/pkg/code_transformers/lib/src/resolvers.dart |
+++ b/pkg/code_transformers/lib/src/resolvers.dart |
@@ -7,9 +7,13 @@ library code_transformers.src.resolvers; |
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,9 +25,22 @@ import 'resolver_impl.dart'; |
/// 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.fromSdk(this.dartSdk, this.dartUriResolver); |
- Resolvers(this.dartSdkDirectory); |
+ 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, new DartUriResolver(sdk)); |
+ } |
/// Get a resolver for [transform]. If provided, this resolves the code |
/// starting from each of the assets in [entryPoints]. If not, this resolves |
@@ -35,7 +52,7 @@ class Resolvers { |
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); |
} |
} |