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

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

Issue 200543006: Allow multiple-entry libraries in code_transformers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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/test/resolver_test.dart » ('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 b98e587467c6f153a9ad53d9ae662392ae2cfb23..f7e39b3de595cca935fbb830ad076013070c51bf 100644
--- a/pkg/code_transformers/lib/src/resolvers.dart
+++ b/pkg/code_transformers/lib/src/resolvers.dart
@@ -19,21 +19,23 @@ import 'resolver_impl.dart';
/// If multiple transformers rely on a resolved AST they should (ideally) share
/// the same Resolvers object to minimize re-parsing the AST.
class Resolvers {
- final Map<AssetId, ResolverImpl> _resolvers = {};
+ final Map<AssetId, Resolver> _resolvers = {};
final String dartSdkDirectory;
Resolvers(this.dartSdkDirectory);
- /// Get a resolver for the AST starting from [id].
+ /// 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.
///
/// [Resolver.release] must be called once it's done being used, or
/// [ResolverTransformer] should be used to automatically release the
/// resolver.
- Future<Resolver> get(Transform transform) {
+ Future<Resolver> get(Transform transform, [List<AssetId> entryPoints]) {
var id = transform.primaryInput.id;
var resolver = _resolvers.putIfAbsent(id,
- () => new ResolverImpl(id, dartSdkDirectory));
- return resolver.resolve(transform);
+ () => new ResolverImpl(dartSdkDirectory));
+ return resolver.resolve(transform, entryPoints);
}
}
@@ -45,8 +47,27 @@ abstract class ResolverTransformer implements Transformer {
/// The cache of resolvers- must be set from subclass.
Resolvers resolvers;
- Future apply(Transform transform) {
- return resolvers.get(transform).then((resolver) {
+ /// This provides a default implementation of `Transformer.apply` that will
+ /// get and release resolvers automatically. Internally this:
+ /// * Gets a resolver associated with the transform primary input.
+ /// * Does resolution to the code starting from that input.
+ /// * Calls [applyResolver].
+ /// * Then releases the resolver.
+ ///
+ /// Use [applyToEntryPoints] instead if you need to override the entry points
+ /// to run the resolver on.
+ Future apply(Transform transform) => applyToEntryPoints(transform);
+
+ /// Helper function to make it easy to write an `Transformer.apply` method
+ /// that automatically gets and releases the resolver. This is typically used
+ /// as follows:
+ ///
+ /// Future apply(Transform transform) {
+ /// var entryPoints = ...; // compute entry points
+ /// return applyToEntryPoints(transform, entryPoints);
+ /// }
+ Future applyToEntryPoints(Transform transform, [List<AssetId> entryPoints]) {
+ return resolvers.get(transform, entryPoints).then((resolver) {
return new Future.value(applyResolver(transform, resolver)).then((_) {
resolver.release();
});
« no previous file with comments | « pkg/code_transformers/lib/src/resolver_impl.dart ('k') | pkg/code_transformers/test/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698