| OLD | NEW |
| 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 /** |
| 11 * The abstract superclass for serialization rules. | 11 * The abstract superclass for serialization rules. |
| 12 */ | 12 */ |
| 13 abstract class SerializationRule { | 13 abstract class SerializationRule { |
| 14 /** | 14 /** |
| 15 * Rules belong uniquely to a particular Serialization instance, and can | 15 * Rules belong uniquely to a particular Serialization instance, and can |
| 16 * be identified within it by number. | 16 * be identified within it by number. |
| 17 */ | 17 */ |
| 18 int _number; | 18 int _number; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Rules belong uniquely to a particular Serialization instance, and can | 21 * Rules belong uniquely to a particular Serialization instance, and can |
| 22 * be identified within it by number. | 22 * be identified within it by number. |
| 23 */ | 23 */ |
| 24 int get number => _number; | 24 int get number => _number; |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Rules belong uniquely to a particular Serialization instance, and can | 27 * Rules belong uniquely to a particular Serialization instance, and can |
| 28 * be identified within it by number. | 28 * be identified within it by number. |
| 29 */ | 29 */ |
| 30 void set number(x) { | 30 void set number(int value) { |
| 31 if (_number != null && _number != x) throw | 31 if (_number != null && _number != value) throw |
| 32 new SerializationException("Rule numbers cannot be changed, once set"); | 32 new SerializationException("Rule numbers cannot be changed, once set"); |
| 33 _number = x; | 33 _number = value; |
| 34 } | 34 } |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Return true if this rule applies to this object, in the context | 37 * Return true if this rule applies to this object, in the context |
| 38 * where we're writing it, false otherwise. | 38 * where we're writing it, false otherwise. |
| 39 */ | 39 */ |
| 40 bool appliesTo(object, Writer writer); | 40 bool appliesTo(object, Writer writer); |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * This extracts the state from the object, calling [f] for each value | 43 * This extracts the state from the object, calling [f] for each value |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 * also want to have multiple different rules that might exclusively apply | 84 * also want to have multiple different rules that might exclusively apply |
| 85 * to the same object. So, we want either ListRule or ListRuleEssential, and | 85 * to the same object. So, we want either ListRule or ListRuleEssential, and |
| 86 * only one of them can be there. But on the other hand, we may want both | 86 * only one of them can be there. But on the other hand, we may want both |
| 87 * ListRule and BasicRule. So we identify the kinds of rules that can share. | 87 * ListRule and BasicRule. So we identify the kinds of rules that can share. |
| 88 * If mustBePrimary returns true, then this rule will only be chosen if no | 88 * If mustBePrimary returns true, then this rule will only be chosen if no |
| 89 * other rule has been found yet. This means that the ordering of rules in | 89 * other rule has been found yet. This means that the ordering of rules in |
| 90 * the serialization is significant, which is unpleasant, but we'll have | 90 * the serialization is significant, which is unpleasant, but we'll have |
| 91 * to see how bad it is. | 91 * to see how bad it is. |
| 92 */ | 92 */ |
| 93 // TODO(alanknight): Reconsider whether this should be handled differently. | 93 // TODO(alanknight): Reconsider whether this should be handled differently. |
| 94 get mustBePrimary => false; | 94 bool get mustBePrimary => false; |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * Create the new object corresponding to [state] using the rules | 97 * Create the new object corresponding to [state] using the rules |
| 98 * from [reader]. This may involve recursively inflating "essential" | 98 * from [reader]. This may involve recursively inflating "essential" |
| 99 * references in the state, which are those that are required for the | 99 * references in the state, which are those that are required for the |
| 100 * object's constructor. It is up to the rule what state is considered | 100 * object's constructor. It is up to the rule what state is considered |
| 101 * essential. | 101 * essential. |
| 102 */ | 102 */ |
| 103 inflateEssential(state, Reader reader); | 103 inflateEssential(state, Reader reader); |
| 104 | 104 |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 removeWhere(x) => _throw(); | 577 removeWhere(x) => _throw(); |
| 578 retainWhere(x) => _throw(); | 578 retainWhere(x) => _throw(); |
| 579 replaceRange(x, y, z) => _throw(); | 579 replaceRange(x, y, z) => _throw(); |
| 580 getRange(x, y) => _throw(); | 580 getRange(x, y) => _throw(); |
| 581 setRange(x, y, z, [a = 0]) => _throw(); | 581 setRange(x, y, z, [a = 0]) => _throw(); |
| 582 setAll(x, y) => _throw(); | 582 setAll(x, y) => _throw(); |
| 583 removeRange(x, y) => _throw(); | 583 removeRange(x, y) => _throw(); |
| 584 get reversed => _throw(); | 584 get reversed => _throw(); |
| 585 void set length(x) => _throw(); | 585 void set length(x) => _throw(); |
| 586 } | 586 } |
| OLD | NEW |