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

Unified Diff: sdk/lib/_internal/pub/asset/dart/transformer_isolate.dart

Issue 236363015: Support loading transformers exported by packages' libraries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 8 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 | « no previous file | sdk/lib/_internal/pub/test/transformer/loads_a_transformer_defined_in_an_exported_library_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/asset/dart/transformer_isolate.dart
diff --git a/sdk/lib/_internal/pub/asset/dart/transformer_isolate.dart b/sdk/lib/_internal/pub/asset/dart/transformer_isolate.dart
index 5b6dfa78e772227544658993c1aff2f3df523293..3b668417ef5321553086efd41ce71ef461d7c1d3 100644
--- a/sdk/lib/_internal/pub/asset/dart/transformer_isolate.dart
+++ b/sdk/lib/_internal/pub/asset/dart/transformer_isolate.dart
@@ -29,36 +29,53 @@ void loadTransformers(SendPort replyTo) {
/// Loads all the transformers and groups defined in [uri].
///
-/// Loads the library, finds any Transformer or TransformerGroup subclasses in
-/// it, instantiates them with [configuration] and [mode], and returns them.
-Iterable _initialize(Uri uri, Map configuration, BarbackMode mode) {
+/// Loads the library, finds any [Transformer] or [TransformerGroup] subclasses
+/// in it, instantiates them with [configuration] and [mode], and returns them.
+List _initialize(Uri uri, Map configuration, BarbackMode mode) {
var mirrors = currentMirrorSystem();
var transformerClass = reflectClass(Transformer);
var groupClass = reflectClass(TransformerGroup);
- // TODO(nweiz): if no valid transformers are found, throw an error message
- // describing candidates and why they were rejected.
- return mirrors.libraries[uri].declarations.values.map((declaration) {
- if (declaration is! ClassMirror) return null;
- var classMirror = declaration;
- if (classMirror.isPrivate) return null;
- if (classMirror.isAbstract) return null;
- if (!classMirror.isSubtypeOf(transformerClass) &&
- !classMirror.isSubtypeOf(groupClass)) {
- return null;
- }
+ var seen = new Set();
+ var transformers = [];
+
+ loadFromLibrary(library) {
+ if (seen.contains(library)) return;
+ seen.add(library);
- var constructor = _getConstructor(classMirror, 'asPlugin');
- if (constructor == null) return null;
- if (constructor.parameters.isEmpty) {
- if (configuration.isNotEmpty) return null;
- return classMirror.newInstance(const Symbol('asPlugin'), []).reflectee;
+ // Load transformers from libraries exported by [library].
+ for (var dependency in library.libraryDependencies) {
+ if (!dependency.isExport) continue;
+ loadFromLibrary(dependency.targetLibrary);
}
- if (constructor.parameters.length != 1) return null;
- return classMirror.newInstance(const Symbol('asPlugin'),
- [new BarbackSettings(configuration, mode)]).reflectee;
- }).where((classMirror) => classMirror != null);
+ // TODO(nweiz): if no valid transformers are found, throw an error message
+ // describing candidates and why they were rejected.
+ transformers.addAll(library.declarations.values.map((declaration) {
+ if (declaration is! ClassMirror) return null;
+ var classMirror = declaration;
+ if (classMirror.isPrivate) return null;
+ if (classMirror.isAbstract) return null;
+ if (!classMirror.isSubtypeOf(transformerClass) &&
+ !classMirror.isSubtypeOf(groupClass)) {
+ return null;
+ }
+
+ var constructor = _getConstructor(classMirror, 'asPlugin');
+ if (constructor == null) return null;
+ if (constructor.parameters.isEmpty) {
+ if (configuration.isNotEmpty) return null;
+ return classMirror.newInstance(const Symbol('asPlugin'), []).reflectee;
+ }
+ if (constructor.parameters.length != 1) return null;
+
+ return classMirror.newInstance(const Symbol('asPlugin'),
+ [new BarbackSettings(configuration, mode)]).reflectee;
+ }).where((classMirror) => classMirror != null));
+ }
+
+ loadFromLibrary(mirrors.libraries[uri]);
+ return transformers;
}
// TODO(nweiz): clean this up when issue 13248 is fixed.
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/transformer/loads_a_transformer_defined_in_an_exported_library_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698