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

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

Issue 11578037: Replicating CL https://chromiumcodereview.appspot.com/11553012/ (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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): Figure out how to reasonably separate out the things 7 // TODO(alanknight): Figure out how to reasonably separate out the things
8 // that require reflection without making the API more awkward. Or if that is 8 // that require reflection without making the API more awkward. Or if that is
9 // in fact necessary. Maybe the tree-shaking will just remove it if unused. 9 // in fact necessary. Maybe the tree-shaking will just remove it if unused.
10 10
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 /** 164 /**
165 * If the value is a List, and the field is a constructor field or 165 * If the value is a List, and the field is a constructor field or
166 * otherwise specially designated, we wrap it in something that indicates 166 * otherwise specially designated, we wrap it in something that indicates
167 * a restriction on the rules that can be used. Which in this case amounts 167 * a restriction on the rules that can be used. Which in this case amounts
168 * to designating the rule, since we so far only have one rule per object. 168 * to designating the rule, since we so far only have one rule per object.
169 */ 169 */
170 checkForEssentialLists(index, value) { 170 checkForEssentialLists(index, value) {
171 if (value is List && fields.contents[index].isEssential) { 171 if (value is List && fields.contents[index].isEssential) {
172 return new DesignatedRuleForObject(value, 172 return new DesignatedRuleForObject(value,
173 (index) => index is ListRuleEssential); 173 (SerializationRule rule) => rule is ListRuleEssential);
174 } else { 174 } else {
175 return value; 175 return value;
176 } 176 }
177 } 177 }
178 178
179 /** Remove any MapWrapper from the extracted state. */ 179 /** Remove any MapWrapper from the extracted state. */
180 _unwrap(result) => (result is _MapWrapper) ? result.asMap() : result; 180 _unwrap(result) => (result is _MapWrapper) ? result.asMap() : result;
181 181
182 /** 182 /**
183 * Call the designated constructor with the appropriate fields from [state], 183 * Call the designated constructor with the appropriate fields from [state],
(...skipping 15 matching lines...) Expand all
199 var value = reader.inflateReference(state[field.index]); 199 var value = reader.inflateReference(state[field.index]);
200 field.setValue(mirror, value); 200 field.setValue(mirror, value);
201 }); 201 });
202 } 202 }
203 203
204 /** 204 /**
205 * Determine if this rule applies to the object in question. In our case 205 * Determine if this rule applies to the object in question. In our case
206 * this is true if the type mirrors are the same. 206 * this is true if the type mirrors are the same.
207 */ 207 */
208 // TODO(alanknight): This seems likely to be slow. Verify. Other options? 208 // TODO(alanknight): This seems likely to be slow. Verify. Other options?
209 bool appliesTo(object) => reflect(object).type == type; 209 bool appliesTo(object, Writer w) => reflect(object).type == type;
210 210
211 /** 211 /**
212 * Given the various field lists provided by the user, construct the list 212 * Given the various field lists provided by the user, construct the list
213 * of field names that we want. 213 * of field names that we want.
214 */ 214 */
215 void _findFields(List constructorFields, List regularFields, 215 void _findFields(List constructorFields, List regularFields,
216 List excludeFields) { 216 List excludeFields) {
217 fields = new _FieldList(type); 217 fields = new _FieldList(type);
218 fields.constructorFields = constructorFields; 218 fields.constructorFields = constructorFields;
219 fields.regular = regularFields; 219 fields.regular = regularFields;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 addAllNotExplicitlyExcluded(names(fields)); 485 addAllNotExplicitlyExcluded(names(fields));
486 addAllNotExplicitlyExcluded(names(gettersWithSetters)); 486 addAllNotExplicitlyExcluded(names(gettersWithSetters));
487 addAllNotExplicitlyExcluded(names(gettersThatMatchConstructor)); 487 addAllNotExplicitlyExcluded(names(gettersThatMatchConstructor));
488 } 488 }
489 } 489 }
490 490
491 /** 491 /**
492 * Provide a typedef for the setWith argument to specialTreatmentFor. It would 492 * Provide a typedef for the setWith argument to specialTreatmentFor. It would
493 * be nice if we could put this closer to the definition. 493 * be nice if we could put this closer to the definition.
494 */ 494 */
495 typedef SetWithFunction(InstanceMirror m, Object o); 495 typedef SetWithFunction(InstanceMirror m, object);
496 496
497 /** 497 /**
498 * This represents a constructor that is to be used when re-creating a 498 * This represents a constructor that is to be used when re-creating a
499 * serialized object. 499 * serialized object.
500 */ 500 */
501 class Constructor { 501 class Constructor {
502 /** The mirror of the class we construct. */ 502 /** The mirror of the class we construct. */
503 final ClassMirror type; 503 final ClassMirror type;
504 504
505 /** The name of the constructor to use, if not the default constructor.*/ 505 /** The name of the constructor to use, if not the default constructor.*/
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 List fieldList; 543 List fieldList;
544 _MapWrapper(this.fieldList); 544 _MapWrapper(this.fieldList);
545 _MapWrapper.fromMap(this._map, this.fieldList); 545 _MapWrapper.fromMap(this._map, this.fieldList);
546 546
547 operator [](key) => _map[fieldList[key].name]; 547 operator [](key) => _map[fieldList[key].name];
548 operator []=(key, value) { _map[fieldList[key].name] = value; } 548 operator []=(key, value) { _map[fieldList[key].name] = value; }
549 get length => _map.length; 549 get length => _map.length;
550 550
551 asMap() => _map; 551 asMap() => _map;
552 } 552 }
OLDNEW
« no previous file with comments | « pkg/serialization/lib/serialization.dart ('k') | pkg/serialization/lib/src/polyfill_identity_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698