Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2782)

Unified Diff: pkg/code_transformers/lib/src/resolvers.dart

Issue 315813003: Support using a mock SDK with the resolver in code-transformers, and switch (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/code_transformers/lib/src/resolver_impl.dart ('k') | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
}
« no previous file with comments | « pkg/code_transformers/lib/src/resolver_impl.dart ('k') | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698