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

Side by Side Diff: pkg/analysis_services/lib/search/search_engine.dart

Issue 484733003: Import analysis_services.dart into analysis_server.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library services.search_engine;
6
7 import 'dart:async';
8
9 import 'package:analysis_services/index/index.dart';
10 import 'package:analysis_services/src/search/search_engine.dart';
11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/java_core.dart';
13 import 'package:analyzer/src/generated/source.dart';
14
15
16 /**
17 * Returns a new [SearchEngine] instance based on the given [Index].
18 */
19 SearchEngine createSearchEngine(Index index) {
20 return new SearchEngineImpl(index);
21 }
22
23
24 /**
25 * Instances of the enum [MatchKind] represent the kind of reference that was
26 * found when a match represents a reference to an element.
27 */
28 class MatchKind {
29 /**
30 * A reference to an Angular element.
31 */
32 static const MatchKind ANGULAR_REFERENCE =
33 const MatchKind('ANGULAR_REFERENCE');
34
35 /**
36 * A reference to an Angular element.
37 */
38 static const MatchKind ANGULAR_CLOSING_TAG_REFERENCE =
39 const MatchKind('ANGULAR_CLOSING_TAG_REFERENCE');
40
41 /**
42 * A declaration of an element.
43 */
44 static const MatchKind DECLARATION = const MatchKind('DECLARATION');
45
46 /**
47 * A reference to an element in which it is being read.
48 */
49 static const MatchKind READ = const MatchKind('READ');
50
51 /**
52 * A reference to an element in which it is being both read and written.
53 */
54 static const MatchKind READ_WRITE = const MatchKind('READ_WRITE');
55
56 /**
57 * A reference to an element in which it is being written.
58 */
59 static const MatchKind WRITE = const MatchKind('WRITE');
60
61 /**
62 * A reference to an element in which it is being invoked.
63 */
64 static const MatchKind INVOCATION = const MatchKind('INVOCATION');
65
66 /**
67 * A reference to an element in which it is referenced.
68 */
69 static const MatchKind REFERENCE = const MatchKind('REFERENCE');
70
71 final String name;
72
73 const MatchKind(this.name);
74
75 @override
76 String toString() => name;
77 }
78
79
80 /**
81 * The interface [SearchEngine] defines the behavior of objects that can be used
82 * to search for various pieces of information.
83 */
84 abstract class SearchEngine {
85 /**
86 * Returns declarations of elements with the given name.
87 *
88 * [name] - the name being declared by the found matches.
89 */
90 Future<List<SearchMatch>> searchElementDeclarations(String name);
91
92 /**
93 * Returns declarations of class members with the given name.
94 *
95 * [name] - the name being declared by the found matches.
96 */
97 Future<List<SearchMatch>> searchMemberDeclarations(String name);
98
99 /**
100 * Returns all resolved and unresolved qualified references to the class
101 * members with given [name].
102 *
103 * [name] - the name being referenced by the found matches.
104 */
105 Future<List<SearchMatch>> searchMemberReferences(String name);
106
107 /**
108 * Returns references to the given [Element].
109 *
110 * [element] - the [Element] being referenced by the found matches.
111 */
112 Future<List<SearchMatch>> searchReferences(Element element);
113
114 /**
115 * Returns subtypes of the given [type].
116 *
117 * [type] - the [ClassElemnet] being subtyped by the found matches.
118 */
119 Future<List<SearchMatch>> searchSubtypes(ClassElement type);
120
121 /**
122 * Returns all the top-level declarations matching the given pattern.
123 *
124 * [pattern] the regular expression used to match the names of the
125 * declarations to be found.
126 */
127 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern);
128 }
129
130 /**
131 * Instances of the class [SearchMatch] represent a match found by
132 * [SearchEngine].
133 */
134 class SearchMatch {
135 /**
136 * The kind of the match.
137 */
138 final MatchKind kind;
139
140 /**
141 * The element containing the source range that was matched.
142 */
143 final Element element;
144
145 /**
146 * The source range that was matched.
147 */
148 final SourceRange sourceRange;
149
150 /**
151 * Is `true` if the match is a resolved reference to some [Element].
152 */
153 final bool isResolved;
154
155 /**
156 * Is `true` if field or method access is done using qualifier.
157 */
158 final bool isQualified;
159
160 SearchMatch(this.kind, this.element, this.sourceRange, this.isResolved,
161 this.isQualified);
162
163 @override
164 int get hashCode => JavaArrays.makeHashCode([element, sourceRange, kind]);
165
166 @override
167 bool operator ==(Object object) {
168 if (identical(object, this)) {
169 return true;
170 }
171 if (object is SearchMatch) {
172 return kind == object.kind &&
173 isResolved == object.isResolved &&
174 isQualified == object.isQualified &&
175 sourceRange == object.sourceRange &&
176 element == object.element;
177 }
178 return false;
179 }
180
181 @override
182 String toString() {
183 StringBuffer buffer = new StringBuffer();
184 buffer.write("SearchMatch(kind=");
185 buffer.write(kind);
186 buffer.write(", element=");
187 buffer.write(element.displayName);
188 buffer.write(", range=");
189 buffer.write(sourceRange);
190 buffer.write(", isResolved=");
191 buffer.write(isResolved);
192 buffer.write(", isQualified=");
193 buffer.write(isQualified);
194 buffer.write(")");
195 return buffer.toString();
196 }
197 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/lib/search/hierarchy.dart ('k') | pkg/analysis_services/lib/src/completion/dart_completion_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698