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

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

Issue 2521363003: Implement SearchEngine for the new driver. (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
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<List<SearchMatch>> searchAllSubtypes(ClassElement type) async {
23 // TODO(scheglov) implement
24 return [];
25 }
26
27 @override
28 Future<List<SearchMatch>> searchMemberDeclarations(String name) async {
29 // TODO(scheglov) implement
30 return [];
31 }
32
33 @override
34 Future<List<SearchMatch>> searchMemberReferences(String name) async {
35 // TODO(scheglov) implement
36 return [];
37 }
38
39 @override
40 Future<List<SearchMatch>> searchReferences(Element element) async {
41 List<SearchResult> allResults = [];
42 for (AnalysisDriver driver in _drivers) {
43 List<SearchResult> results = await driver.search.references(element);
44 allResults.addAll(results);
45 }
46 return allResults.map(_SearchMatch.forSearchResult).toList();
47 }
48
49 @override
50 Future<List<SearchMatch>> searchSubtypes(ClassElement type) async {
51 // TODO(scheglov) implement
52 return [];
53 }
54
55 @override
56 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) async {
57 // TODO(scheglov) implement
58 return [];
59 }
60 }
61
62 class _SearchMatch implements SearchMatch {
63 @override
64 final String file;
65
66 @override
67 final Source librarySource;
68
69 @override
70 final Source unitSource;
71
72 @override
73 final LibraryElement libraryElement;
74
75 @override
76 final Element element;
77
78 @override
79 final bool isResolved;
80
81 @override
82 final bool isQualified;
83
84 @override
85 final MatchKind kind;
86
87 @override
88 final SourceRange sourceRange;
89
90 _SearchMatch(
91 this.file,
92 this.librarySource,
93 this.unitSource,
94 this.libraryElement,
95 this.element,
96 this.isResolved,
97 this.isQualified,
98 this.kind,
99 this.sourceRange);
100
101 @override
102 String toString() {
103 StringBuffer buffer = new StringBuffer();
104 buffer.write("SearchMatch(kind=");
105 buffer.write(kind);
106 buffer.write(", libraryUri=");
107 buffer.write(librarySource.uri);
108 buffer.write(", unitUri=");
109 buffer.write(unitSource.uri);
110 buffer.write(", range=");
111 buffer.write(sourceRange);
112 buffer.write(", isResolved=");
113 buffer.write(isResolved);
114 buffer.write(", isQualified=");
115 buffer.write(isQualified);
116 buffer.write(")");
117 return buffer.toString();
118 }
119
120 static _SearchMatch forSearchResult(SearchResult result) {
121 Element enclosingElement = result.enclosingElement;
122 return new _SearchMatch(
123 enclosingElement.source.fullName,
124 enclosingElement.librarySource,
125 enclosingElement.source,
126 enclosingElement.library,
127 enclosingElement,
128 result.isResolved,
129 result.isQualified,
130 toMatchKind(result.kind),
131 new SourceRange(result.offset, result.length));
132 }
133
134 static MatchKind toMatchKind(SearchResultKind kind) {
135 if (kind == SearchResultKind.READ) {
136 return MatchKind.READ;
137 }
138 if (kind == SearchResultKind.READ_WRITE) {
139 return MatchKind.READ_WRITE;
140 }
141 if (kind == SearchResultKind.WRITE) {
142 return MatchKind.WRITE;
143 }
144 if (kind == SearchResultKind.INVOCATION) {
145 return MatchKind.INVOCATION;
146 }
147 return MatchKind.REFERENCE;
148 }
149 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/search/search_domain.dart ('k') | pkg/analyzer/lib/src/dart/analysis/search.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698