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

Side by Side Diff: pkg/serialization/lib/src/serialization_rule.dart

Issue 14773027: Fix regression in meta-serializing rules (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Slight improvement for the case of duplicate library names Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of serialization; 5 part of serialization;
6 6
7 // TODO(alanknight): We should have an example and tests for subclassing 7 // TODO(alanknight): We should have an example and tests for subclassing
8 // serialization rule rather than using the hard-coded ClosureToMap rule. And 8 // serialization rule rather than using the hard-coded ClosureToMap rule. And
9 // possibly an abstract superclass that's designed to be subclassed that way. 9 // possibly an abstract superclass that's designed to be subclassed that way.
10 /** 10 /**
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 class MirrorRule extends NamedObjectRule { 393 class MirrorRule extends NamedObjectRule {
394 bool appliesTo(object, Writer writer) => object is DeclarationMirror; 394 bool appliesTo(object, Writer writer) => object is DeclarationMirror;
395 nameFor(DeclarationMirror object, Writer writer) => 395 nameFor(DeclarationMirror object, Writer writer) =>
396 MirrorSystem.getName(object.qualifiedName); 396 MirrorSystem.getName(object.qualifiedName);
397 397
398 inflateEssential(state, Reader r) { 398 inflateEssential(state, Reader r) {
399 var qualifiedName = r.resolveReference(state.first); 399 var qualifiedName = r.resolveReference(state.first);
400 var lookupFull = r.objectNamed(qualifiedName, (x) => null); 400 var lookupFull = r.objectNamed(qualifiedName, (x) => null);
401 if (lookupFull != null) return lookupFull; 401 if (lookupFull != null) return lookupFull;
402 var separatorIndex = qualifiedName.lastIndexOf("."); 402 var separatorIndex = qualifiedName.lastIndexOf(".");
403 var lib = new Symbol(qualifiedName.substring(0, separatorIndex));
404 var type = qualifiedName.substring(separatorIndex + 1); 403 var type = qualifiedName.substring(separatorIndex + 1);
405 var lookup = r.objectNamed(type, (x) => null); 404 var lookup = r.objectNamed(type, (x) => null);
406 if (lookup != null) return lookup; 405 if (lookup != null) return lookup;
407 var libMirror = currentMirrorSystem().findLibrary(lib).first; 406 var name = qualifiedName.substring(0, separatorIndex);
408 return libMirror.classes[new Symbol(type)]; 407 // This is very ugly. The library name for an unnamed library is its URI.
408 // That can't be constructed as a Symbol, so we can't use findLibrary.
409 // So follow one or the other path depending if it has a colon, which we
410 // assume is in any URI and can't be in a Symbol.
411 if (name.contains(":")) {
412 var uri = new Uri(name);
413 var libMirror = currentMirrorSystem().libraries[uri];
414 return libMirror.classes[new Symbol(type)];
415 } else {
416 var symbol = new Symbol(name);
417 var typeSymbol = new Symbol(type);
418 var libMirror = currentMirrorSystem().findLibrary(symbol).firstWhere(
419 (lib) => lib.classes[typeSymbol] != null);
420 return libMirror.classes[typeSymbol];
421 }
409 } 422 }
410 } 423 }
411 424
412 /** 425 /**
413 * This provides an abstract superclass for writing your own rules specific to 426 * This provides an abstract superclass for writing your own rules specific to
414 * a class. It makes some assumptions about behaviour, and so can have a 427 * a class. It makes some assumptions about behaviour, and so can have a
415 * simpler set of methods that need to be implemented in order to subclass it. 428 * simpler set of methods that need to be implemented in order to subclass it.
416 * 429 *
417 */ 430 */
418 abstract class CustomRule extends SerializationRule { 431 abstract class CustomRule extends SerializationRule {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 removeWhere(x) => _throw(); 590 removeWhere(x) => _throw();
578 retainWhere(x) => _throw(); 591 retainWhere(x) => _throw();
579 replaceRange(x, y, z) => _throw(); 592 replaceRange(x, y, z) => _throw();
580 getRange(x, y) => _throw(); 593 getRange(x, y) => _throw();
581 setRange(x, y, z, [a = 0]) => _throw(); 594 setRange(x, y, z, [a = 0]) => _throw();
582 setAll(x, y) => _throw(); 595 setAll(x, y) => _throw();
583 removeRange(x, y) => _throw(); 596 removeRange(x, y) => _throw();
584 get reversed => _throw(); 597 get reversed => _throw();
585 void set length(x) => _throw(); 598 void set length(x) => _throw();
586 } 599 }
OLDNEW
« no previous file with comments | « pkg/serialization/lib/serialization.dart ('k') | pkg/serialization/test/serialization_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698