| 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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 if (link.head.getEndToken() != null) return link.head.getEndToken(); | 464 if (link.head.getEndToken() != null) return link.head.getEndToken(); |
| 465 if (link.head.getBeginToken() != null) return link.head.getBeginToken(); | 465 if (link.head.getBeginToken() != null) return link.head.getBeginToken(); |
| 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 Collection mappedBy(f(Node element)) { | 474 Iterable mappedBy(f(Node element)) => new MappedIterable(this, f); |
| 475 List result = []; | |
| 476 for (Node element in this) result.add(f(element)); | |
| 477 return result; | |
| 478 } | |
| 479 | 475 |
| 480 Collection<Node> where(bool f(Node element)) { | 476 Collection<Node> where(bool f(Node element)) { |
| 481 List result = <Node>[]; | 477 List result = <Node>[]; |
| 482 for (Node element in this) if (f(element)) result.add(element); | 478 for (Node element in this) if (f(element)) result.add(element); |
| 483 return result; | 479 return result; |
| 484 } | 480 } |
| 485 | 481 |
| 486 bool contains(Node element) { | 482 bool contains(Node element) { |
| 487 for (Node e in this) { | 483 for (Node e in this) { |
| 488 if (e == element) return true; | 484 if (e == element) return true; |
| (...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 * argument). | 2042 * argument). |
| 2047 * | 2043 * |
| 2048 * TODO(ahe): This method is controversial, the team needs to discuss | 2044 * TODO(ahe): This method is controversial, the team needs to discuss |
| 2049 * if top-level methods are acceptable and what naming conventions to | 2045 * if top-level methods are acceptable and what naming conventions to |
| 2050 * use. | 2046 * use. |
| 2051 */ | 2047 */ |
| 2052 initializerDo(Node node, f(Node node)) { | 2048 initializerDo(Node node, f(Node node)) { |
| 2053 SendSet send = node.asSendSet(); | 2049 SendSet send = node.asSendSet(); |
| 2054 if (send != null) return f(send.arguments.head); | 2050 if (send != null) return f(send.arguments.head); |
| 2055 } | 2051 } |
| OLD | NEW |