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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/checked_mirrors/lib/src/wrappers.dart ('k') | pkg/checked_mirrors/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * Replaces uses of "package:checked_mirrors/checked_mirrors.dart" with
7 * "dart:mirrors" that contain the MirrorUsed annotation.
8 */
9 library checked_mirrors.transformer;
10
11 import 'dart:async';
12
13 import 'package:barback/barback.dart';
14
15 /**
16 * A [Transformer] that replaces observables based on dirty-checking with an
17 * implementation based on change notifications.
18 *
19 * The transformation adds hooks for field setters and notifies the observation
20 * system of the change.
21 */
22 class CheckedMirrorsTransformer extends Transformer {
23
24 final List<String> _files;
25 CheckedMirrorsTransformer() : _files = null;
26 CheckedMirrorsTransformer.asPlugin(BarbackSettings settings)
27 : _files = _readFiles(settings.configuration['files']);
28
29 static List<String> _readFiles(value) {
30 if (value == null) return null;
31 var files = [];
32 bool error;
33 if (value is List) {
34 files = value;
35 error = value.any((e) => e is! String);
36 } else if (value is String) {
37 files = [value];
38 error = false;
39 } else {
40 error = true;
41 }
42 if (error) print('Invalid value for "files" in the observe transformer.');
43 return files;
44 }
45
46 Future<bool> isPrimary(Asset input) {
47 if (input.id.extension != '.dart' ||
48 (_files != null && !_files.contains(input.id.path))) {
49 return new Future.value(false);
50 }
51 return input.readAsString().then(
52 (c) => c.contains("package:checked_mirrors.dart/checked_mirrors.dart"));
53 }
54
55 Future apply(Transform transform) {
56 return transform.primaryInput.readAsString().then((content) {
57 var id = transform.primaryInput.id;
58 // TODO(sigmund): do a real transformer that only replaces imports, not
59 // all occurrences of this string.
60 // -----
61 // TODO(sigmund): move the @MirrorUsed from the field to the import
62 // need to do this before this CL is ready.
63 // ----
64 transform.addOutput(new Asset.fromString(id, content.replaceAll(
65 "package:checked_mirrors.dart/checked_mirrors.dart",
66 "dart:mirrors")));
67 });
68 }
69 }
OLDNEW
« 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