| 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'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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 // find element references | 30 // find element references |
| 31 futureGroup.add(_findElementsReferences(element)); | 31 futureGroup.add(_findElementsReferences(element)); |
| 32 // add potential references | 32 // add potential references |
| 33 if (withPotential) { | 33 if (withPotential && _isMemberElement(element)) { |
| 34 String name = element.displayName; | 34 String name = element.displayName; |
| 35 var matchesFuture = searchEngine.searchMemberReferences(name); | 35 var matchesFuture = searchEngine.searchMemberReferences(name); |
| 36 var resultsFuture = matchesFuture.then((List<SearchMatch> matches) { | 36 var resultsFuture = matchesFuture.then((List<SearchMatch> matches) { |
| 37 return matches.where((match) => !match.isResolved).map(toResult); | 37 return matches.where((match) => !match.isResolved).map(toResult); |
| 38 }); | 38 }); |
| 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 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 new SourceRange(nameOffset, nameLength), | 98 new SourceRange(nameOffset, nameLength), |
| 99 true, | 99 true, |
| 100 false); | 100 false); |
| 101 return new SearchResult.fromMatch(searchMatch); | 101 return new SearchResult.fromMatch(searchMatch); |
| 102 } | 102 } |
| 103 | 103 |
| 104 static SearchResult toResult(SearchMatch match) { | 104 static SearchResult toResult(SearchMatch match) { |
| 105 return new SearchResult.fromMatch(match); | 105 return new SearchResult.fromMatch(match); |
| 106 } | 106 } |
| 107 | 107 |
| 108 static bool _isMemberElement(Element element) { |
| 109 return element.enclosingElement is ClassElement; |
| 110 } |
| 111 |
| 108 static bool _isVariableLikeElement(Element element) { | 112 static bool _isVariableLikeElement(Element element) { |
| 109 if (element is LocalVariableElement) { | 113 if (element is LocalVariableElement) { |
| 110 return true; | 114 return true; |
| 111 } | 115 } |
| 112 if (element is ParameterElement) { | 116 if (element is ParameterElement) { |
| 113 return true; | 117 return true; |
| 114 } | 118 } |
| 115 if (element is PropertyInducingElement) { | 119 if (element is PropertyInducingElement) { |
| 116 return !element.isSynthetic; | 120 return !element.isSynthetic; |
| 117 } | 121 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 135 * Adds a [Future] or an [E] value to results. | 139 * Adds a [Future] or an [E] value to results. |
| 136 */ | 140 */ |
| 137 void add(value) { | 141 void add(value) { |
| 138 if (value is Future) { | 142 if (value is Future) { |
| 139 _futures.add(value); | 143 _futures.add(value); |
| 140 } else { | 144 } else { |
| 141 _futures.add(new Future.value(<E>[value])); | 145 _futures.add(new Future.value(<E>[value])); |
| 142 } | 146 } |
| 143 } | 147 } |
| 144 } | 148 } |
| OLD | NEW |