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

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

Issue 12604023: Add test and fix for 9203, fix sdk dep, delete unused file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 * [Serialization.read]. 391 * [Serialization.read].
392 */ 392 */
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) => object.qualifiedName; 395 nameFor(DeclarationMirror object, Writer writer) => object.qualifiedName;
396 396
397 inflateEssential(state, Reader r) { 397 inflateEssential(state, Reader r) {
398 var qualifiedName = r.resolveReference(state.first); 398 var qualifiedName = r.resolveReference(state.first);
399 var lookupFull = r.objectNamed(qualifiedName, (x) => null); 399 var lookupFull = r.objectNamed(qualifiedName, (x) => null);
400 if (lookupFull != null) return lookupFull; 400 if (lookupFull != null) return lookupFull;
401 var lib = qualifiedName.substring(0, qualifiedName.indexOf(".")); 401 var separatorIndex = qualifiedName.lastIndexOf(".");
402 var type = qualifiedName.substring(qualifiedName.indexOf(".") + 1); 402 var lib = qualifiedName.substring(0, separatorIndex);
403 var type = qualifiedName.substring(separatorIndex + 1);
403 var lookup = r.objectNamed(type, (x) => null); 404 var lookup = r.objectNamed(type, (x) => null);
404 if (lookup != null) return lookup; 405 if (lookup != null) return lookup;
405 var libMirror = currentMirrorSystem().libraries[lib]; 406 var libMirror = currentMirrorSystem().libraries[lib];
406 return libMirror.classes[type]; 407 return libMirror.classes[type];
407 } 408 }
408 } 409 }
409 410
410 /** 411 /**
411 * This provides an abstract superclass for writing your own rules specific to 412 * This provides an abstract superclass for writing your own rules specific to
412 * a class. It makes some assumptions about behaviour, and so can have a 413 * a class. It makes some assumptions about behaviour, and so can have a
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 get first => _reader.inflateReference(_raw.first); 535 get first => _reader.inflateReference(_raw.first);
535 get last => _reader.inflateReference(_raw.last); 536 get last => _reader.inflateReference(_raw.last);
536 537
537 // These operations, and other inherited methods that iterate over the whole 538 // These operations, and other inherited methods that iterate over the whole
538 // list will work, but may be expensive, and are probably 539 // list will work, but may be expensive, and are probably
539 // best avoided. 540 // best avoided.
540 List get _inflated => _raw.map(_reader.inflateReference); 541 List get _inflated => _raw.map(_reader.inflateReference);
541 Iterator get iterator => _inflated.iterator; 542 Iterator get iterator => _inflated.iterator;
542 indexOf(x, [pos = 0]) => _inflated.toList().indexOf(x); 543 indexOf(x, [pos = 0]) => _inflated.toList().indexOf(x);
543 lastIndexOf(x, [pos]) => _inflated.toList().lastIndexOf(x); 544 lastIndexOf(x, [pos]) => _inflated.toList().lastIndexOf(x);
545 sublist(start, [end]) => _inflated.sublist(start, end);
544 546
545 Map<int, dynamic> asMap() => IterableMixinWorkaround.asMapList(this); 547 Map<int, dynamic> asMap() => IterableMixinWorkaround.asMapList(this);
546 548
547 // These operations are all invalid 549 // These operations are all invalid
548 _throw() { 550 _throw() {
549 throw new UnsupportedError("Not modifiable"); 551 throw new UnsupportedError("Not modifiable");
550 } 552 }
551 operator []=(x, y) => _throw(); 553 operator []=(x, y) => _throw();
552 add(x) => _throw(); 554 add(x) => _throw();
553 addLast(x) => _throw(); 555 addLast(x) => _throw();
554 addAll(x) => _throw(); 556 addAll(x) => _throw();
555 sort([f]) => _throw(); 557 sort([f]) => _throw();
556 clear() => _throw(); 558 clear() => _throw();
557 insert(x, y) => _throw(); 559 insert(x, y) => _throw();
558 removeAt(x) => _throw(); 560 removeAt(x) => _throw();
559 remove(x) => _throw(); 561 remove(x) => _throw();
560 removeLast() => _throw(); 562 removeLast() => _throw();
561 removeAll(x) => _throw(); 563 removeAll(x) => _throw();
562 retainAll(x) => _throw(); 564 retainAll(x) => _throw();
563 removeWhere(x) => _throw(); 565 removeWhere(x) => _throw();
564 retainWhere(x) => _throw(); 566 retainWhere(x) => _throw();
565 getRange(x, y) => _throw(); 567 getRange(x, y) => _throw();
566 setRange(x, y, z, [a]) => _throw(); 568 setRange(x, y, z, [a]) => _throw();
567 removeRange(x, y) => _throw(); 569 removeRange(x, y) => _throw();
568 insertRange(x, y, [z]) => _throw(); 570 insertRange(x, y, [z]) => _throw();
569 get reversed => _throw(); 571 get reversed => _throw();
570 void set length(x) => _throw(); 572 void set length(x) => _throw();
571 } 573 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698