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

Unified Diff: pkg/checked_mirrors/lib/transformer.dart

Issue 111643015: Preliminary checked mirrors (not ready for review yet) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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/checked_mirrors/lib/src/wrappers.dart ('k') | pkg/checked_mirrors/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/checked_mirrors/lib/transformer.dart
diff --git a/pkg/checked_mirrors/lib/transformer.dart b/pkg/checked_mirrors/lib/transformer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3f53ecd1947a63c6ed6354968152419cecfcde77
--- /dev/null
+++ b/pkg/checked_mirrors/lib/transformer.dart
@@ -0,0 +1,69 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/**
+ * Replaces uses of "package:checked_mirrors/checked_mirrors.dart" with
+ * "dart:mirrors" that contain the MirrorUsed annotation.
+ */
+library checked_mirrors.transformer;
+
+import 'dart:async';
+
+import 'package:barback/barback.dart';
+
+/**
+ * A [Transformer] that replaces observables based on dirty-checking with an
+ * implementation based on change notifications.
+ *
+ * The transformation adds hooks for field setters and notifies the observation
+ * system of the change.
+ */
+class CheckedMirrorsTransformer extends Transformer {
+
+ final List<String> _files;
+ CheckedMirrorsTransformer() : _files = null;
+ CheckedMirrorsTransformer.asPlugin(BarbackSettings settings)
+ : _files = _readFiles(settings.configuration['files']);
+
+ static List<String> _readFiles(value) {
+ if (value == null) return null;
+ var files = [];
+ bool error;
+ if (value is List) {
+ files = value;
+ error = value.any((e) => e is! String);
+ } else if (value is String) {
+ files = [value];
+ error = false;
+ } else {
+ error = true;
+ }
+ if (error) print('Invalid value for "files" in the observe transformer.');
+ return files;
+ }
+
+ Future<bool> isPrimary(Asset input) {
+ if (input.id.extension != '.dart' ||
+ (_files != null && !_files.contains(input.id.path))) {
+ return new Future.value(false);
+ }
+ return input.readAsString().then(
+ (c) => c.contains("package:checked_mirrors.dart/checked_mirrors.dart"));
+ }
+
+ Future apply(Transform transform) {
+ return transform.primaryInput.readAsString().then((content) {
+ var id = transform.primaryInput.id;
+ // TODO(sigmund): do a real transformer that only replaces imports, not
+ // all occurrences of this string.
+ // -----
+ // TODO(sigmund): move the @MirrorUsed from the field to the import
+ // need to do this before this CL is ready.
+ // ----
+ transform.addOutput(new Asset.fromString(id, content.replaceAll(
+ "package:checked_mirrors.dart/checked_mirrors.dart",
+ "dart:mirrors")));
+ });
+ }
+}
« no previous file with comments | « pkg/checked_mirrors/lib/src/wrappers.dart ('k') | pkg/checked_mirrors/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698