Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: pkg/analysis_server/lib/src/search/element_references.dart

Issue 2518183003: Stop returning declaration matches from search for references. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/search/element_references_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/protocol_server.dart' 9 import 'package:analysis_server/src/protocol_server.dart'
10 show SearchResult, newSearchResult_fromMatch; 10 show SearchResult, newSearchResult_fromMatch;
11 import 'package:analysis_server/src/services/search/hierarchy.dart'; 11 import 'package:analysis_server/src/services/search/hierarchy.dart';
12 import 'package:analysis_server/src/services/search/search_engine.dart'; 12 import 'package:analysis_server/src/services/search/search_engine.dart';
13 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ;
14 import 'package:analyzer/dart/element/element.dart'; 13 import 'package:analyzer/dart/element/element.dart';
15 import 'package:analyzer/src/generated/source.dart';
16 14
17 /** 15 /**
18 * A computer for `search.findElementReferences` request results. 16 * A computer for `search.findElementReferences` request results.
19 */ 17 */
20 class ElementReferencesComputer { 18 class ElementReferencesComputer {
21 final SearchEngine searchEngine; 19 final SearchEngine searchEngine;
22 20
23 ElementReferencesComputer(this.searchEngine); 21 ElementReferencesComputer(this.searchEngine);
24 22
25 /** 23 /**
(...skipping 19 matching lines...) Expand all
45 } 43 }
46 44
47 /** 45 /**
48 * 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
49 * to the corresponding hierarchy [Element]s. 47 * to the corresponding hierarchy [Element]s.
50 */ 48 */
51 Future<List<SearchResult>> _findElementsReferences(Element element) async { 49 Future<List<SearchResult>> _findElementsReferences(Element element) async {
52 List<SearchResult> allResults = <SearchResult>[]; 50 List<SearchResult> allResults = <SearchResult>[];
53 Iterable<Element> refElements = await _getRefElements(element); 51 Iterable<Element> refElements = await _getRefElements(element);
54 for (Element refElement in refElements) { 52 for (Element refElement in refElements) {
55 // add declaration
56 if (_isDeclarationInteresting(refElement)) {
57 SearchResult searchResult = _newDeclarationResult(refElement);
58 allResults.add(searchResult);
59 }
60 // do search
61 List<SearchResult> elementResults = 53 List<SearchResult> elementResults =
62 await _findSingleElementReferences(refElement); 54 await _findSingleElementReferences(refElement);
63 allResults.addAll(elementResults); 55 allResults.addAll(elementResults);
64 } 56 }
65 return allResults; 57 return allResults;
66 } 58 }
67 59
68 /** 60 /**
69 * Returns a [Future] completing with a [List] of references to [element]. 61 * Returns a [Future] completing with a [List] of references to [element].
70 */ 62 */
(...skipping 12 matching lines...) Expand all
83 * 75 *
84 * Otherwise, only references to [element] should be searched. 76 * Otherwise, only references to [element] should be searched.
85 */ 77 */
86 Future<Iterable<Element>> _getRefElements(Element element) { 78 Future<Iterable<Element>> _getRefElements(Element element) {
87 if (element is ClassMemberElement) { 79 if (element is ClassMemberElement) {
88 return getHierarchyMembers(searchEngine, element); 80 return getHierarchyMembers(searchEngine, element);
89 } 81 }
90 return new Future.value([element]); 82 return new Future.value([element]);
91 } 83 }
92 84
93 SearchResult _newDeclarationResult(Element refElement) {
94 int nameOffset = refElement.nameOffset;
95 int nameLength = refElement.nameLength;
96 SearchMatch searchMatch = new SearchMatchImpl(
97 refElement.context,
98 refElement.library.source.uri.toString(),
99 refElement.source.uri.toString(),
100 MatchKind.DECLARATION,
101 new SourceRange(nameOffset, nameLength),
102 true,
103 false);
104 return newSearchResult_fromMatch(searchMatch);
105 }
106
107 static SearchResult toResult(SearchMatch match) { 85 static SearchResult toResult(SearchMatch match) {
108 return newSearchResult_fromMatch(match); 86 return newSearchResult_fromMatch(match);
109 } 87 }
110 88
111 static bool _isDeclarationInteresting(Element element) {
112 if (element is LabelElement) {
113 return true;
114 }
115 if (element is LocalVariableElement) {
116 return true;
117 }
118 if (element is ParameterElement) {
119 return true;
120 }
121 if (element is PrefixElement) {
122 return true;
123 }
124 if (element is PropertyInducingElement) {
125 return !element.isSynthetic;
126 }
127 return false;
128 }
129
130 static bool _isMemberElement(Element element) { 89 static bool _isMemberElement(Element element) {
131 if (element is ConstructorElement) { 90 if (element is ConstructorElement) {
132 return false; 91 return false;
133 } 92 }
134 return element.enclosingElement is ClassElement; 93 return element.enclosingElement is ClassElement;
135 } 94 }
136 } 95 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/search/element_references_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698