OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Command-line tool to query for code dependencies. Currently this tool only | 5 /// Command-line tool to query for code dependencies. Currently this tool only |
6 /// supports the `some_path` query, which gives you the shortest path for how | 6 /// supports the `some_path` query, which gives you the shortest path for how |
7 /// one function depends on another. | 7 /// one function depends on another. |
8 /// | 8 /// |
9 /// You can run this tool as follows: | 9 /// You can run this tool as follows: |
10 /// ```bash | 10 /// ```bash |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 /// The info associated with the source element. | 89 /// The info associated with the source element. |
90 Info source; | 90 Info source; |
91 | 91 |
92 /// The info associated with the target element. | 92 /// The info associated with the target element. |
93 Info target; | 93 Info target; |
94 | 94 |
95 SomePathQuery(this.source, this.target); | 95 SomePathQuery(this.source, this.target); |
96 | 96 |
97 List<Info> run(Graph<Info> graph) { | 97 List<Info> run(Graph<Info> graph) { |
98 var seen = {source: null}; | 98 var seen = {source: null}; |
99 var queue = new Queue(); | 99 var queue = new Queue<Info>(); |
100 queue.addLast(source); | 100 queue.addLast(source); |
101 while (queue.isNotEmpty) { | 101 while (queue.isNotEmpty) { |
102 var node = queue.removeFirst(); | 102 var node = queue.removeFirst(); |
103 if (identical(node, target)) { | 103 if (identical(node, target)) { |
104 var result = new Queue(); | 104 var result = new Queue<Info>(); |
105 while (node != null) { | 105 while (node != null) { |
106 result.addFirst(node); | 106 result.addFirst(node); |
107 node = seen[node]; | 107 node = seen[node]; |
108 } | 108 } |
109 return result.toList(); | 109 return result.toList(); |
110 } | 110 } |
111 for (var neighbor in graph.targetsOf(node)) { | 111 for (var neighbor in graph.targetsOf(node)) { |
112 if (seen.containsKey(neighbor)) continue; | 112 if (seen.containsKey(neighbor)) continue; |
113 seen[neighbor] = node; | 113 seen[neighbor] = node; |
114 queue.addLast(neighbor); | 114 queue.addLast(neighbor); |
115 } | 115 } |
116 } | 116 } |
117 return []; | 117 return []; |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 _longNameMatcher(RegExp regexp) => (e) => regexp.hasMatch(longName(e)); | 121 typedef bool LongNameMatcher(FunctionInfo info); |
| 122 |
| 123 LongNameMatcher _longNameMatcher(RegExp regexp) => |
| 124 (e) => regexp.hasMatch(longName(e)); |
OLD | NEW |