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

Unified Diff: pkg/serialization/lib/src/serialization_rule.dart

Issue 13982012: Update pkg/serialization to use Symbols and synchronous mirrors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | « pkg/serialization/lib/src/mirrors_helpers.dart ('k') | pkg/serialization/test/serialization_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/serialization/lib/src/serialization_rule.dart
diff --git a/pkg/serialization/lib/src/serialization_rule.dart b/pkg/serialization/lib/src/serialization_rule.dart
index d63f07ab8842b63f6b91505e40673b327b7083a3..378da45394e3360854e876dc5ea15764520d4b49 100644
--- a/pkg/serialization/lib/src/serialization_rule.dart
+++ b/pkg/serialization/lib/src/serialization_rule.dart
@@ -392,19 +392,20 @@ class NamedObjectRule extends SerializationRule {
*/
class MirrorRule extends NamedObjectRule {
bool appliesTo(object, Writer writer) => object is DeclarationMirror;
- nameFor(DeclarationMirror object, Writer writer) => object.qualifiedName;
+ nameFor(DeclarationMirror object, Writer writer) =>
+ MirrorSystem.getName(object.qualifiedName);
inflateEssential(state, Reader r) {
var qualifiedName = r.resolveReference(state.first);
var lookupFull = r.objectNamed(qualifiedName, (x) => null);
if (lookupFull != null) return lookupFull;
var separatorIndex = qualifiedName.lastIndexOf(".");
- var lib = qualifiedName.substring(0, separatorIndex);
+ var lib = new Symbol(qualifiedName.substring(0, separatorIndex));
var type = qualifiedName.substring(separatorIndex + 1);
var lookup = r.objectNamed(type, (x) => null);
if (lookup != null) return lookup;
var libMirror = currentMirrorSystem().libraries[lib];
- return libMirror.classes[type];
+ return libMirror.classes[new Symbol(type)];
}
}
@@ -469,6 +470,16 @@ abstract class CustomRule extends SerializationRule {
get hasVariableLengthEntries => true;
}
+/** A hard-coded rule for serializing Symbols. */
+class SymbolRule extends CustomRule {
+ bool appliesTo(instance, _) => instance is Symbol;
+ getState(instance) => [MirrorSystem.getName(instance)];
+ create(state) => new Symbol(state[0]);
+ setState(symbol, state) {}
+ int get dataLength => 1;
+ bool get hasVariableLengthEntries => false;
+}
+
/** Create a lazy list/map that will inflate its items on demand in [r]. */
_lazy(l, Reader r) {
if (l is List) return new _LazyList(l, r);
« no previous file with comments | « pkg/serialization/lib/src/mirrors_helpers.dart ('k') | pkg/serialization/test/serialization_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698