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

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

Issue 14447008: Fix for mirror API breaking change to index libraries by URI, and clean up references in doc commen… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix from review Created 7 years, 8 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 /** 7 /**
8 * This writes out the state of the objects to an external format. It holds 8 * This writes out the state of the objects to an external format. It holds
9 * all of the intermediate state needed. The primary API for it is the 9 * all of the intermediate state needed. The primary API for it is the
10 * [write] method. 10 * [write] method.
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 * no reference, return the object itself. Once we have finished the tracing 204 * no reference, return the object itself. Once we have finished the tracing
205 * step, all objects that should have a reference (roughly speaking, 205 * step, all objects that should have a reference (roughly speaking,
206 * non-primitives) can be relied on to have a reference. 206 * non-primitives) can be relied on to have a reference.
207 */ 207 */
208 _referenceFor(object) { 208 _referenceFor(object) {
209 var result = references[object]; 209 var result = references[object];
210 return (result == null) ? object : result; 210 return (result == null) ? object : result;
211 } 211 }
212 212
213 /** 213 /**
214 * Return true if the [namedObjects] collection has a reference to [object]. 214 * Return true if the [Serialization.namedObjects] collection has a
215 * reference to [object].
215 */ 216 */
216 // TODO(alanknight): Should the writer also have its own namedObjects 217 // TODO(alanknight): Should the writer also have its own namedObjects
217 // collection specific to the particular write, or is that just adding 218 // collection specific to the particular write, or is that just adding
218 // complexity for little value? 219 // complexity for little value?
219 hasNameFor(object) => serialization._hasNameFor(object); 220 hasNameFor(object) => serialization._hasNameFor(object);
220 221
221 /** 222 /**
222 * Return the name we have for this object in the [namedObjects] collection. 223 * Return the name we have for this object in the [Serialization.namedObjects]
224 * collection.
223 */ 225 */
224 nameFor(object) => serialization._nameFor(object); 226 nameFor(object) => serialization._nameFor(object);
225 227
226 // For debugging/testing purposes. Find what state a reference points to. 228 // For debugging/testing purposes. Find what state a reference points to.
227 stateForReference(Reference r) => states[r.ruleNumber][r.objectNumber]; 229 stateForReference(Reference r) => states[r.ruleNumber][r.objectNumber];
228 230
229 /** Return the state pointed to by [reference]. */ 231 /** Return the state pointed to by [reference]. */
230 resolveReference(reference) => stateForReference(reference); 232 resolveReference(reference) => stateForReference(reference);
231 } 233 }
232 234
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 * Each rule has a number, and rules keep track of the objects that they 273 * Each rule has a number, and rules keep track of the objects that they
272 * serialize, in order. So the state of any object can be found by indexing 274 * serialize, in order. So the state of any object can be found by indexing
273 * from the rule number and the object number within the rule. 275 * from the rule number and the object number within the rule.
274 * The actual representation of the state is determined by the rule. Lists 276 * The actual representation of the state is determined by the rule. Lists
275 * and Maps are common, but it is arbitrary. See [Writer.states]. 277 * and Maps are common, but it is arbitrary. See [Writer.states].
276 */ 278 */
277 List<List> _data; 279 List<List> _data;
278 280
279 /** 281 /**
280 * The resulting objects, indexed according to the same scheme as 282 * The resulting objects, indexed according to the same scheme as
281 * [data], where each rule has a number, and rules keep track of the objects 283 * _data, where each rule has a number, and rules keep track of the objects
282 * that they serialize, in order. 284 * that they serialize, in order.
283 */ 285 */
284 List<List> objects; 286 List<List> objects;
285 287
286 Format format = new SimpleMapFormat(); 288 Format format = new SimpleMapFormat();
287 289
288 /** 290 /**
289 * Creates a new [Reader] that uses the rules from its parent 291 * Creates a new [Reader] that uses the rules from its parent
290 * [Serialization]. Serializations do not keep any state related to 292 * [Serialization]. Serializations do not keep any state related to
291 * a particular read or write operation, so the same one can be used 293 * a particular read or write operation, so the same one can be used
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 /** 574 /**
573 * Return the thing this reference points to. Assumes that we have a valid 575 * Return the thing this reference points to. Assumes that we have a valid
574 * parent and that it is a Reader, as inflating is not meaningful when 576 * parent and that it is a Reader, as inflating is not meaningful when
575 * writing. 577 * writing.
576 */ 578 */
577 inflated() => parent.resolveReference(this); 579 inflated() => parent.resolveReference(this);
578 580
579 /** 581 /**
580 * Convert the reference to a map in JSON format. This is specific to the 582 * Convert the reference to a map in JSON format. This is specific to the
581 * custom JSON format we define, and must be consistent with the 583 * custom JSON format we define, and must be consistent with the
582 * [asReference] method. 584 * [Reader.asReference] method.
583 */ 585 */
584 // TODO(alanknight): This is a hack both in defining a toJson specific to a 586 // TODO(alanknight): This is a hack both in defining a toJson specific to a
585 // particular representation, and the use of a bogus sentinel "__Ref" 587 // particular representation, and the use of a bogus sentinel "__Ref"
586 toJson() => { 588 toJson() => {
587 "__Ref" : true, 589 "__Ref" : true,
588 "rule" : ruleNumber, 590 "rule" : ruleNumber,
589 "object" : objectNumber 591 "object" : objectNumber
590 }; 592 };
591 593
592 /** Write our information to [list]. Useful in writing to flat formats.*/ 594 /** Write our information to [list]. Useful in writing to flat formats.*/
(...skipping 13 matching lines...) Expand all
606 * for an example. It knows how to return its object and how to filter. 608 * for an example. It knows how to return its object and how to filter.
607 */ 609 */
608 class DesignatedRuleForObject { 610 class DesignatedRuleForObject {
609 Function rulePredicate; 611 Function rulePredicate;
610 final target; 612 final target;
611 613
612 DesignatedRuleForObject(this.target, this.rulePredicate); 614 DesignatedRuleForObject(this.target, this.rulePredicate);
613 615
614 possibleRules(List rules) => rules.where(rulePredicate).toList(); 616 possibleRules(List rules) => rules.where(rulePredicate).toList();
615 } 617 }
OLDNEW
« no previous file with comments | « pkg/serialization/lib/src/format.dart ('k') | pkg/serialization/lib/src/serialization_rule.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698