| 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 /** | 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 * This class works by doing a breadth-first traversal of the objects, | 502 * This class works by doing a breadth-first traversal of the objects, |
| 503 * with the traversal order maintained in [queue]. | 503 * with the traversal order maintained in [queue]. |
| 504 */ | 504 */ |
| 505 final Queue queue = new Queue(); | 505 final Queue queue = new Queue(); |
| 506 | 506 |
| 507 /** The root objects from which we will be tracing. */ | 507 /** The root objects from which we will be tracing. */ |
| 508 final List roots = []; | 508 final List roots = []; |
| 509 | 509 |
| 510 Trace(this.writer); | 510 Trace(this.writer); |
| 511 | 511 |
| 512 addRoot(object) { | 512 void addRoot(object) { |
| 513 roots.add(object); | 513 roots.add(object); |
| 514 } | 514 } |
| 515 | 515 |
| 516 /** A convenience method to add a single root and trace it in one step. */ | 516 /** A convenience method to add a single root and trace it in one step. */ |
| 517 trace(object) { | 517 void trace(object) { |
| 518 addRoot(object); | 518 addRoot(object); |
| 519 traceAll(); | 519 traceAll(); |
| 520 } | 520 } |
| 521 | 521 |
| 522 /** | 522 /** |
| 523 * Process all of the objects reachable from our roots via state that the | 523 * Process all of the objects reachable from our roots via state that the |
| 524 * serialization rules access. | 524 * serialization rules access. |
| 525 */ | 525 */ |
| 526 traceAll() { | 526 void traceAll() { |
| 527 queue.addAll(roots); | 527 queue.addAll(roots); |
| 528 while (!queue.isEmpty) { | 528 while (!queue.isEmpty) { |
| 529 var next = queue.removeFirst(); | 529 var next = queue.removeFirst(); |
| 530 if (!hasProcessed(next)) writer._process(next, this); | 530 if (!hasProcessed(next)) writer._process(next, this); |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 | 533 |
| 534 /** | 534 /** |
| 535 * Has this object been seen yet? We test for this by checking if the | 535 * Has this object been seen yet? We test for this by checking if the |
| 536 * writer has a reference for it. See comment for _hasIndexFor. | 536 * writer has a reference for it. See comment for _hasIndexFor. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 * 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. |
| 609 */ | 609 */ |
| 610 class DesignatedRuleForObject { | 610 class DesignatedRuleForObject { |
| 611 final Function rulePredicate; | 611 final Function rulePredicate; |
| 612 final target; | 612 final target; |
| 613 | 613 |
| 614 DesignatedRuleForObject(this.target, this.rulePredicate); | 614 DesignatedRuleForObject(this.target, this.rulePredicate); |
| 615 | 615 |
| 616 List possibleRules(List rules) => rules.where(rulePredicate).toList(); | 616 List possibleRules(List rules) => rules.where(rulePredicate).toList(); |
| 617 } | 617 } |
| OLD | NEW |