| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library search.element_references; | 5 library search.element_references; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/collections.dart'; | 9 import 'package:analysis_server/src/collections.dart'; |
| 10 import 'package:analysis_server/src/protocol_server.dart' | 10 import 'package:analysis_server/src/protocol_server.dart' |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 futureGroup.add(resultsFuture); | 39 futureGroup.add(resultsFuture); |
| 40 } | 40 } |
| 41 // merge results | 41 // merge results |
| 42 return futureGroup.future; | 42 return futureGroup.future; |
| 43 } | 43 } |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * Returns a [Future] completing with a [List] of references to [element] or | 46 * Returns a [Future] completing with a [List] of references to [element] or |
| 47 * to the corresponding hierarchy [Element]s. | 47 * to the corresponding hierarchy [Element]s. |
| 48 */ | 48 */ |
| 49 Future<List<SearchResult>> _findElementsReferences(Element element) { | 49 Future<List<SearchResult>> _findElementsReferences(Element element) async { |
| 50 return _getRefElements(element).then((Iterable<Element> refElements) { | 50 Iterable<Element> refElements = await _getRefElements(element); |
| 51 var futureGroup = new _ConcatFutureGroup<SearchResult>(); | 51 var futureGroup = new _ConcatFutureGroup<SearchResult>(); |
| 52 for (Element refElement in refElements) { | 52 for (Element refElement in refElements) { |
| 53 // add declaration | 53 // add declaration |
| 54 if (_isDeclarationInteresting(refElement)) { | 54 if (_isDeclarationInteresting(refElement)) { |
| 55 SearchResult searchResult = _newDeclarationResult(refElement); | 55 SearchResult searchResult = _newDeclarationResult(refElement); |
| 56 futureGroup.add(searchResult); | 56 futureGroup.add(searchResult); |
| 57 } | |
| 58 // do search | |
| 59 futureGroup.add(_findSingleElementReferences(refElement)); | |
| 60 } | 57 } |
| 61 return futureGroup.future; | 58 // do search |
| 62 }); | 59 futureGroup.add(_findSingleElementReferences(refElement)); |
| 60 } |
| 61 return futureGroup.future; |
| 63 } | 62 } |
| 64 | 63 |
| 65 /** | 64 /** |
| 66 * Returns a [Future] completing with a [List] of references to [element]. | 65 * Returns a [Future] completing with a [List] of references to [element]. |
| 67 */ | 66 */ |
| 68 Future<List<SearchResult>> _findSingleElementReferences(Element element) { | 67 Future<List<SearchResult>> _findSingleElementReferences(Element element) { |
| 69 Future<List<SearchMatch>> matchesFuture = | 68 Future<List<SearchMatch>> matchesFuture = |
| 70 searchEngine.searchReferences(element); | 69 searchEngine.searchReferences(element); |
| 71 return matchesFuture.then((List<SearchMatch> matches) { | 70 return matchesFuture.then((List<SearchMatch> matches) { |
| 72 return matches.map(toResult).toList(); | 71 return matches.map(toResult).toList(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 141 |
| 143 Future<List<E>> get future { | 142 Future<List<E>> get future { |
| 144 return Future.wait(_futures).then(concatToList); | 143 return Future.wait(_futures).then(concatToList); |
| 145 } | 144 } |
| 146 | 145 |
| 147 /** | 146 /** |
| 148 * Adds a [Future] or an [E] value to results. | 147 * Adds a [Future] or an [E] value to results. |
| 149 */ | 148 */ |
| 150 void add(value) { | 149 void add(value) { |
| 151 if (value is Future) { | 150 if (value is Future) { |
| 152 _futures.add(value); | 151 _futures.add(value as Future<List<E>>); |
| 153 } else { | 152 } else { |
| 154 _futures.add(new Future.value(<E>[value])); | 153 _futures.add(new Future.value(<E>[value as E])); |
| 155 } | 154 } |
| 156 } | 155 } |
| 157 } | 156 } |
| OLD | NEW |