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

Unified Diff: sky/examples/fn/lib/reflect.dart

Issue 971183002: Initial commit of Effen reactive framework experiment for Sky (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « sky/examples/fn/lib/node.dart ('k') | sky/examples/fn/lib/style.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/fn/lib/reflect.dart
diff --git a/sky/examples/fn/lib/reflect.dart b/sky/examples/fn/lib/reflect.dart
new file mode 100644
index 0000000000000000000000000000000000000000..66b2efefc2ea698c86a7c7cd98819750f054157c
--- /dev/null
+++ b/sky/examples/fn/lib/reflect.dart
@@ -0,0 +1,41 @@
+library reflect;
+
+import 'dart:mirrors';
+import 'dart:collection';
+
+HashMap<ClassMirror, List> _fieldCache = new HashMap<ClassMirror, List>();
+
+List<Symbol> _getPublicFields(ClassMirror mirror) {
+ var fields = _fieldCache[mirror];
+ if (fields == null) {
+ fields = new List<Symbol>();
+ _fieldCache[mirror] = fields;
+
+ while (mirror != null) {
+ var decls = mirror.declarations;
+ fields.addAll(decls.keys.where((symbol) {
+ var mirror = decls[symbol];
+ if (mirror is! VariableMirror) {
+ return false;
+ }
+
+ var vMirror = mirror as VariableMirror;
+ return !vMirror.isPrivate && !vMirror.isStatic && !vMirror.isFinal;
+ }));
+
+ mirror = mirror.superclass;
+ }
+ }
+
+ return fields;
+}
+
+void copyPublicFields(Object source, Object target) {
+ assert(source.runtimeType == target.runtimeType);
+
+ var sourceMirror = reflect(source);
+ var targetMirror = reflect(target);
+ for (var symbol in _getPublicFields(sourceMirror.type)) {
+ targetMirror.setField(symbol, sourceMirror.getField(symbol).reflectee);
+ }
+}
« no previous file with comments | « sky/examples/fn/lib/node.dart ('k') | sky/examples/fn/lib/style.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698