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

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

Issue 975753002: Some clean-ups for Index / SearchEngine. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months 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 | Annotate | Revision Log
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 services.src.search.search_engine; 5 library services.src.search.search_engine;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/search/search_engine.dart'; 10 import 'package:analysis_server/src/services/search/search_engine.dart';
11 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/source.dart'; 12 import 'package:analyzer/src/generated/source.dart';
13 import 'package:analysis_server/src/services/correction/source_range.dart';
13 14
14 /** 15 /**
15 * A [SearchEngine] implementation. 16 * A [SearchEngine] implementation.
16 */ 17 */
17 class SearchEngineImpl implements SearchEngine { 18 class SearchEngineImpl implements SearchEngine {
18 final Index _index; 19 final Index _index;
19 20
20 SearchEngineImpl(this._index); 21 SearchEngineImpl(this._index);
21 22
22 @override 23 @override
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 requestor.add(type, IndexConstants.IS_IMPLEMENTED_BY, MatchKind.REFERENCE); 96 requestor.add(type, IndexConstants.IS_IMPLEMENTED_BY, MatchKind.REFERENCE);
96 return requestor.merge(); 97 return requestor.merge();
97 } 98 }
98 99
99 @override 100 @override
100 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) { 101 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) {
101 RegExp regExp = new RegExp(pattern); 102 RegExp regExp = new RegExp(pattern);
102 List<Element> elements = 103 List<Element> elements =
103 _index.getTopLevelDeclarations((String name) => regExp.hasMatch(name)); 104 _index.getTopLevelDeclarations((String name) => regExp.hasMatch(name));
104 List<SearchMatch> matches = <SearchMatch>[]; 105 List<SearchMatch> matches = <SearchMatch>[];
105 for (var element in elements) { 106 for (Element element in elements) {
106 SourceRange range = 107 matches.add(new SearchMatch(MatchKind.DECLARATION, element,
107 new SourceRange(element.nameOffset, element.name.length); 108 rangeElementName(element), true, false));
108 matches.add(
109 new SearchMatch(MatchKind.DECLARATION, element, range, true, false));
110 } 109 }
111 // TODO(scheglov) it does not have to be a Future
112 return new Future.value(matches); 110 return new Future.value(matches);
113 } 111 }
114 112
115 Future<List<SearchMatch>> _searchReferences(Element element) { 113 Future<List<SearchMatch>> _searchReferences(Element element) {
116 _Requestor requestor = new _Requestor(_index); 114 _Requestor requestor = new _Requestor(_index);
117 requestor.add( 115 requestor.add(
118 element, IndexConstants.IS_REFERENCED_BY, MatchKind.REFERENCE); 116 element, IndexConstants.IS_REFERENCED_BY, MatchKind.REFERENCE);
119 return requestor.merge(); 117 return requestor.merge();
120 } 118 }
121 119
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 }); 210 });
213 futures.add(matchesFuture); 211 futures.add(matchesFuture);
214 } 212 }
215 213
216 Future<List<SearchMatch>> merge() { 214 Future<List<SearchMatch>> merge() {
217 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { 215 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) {
218 return matchesList.expand((matches) => matches).toList(); 216 return matchesList.expand((matches) => matches).toList();
219 }); 217 });
220 } 218 }
221 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698