@@ -6,7 +6,6 @@ library search.element_references;
6
6
7
7
import 'dart:async' ;
8
8
9
- import 'package:analysis_server/src/collections.dart' ;
10
9
import 'package:analysis_server/src/protocol_server.dart'
11
10
show SearchResult, newSearchResult_fromMatch;
12
11
import 'package:analysis_server/src/services/search/hierarchy.dart' ;
@@ -25,40 +24,44 @@ class ElementReferencesComputer {
25
24
/**
26
25
* Computes [SearchResult] s for [element] references.
27
26
*/
28
- Future <List <SearchResult >> compute (Element element, bool withPotential) {
29
- var futureGroup = new _ConcatFutureGroup <SearchResult >();
30
- // find element references
31
- futureGroup.add (_findElementsReferences (element));
32
- // add potential references
27
+ Future <List <SearchResult >> compute (
28
+ Element element, bool withPotential) async {
29
+ List <SearchResult > results = < SearchResult > [];
30
+
31
+ // Add element references.
32
+ results.addAll (await _findElementsReferences (element));
33
+
34
+ // Add potential references.
33
35
if (withPotential && _isMemberElement (element)) {
34
36
String name = element.displayName;
35
- var matchesFuture = searchEngine.searchMemberReferences (name);
36
- var resultsFuture = matchesFuture.then ((List <SearchMatch > matches) {
37
- return matches.where ((match) => ! match.isResolved).map (toResult);
38
- });
39
- futureGroup.add (resultsFuture);
37
+ List <SearchMatch > matches =
38
+ await searchEngine.searchMemberReferences (name);
39
+ matches = SearchMatch .withNotNullElement (matches);
40
+ results.addAll (matches.where ((match) => ! match.isResolved).map (toResult));
40
41
}
41
- // merge results
42
- return futureGroup.future ;
42
+
43
+ return results ;
43
44
}
44
45
45
46
/**
46
47
* Returns a [Future] completing with a [List] of references to [element] or
47
48
* to the corresponding hierarchy [Element] s.
48
49
*/
49
50
Future <List <SearchResult >> _findElementsReferences (Element element) async {
51
+ List <SearchResult > allResults = < SearchResult > [];
50
52
Iterable <Element > refElements = await _getRefElements (element);
51
- var futureGroup = new _ConcatFutureGroup <SearchResult >();
52
53
for (Element refElement in refElements) {
53
54
// add declaration
54
55
if (_isDeclarationInteresting (refElement)) {
55
56
SearchResult searchResult = _newDeclarationResult (refElement);
56
- futureGroup .add (searchResult);
57
+ allResults .add (searchResult);
57
58
}
58
59
// do search
59
- futureGroup.add (_findSingleElementReferences (refElement));
60
+ List <SearchResult > elementResults =
61
+ await _findSingleElementReferences (refElement);
62
+ allResults.addAll (elementResults);
60
63
}
61
- return futureGroup.future ;
64
+ return allResults ;
62
65
}
63
66
64
67
/**
@@ -67,6 +70,7 @@ class ElementReferencesComputer {
67
70
Future <List <SearchResult >> _findSingleElementReferences (
68
71
Element element) async {
69
72
List <SearchMatch > matches = await searchEngine.searchReferences (element);
73
+ matches = SearchMatch .withNotNullElement (matches);
70
74
return matches.map (toResult).toList ();
71
75
}
72
76
@@ -129,26 +133,3 @@ class ElementReferencesComputer {
129
133
return element.enclosingElement is ClassElement ;
130
134
}
131
135
}
132
-
133
- /**
134
- * A collection of [Future] s that concats [List] results of added [Future] s into
135
- * a single [List] .
136
- */
137
- class _ConcatFutureGroup <E > {
138
- final List <Future <List <E >>> _futures = < Future <List <E >>> [];
139
-
140
- Future <List <E >> get future {
141
- return Future .wait (_futures).then (concatToList);
142
- }
143
-
144
- /**
145
- * Adds a [Future] or an [E] value to results.
146
- */
147
- void add (value) {
148
- if (value is Future ) {
149
- _futures.add (value as Future <List <E >>);
150
- } else {
151
- _futures.add (new Future .value (< E > [value as E ]));
152
- }
153
- }
154
- }
0 commit comments