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

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

Issue 2949823002: Remove unused implementation of SearchEngine and rename the driver-based implementation (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'dart:async';
6
7 import 'package:analysis_server/src/services/search/search_engine.dart';
8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/dart/analysis/driver.dart';
10 import 'package:analyzer/src/dart/analysis/search.dart';
11 import 'package:analyzer/src/generated/source.dart' show Source, SourceRange;
12
13 /**
14 * A [SearchEngine] implementation.
15 */
16 class SearchEngineImpl2 implements SearchEngine {
17 final Iterable<AnalysisDriver> _drivers;
18
19 SearchEngineImpl2(this._drivers);
20
21 @override
22 Future<Set<ClassElement>> searchAllSubtypes(ClassElement type) async {
23 Set<ClassElement> allSubtypes = new Set<ClassElement>();
24
25 Future<Null> addSubtypes(ClassElement type) async {
26 List<SearchResult> directResults = await _searchDirectSubtypes(type);
27 for (SearchResult directResult in directResults) {
28 var directSubtype = directResult.enclosingElement as ClassElement;
29 if (allSubtypes.add(directSubtype)) {
30 await addSubtypes(directSubtype);
31 }
32 }
33 }
34
35 await addSubtypes(type);
36 return allSubtypes;
37 }
38
39 @override
40 Future<List<SearchMatch>> searchMemberDeclarations(String name) async {
41 List<SearchMatch> allDeclarations = [];
42 List<AnalysisDriver> drivers = _drivers.toList();
43 for (AnalysisDriver driver in drivers) {
44 List<Element> elements = await driver.search.classMembers(name);
45 allDeclarations.addAll(elements.map(_SearchMatch.forElement));
46 }
47 return allDeclarations;
48 }
49
50 @override
51 Future<List<SearchMatch>> searchMemberReferences(String name) async {
52 List<SearchResult> allResults = [];
53 List<AnalysisDriver> drivers = _drivers.toList();
54 for (AnalysisDriver driver in drivers) {
55 List<SearchResult> results =
56 await driver.search.unresolvedMemberReferences(name);
57 allResults.addAll(results);
58 }
59 return allResults.map(_SearchMatch.forSearchResult).toList();
60 }
61
62 @override
63 Future<List<SearchMatch>> searchReferences(Element element) async {
64 List<SearchResult> allResults = [];
65 List<AnalysisDriver> drivers = _drivers.toList();
66 for (AnalysisDriver driver in drivers) {
67 List<SearchResult> results = await driver.search.references(element);
68 allResults.addAll(results);
69 }
70 return allResults.map(_SearchMatch.forSearchResult).toList();
71 }
72
73 @override
74 Future<List<SearchMatch>> searchSubtypes(ClassElement type) async {
75 List<SearchResult> results = await _searchDirectSubtypes(type);
76 return results.map(_SearchMatch.forSearchResult).toList();
77 }
78
79 @override
80 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) async {
81 List<SearchMatch> allDeclarations = [];
82 RegExp regExp = new RegExp(pattern);
83 List<AnalysisDriver> drivers = _drivers.toList();
84 for (AnalysisDriver driver in drivers) {
85 List<Element> elements = await driver.search.topLevelElements(regExp);
86 allDeclarations.addAll(elements.map(_SearchMatch.forElement));
87 }
88 return allDeclarations;
89 }
90
91 Future<List<SearchResult>> _searchDirectSubtypes(ClassElement type) async {
92 List<SearchResult> allResults = [];
93 List<AnalysisDriver> drivers = _drivers.toList();
94 for (AnalysisDriver driver in drivers) {
95 List<SearchResult> results = await driver.search.subTypes(type);
96 allResults.addAll(results);
97 }
98 return allResults;
99 }
100 }
101
102 class _SearchMatch implements SearchMatch {
103 @override
104 final String file;
105
106 @override
107 final Source librarySource;
108
109 @override
110 final Source unitSource;
111
112 @override
113 final LibraryElement libraryElement;
114
115 @override
116 final Element element;
117
118 @override
119 final bool isResolved;
120
121 @override
122 final bool isQualified;
123
124 @override
125 final MatchKind kind;
126
127 @override
128 final SourceRange sourceRange;
129
130 _SearchMatch(
131 this.file,
132 this.librarySource,
133 this.unitSource,
134 this.libraryElement,
135 this.element,
136 this.isResolved,
137 this.isQualified,
138 this.kind,
139 this.sourceRange);
140
141 @override
142 String toString() {
143 StringBuffer buffer = new StringBuffer();
144 buffer.write("SearchMatch(kind=");
145 buffer.write(kind);
146 buffer.write(", libraryUri=");
147 buffer.write(librarySource.uri);
148 buffer.write(", unitUri=");
149 buffer.write(unitSource.uri);
150 buffer.write(", range=");
151 buffer.write(sourceRange);
152 buffer.write(", isResolved=");
153 buffer.write(isResolved);
154 buffer.write(", isQualified=");
155 buffer.write(isQualified);
156 buffer.write(")");
157 return buffer.toString();
158 }
159
160 static _SearchMatch forElement(Element element) {
161 return new _SearchMatch(
162 element.source.fullName,
163 element.librarySource,
164 element.source,
165 element.library,
166 element,
167 true,
168 true,
169 MatchKind.DECLARATION,
170 new SourceRange(element.nameOffset, element.nameLength));
171 }
172
173 static _SearchMatch forSearchResult(SearchResult result) {
174 Element enclosingElement = result.enclosingElement;
175 return new _SearchMatch(
176 enclosingElement.source.fullName,
177 enclosingElement.librarySource,
178 enclosingElement.source,
179 enclosingElement.library,
180 enclosingElement,
181 result.isResolved,
182 result.isQualified,
183 toMatchKind(result.kind),
184 new SourceRange(result.offset, result.length));
185 }
186
187 static MatchKind toMatchKind(SearchResultKind kind) {
188 if (kind == SearchResultKind.READ) {
189 return MatchKind.READ;
190 }
191 if (kind == SearchResultKind.READ_WRITE) {
192 return MatchKind.READ_WRITE;
193 }
194 if (kind == SearchResultKind.WRITE) {
195 return MatchKind.WRITE;
196 }
197 if (kind == SearchResultKind.INVOCATION) {
198 return MatchKind.INVOCATION;
199 }
200 return MatchKind.REFERENCE;
201 }
202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698