| 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 tree; | 5 part of tree; |
| 6 | 6 |
| 7 abstract class Visitor<R> { | 7 abstract class Visitor<R> { |
| 8 const Visitor(); | 8 const Visitor(); |
| 9 | 9 |
| 10 R visitNode(Node node); | 10 R visitNode(Node node); |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 466 } |
| 467 return beginToken; | 467 return beginToken; |
| 468 } | 468 } |
| 469 | 469 |
| 470 // ------------------- Iterable methods ------------------------------------- | 470 // ------------------- Iterable methods ------------------------------------- |
| 471 // | 471 // |
| 472 // TODO(floitsch): these functions should be pulled in through a mixin | 472 // TODO(floitsch): these functions should be pulled in through a mixin |
| 473 // mechanism. | 473 // mechanism. |
| 474 Iterable mappedBy(f(Node element)) => new MappedIterable(this, f); | 474 Iterable mappedBy(f(Node element)) => new MappedIterable(this, f); |
| 475 | 475 |
| 476 Collection<Node> where(bool f(Node element)) { | 476 Iterable<Node> where(bool f(Node element)) |
| 477 List result = <Node>[]; | 477 => new WhereIterable<Node>(this, f); |
| 478 for (Node element in this) if (f(element)) result.add(element); | |
| 479 return result; | |
| 480 } | |
| 481 | 478 |
| 482 bool contains(Node element) { | 479 bool contains(Node element) { |
| 483 for (Node e in this) { | 480 for (Node e in this) { |
| 484 if (e == element) return true; | 481 if (e == element) return true; |
| 485 } | 482 } |
| 486 return false; | 483 return false; |
| 487 } | 484 } |
| 488 | 485 |
| 489 void forEach(void f(Node element)) { | 486 void forEach(void f(Node element)) { |
| 490 for (Node element in this) f(element); | 487 for (Node element in this) f(element); |
| (...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 * argument). | 2039 * argument). |
| 2043 * | 2040 * |
| 2044 * TODO(ahe): This method is controversial, the team needs to discuss | 2041 * TODO(ahe): This method is controversial, the team needs to discuss |
| 2045 * if top-level methods are acceptable and what naming conventions to | 2042 * if top-level methods are acceptable and what naming conventions to |
| 2046 * use. | 2043 * use. |
| 2047 */ | 2044 */ |
| 2048 initializerDo(Node node, f(Node node)) { | 2045 initializerDo(Node node, f(Node node)) { |
| 2049 SendSet send = node.asSendSet(); | 2046 SendSet send = node.asSendSet(); |
| 2050 if (send != null) return f(send.arguments.head); | 2047 if (send != null) return f(send.arguments.head); |
| 2051 } | 2048 } |
| OLD | NEW |