| 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/search/search_result.dart'; | 10 import 'package:analysis_server/src/search/search_result.dart'; |
| 11 import 'package:analysis_services/search/hierarchy.dart'; | 11 import 'package:analysis_services/search/hierarchy.dart'; |
| 12 import 'package:analysis_services/search/search_engine.dart'; | 12 import 'package:analysis_services/search/search_engine.dart'; |
| 13 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 | 15 |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * A computer for `search.findElementReferences` request results. | 18 * A computer for `search.findElementReferences` request results. |
| 19 */ | 19 */ |
| 20 class ElementReferencesComputer { | 20 class ElementReferencesComputer { |
| 21 final SearchEngine searchEngine; | 21 final SearchEngine searchEngine; |
| 22 | 22 |
| 23 ElementReferencesComputer(this.searchEngine); | 23 ElementReferencesComputer(this.searchEngine); |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Computes [SearchResult]s for [element] references. | 26 * Computes [SearchResult]s for [element] references. |
| 27 */ | 27 */ |
| 28 Future<List<SearchResult>> compute(Element element, bool withPotential) { | 28 Future<List<SearchResult>> compute(Element element, bool withPotential) { |
| 29 var futureGroup = new _ConcatFutureGroup<SearchResult>(); | 29 var futureGroup = new _ConcatFutureGroup<SearchResult>(); |
| 30 // tweak element | |
| 31 if (element is FieldFormalParameterElement) { | |
| 32 element = (element as FieldFormalParameterElement).field; | |
| 33 } | |
| 34 if (element is PropertyAccessorElement) { | |
| 35 element = (element as PropertyAccessorElement).variable; | |
| 36 } | |
| 37 // find element references | 30 // find element references |
| 38 futureGroup.add(_findElementsReferences(element)); | 31 futureGroup.add(_findElementsReferences(element)); |
| 39 // add potential references | 32 // add potential references |
| 40 if (withPotential) { | 33 if (withPotential) { |
| 41 String name = element.displayName; | 34 String name = element.displayName; |
| 42 var matchesFuture = searchEngine.searchMemberReferences(name); | 35 var matchesFuture = searchEngine.searchMemberReferences(name); |
| 43 var resultsFuture = matchesFuture.then((List<SearchMatch> matches) { | 36 var resultsFuture = matchesFuture.then((List<SearchMatch> matches) { |
| 44 return matches.where((match) => !match.isResolved).map(toResult); | 37 return matches.where((match) => !match.isResolved).map(toResult); |
| 45 }); | 38 }); |
| 46 futureGroup.add(resultsFuture); | 39 futureGroup.add(resultsFuture); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 * Adds a [Future] or an [E] value to results. | 135 * Adds a [Future] or an [E] value to results. |
| 143 */ | 136 */ |
| 144 void add(value) { | 137 void add(value) { |
| 145 if (value is Future) { | 138 if (value is Future) { |
| 146 _futures.add(value); | 139 _futures.add(value); |
| 147 } else { | 140 } else { |
| 148 _futures.add(new Future.value(<E>[value])); | 141 _futures.add(new Future.value(<E>[value])); |
| 149 } | 142 } |
| 150 } | 143 } |
| 151 } | 144 } |
| OLD | NEW |