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

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

Issue 17379025: pkg/serialization: cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 bool containsValue(x) => _inflated.containsValue(x); 539 bool containsValue(x) => _inflated.containsValue(x);
540 Iterable get values => _inflated.values; 540 Iterable get values => _inflated.values;
541 void forEach(f) => _inflated.forEach(f); 541 void forEach(f) => _inflated.forEach(f);
542 542
543 // These operations are all invalid 543 // These operations are all invalid
544 _throw() { 544 _throw() {
545 throw new UnsupportedError("Not modifiable"); 545 throw new UnsupportedError("Not modifiable");
546 } 546 }
547 operator []=(x, y) => _throw(); 547 operator []=(x, y) => _throw();
548 putIfAbsent(x, y) => _throw(); 548 putIfAbsent(x, y) => _throw();
549 remove(x) => _throw(); 549 bool remove(x) => _throw();
550 clear() => _throw(); 550 void clear() => _throw();
Alan Knight 2013/06/21 22:47:46 You can't declare things void and use the => synta
kevmoo-old 2013/06/21 22:57:32 It's more about incompatible return types. If _th
Alan Knight 2013/06/21 23:15:20 Since _throw never returns, it's moot anyway. But
551 void addAll(Map other) => _throw();
551 } 552 }
552 553
553 /** 554 /**
554 * This provides an implementation of List that wraps a list which may 555 * This provides an implementation of List that wraps a list which may
555 * contain references to (potentially) non-inflated objects. If these 556 * contain references to (potentially) non-inflated objects. If these
556 * are accessed it will inflate them. This allows us to pass something that 557 * are accessed it will inflate them. This allows us to pass something that
557 * looks like it's just a list of objects to a [CustomRule] without needing 558 * looks like it's just a list of objects to a [CustomRule] without needing
558 * to inflate all the references in advance. 559 * to inflate all the references in advance.
559 */ 560 */
560 class _LazyList extends IterableBase implements List { 561 class _LazyList extends IterableBase with ListMixin implements List {
561 _LazyList(this._raw, this._reader); 562 _LazyList(this._raw, this._reader);
562 563
563 final List _raw; 564 final List _raw;
564 final Reader _reader; 565 final Reader _reader;
565 566
566 // This is the only operation that really matters. 567 operator [](int x) => _reader.inflateReference(_raw[x]);
567 operator [](x) => _reader.inflateReference(_raw[x]); 568 int get length => _raw.length;
Alan Knight 2013/06/21 22:47:46 Nice to be able to get rid of all that boilerplate
kevmoo-old 2013/06/21 22:57:32 Yup yup
568 569
569 int get length => _raw.length; 570 void set length(int value) => _throw();
570 bool get isEmpty => _raw.isEmpty;
571 get first => _reader.inflateReference(_raw.first);
572 get last => _reader.inflateReference(_raw.last);
573 571
574 // These operations, and other inherited methods that iterate over the whole 572 void operator []=(int index, value) => _throw();
575 // list will work, but may be expensive, and are probably
576 // best avoided.
577 Iterable get _inflated => _raw.map(_reader.inflateReference);
578 Iterator get iterator => _inflated.iterator;
579 indexOf(x, [pos = 0]) => _inflated.toList().indexOf(x);
580 lastIndexOf(x, [pos]) => _inflated.toList().lastIndexOf(x);
581 sublist(start, [end]) => _inflated.sublist(start, end);
582 573
583 Map<int, dynamic> asMap() => _inflated.asMap(); 574 void _throw() {
584
585 // These operations are all invalid
586 _throw() {
587 throw new UnsupportedError("Not modifiable"); 575 throw new UnsupportedError("Not modifiable");
588 } 576 }
589 operator []=(x, y) => _throw();
590 add(x) => _throw();
591 addAll(x) => _throw();
592 sort([f]) => _throw();
593 clear() => _throw();
594 insert(x, y) => _throw();
595 insertAll(x, y) => _throw();
596 fillRange(x, y, [z]) => _throw();
597 removeAt(x) => _throw();
598 remove(x) => _throw();
599 removeLast() => _throw();
600 removeAll(x) => _throw();
601 retainAll(x) => _throw();
602 removeWhere(x) => _throw();
603 retainWhere(x) => _throw();
604 replaceRange(x, y, z) => _throw();
605 getRange(x, y) => _throw();
606 setRange(x, y, z, [a = 0]) => _throw();
607 setAll(x, y) => _throw();
608 removeRange(x, y) => _throw();
609 get reversed => _throw();
610 void set length(x) => _throw();
611 } 577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698