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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart

Issue 904603004: rename completion constants and cleanup comment (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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.completion.dart.cache; 5 library services.completion.dart.cache;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/protocol_server.dart' hide Element, 10 import 'package:analysis_server/src/protocol_server.dart' hide Element,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 */ 171 */
172 void _addDartCoreSuggestions() { 172 void _addDartCoreSuggestions() {
173 Source coreUri = context.sourceFactory.forUri('dart:core'); 173 Source coreUri = context.sourceFactory.forUri('dart:core');
174 LibraryElement coreLib = context.getLibraryElement(coreUri); 174 LibraryElement coreLib = context.getLibraryElement(coreUri);
175 Namespace coreNamespace = 175 Namespace coreNamespace =
176 new NamespaceBuilder().createPublicNamespaceForLibrary(coreLib); 176 new NamespaceBuilder().createPublicNamespaceForLibrary(coreLib);
177 coreNamespace.definedNames.forEach((String name, Element elem) { 177 coreNamespace.definedNames.forEach((String name, Element elem) {
178 if (elem is ClassElement) { 178 if (elem is ClassElement) {
179 importedClassMap[name] = elem; 179 importedClassMap[name] = elem;
180 } 180 }
181 _addSuggestion(elem, COMPLETION_RELEVANCE_DEFAULT); 181 _addSuggestion(elem, DART_RELEVANCE_DEFAULT);
182 }); 182 });
183 } 183 }
184 184
185 /** 185 /**
186 * Add suggestions for explicitly imported and part elements in the given 186 * Add suggestions for explicitly imported and part elements in the given
187 * library. Add libraries that should not have their elements suggested 187 * library. Add libraries that should not have their elements suggested
188 * even as low priority to [excludedLibs]. 188 * even as low priority to [excludedLibs].
189 */ 189 */
190 void _addImportedElemSuggestions(Source libSource, CompilationUnit libUnit, 190 void _addImportedElemSuggestions(Source libSource, CompilationUnit libUnit,
191 Set<LibraryElement> excludedLibs) { 191 Set<LibraryElement> excludedLibs) {
192 if (libUnit != null) { 192 if (libUnit != null) {
193 libUnit.directives.forEach((Directive directive) { 193 libUnit.directives.forEach((Directive directive) {
194 if (directive is ImportDirective) { 194 if (directive is ImportDirective) {
195 ImportElement importElem = directive.element; 195 ImportElement importElem = directive.element;
196 if (importElem != null && importElem.importedLibrary != null) { 196 if (importElem != null && importElem.importedLibrary != null) {
197 if (directive.prefix == null) { 197 if (directive.prefix == null) {
198 Namespace importNamespace = 198 Namespace importNamespace =
199 new NamespaceBuilder().createImportNamespaceForDirective(impor tElem); 199 new NamespaceBuilder().createImportNamespaceForDirective(impor tElem);
200 // Include top level elements 200 // Include top level elements
201 importNamespace.definedNames.forEach((String name, Element elem) { 201 importNamespace.definedNames.forEach((String name, Element elem) {
202 if (elem is ClassElement) { 202 if (elem is ClassElement) {
203 importedClassMap[name] = elem; 203 importedClassMap[name] = elem;
204 } 204 }
205 _addSuggestion(elem, COMPLETION_RELEVANCE_DEFAULT); 205 _addSuggestion(elem, DART_RELEVANCE_DEFAULT);
206 }); 206 });
207 } else { 207 } else {
208 // Exclude elements from prefixed imports 208 // Exclude elements from prefixed imports
209 // because they are provided by InvocationComputer 209 // because they are provided by InvocationComputer
210 _addLibraryPrefixSuggestion(importElem); 210 _addLibraryPrefixSuggestion(importElem);
211 excludedLibs.add(importElem.importedLibrary); 211 excludedLibs.add(importElem.importedLibrary);
212 } 212 }
213 } 213 }
214 } else if (directive is PartDirective) { 214 } else if (directive is PartDirective) {
215 CompilationUnitElement partElem = directive.element; 215 CompilationUnitElement partElem = directive.element;
216 if (partElem != null && partElem.source != source) { 216 if (partElem != null && partElem.source != source) {
217 partElem.accept(new _NonLocalElementCacheVisitor(this)); 217 partElem.accept(new _NonLocalElementCacheVisitor(this));
218 } 218 }
219 } 219 }
220 }); 220 });
221 if (libSource != source) { 221 if (libSource != source) {
222 libUnit.element.accept(new _NonLocalElementCacheVisitor(this)); 222 libUnit.element.accept(new _NonLocalElementCacheVisitor(this));
223 } 223 }
224 } 224 }
225 } 225 }
226 226
227 void _addLibraryPrefixSuggestion(ImportElement importElem) { 227 void _addLibraryPrefixSuggestion(ImportElement importElem) {
228 CompletionSuggestion suggestion = null; 228 CompletionSuggestion suggestion = null;
229 String completion = importElem.prefix.displayName; 229 String completion = importElem.prefix.displayName;
230 if (completion != null && completion.length > 0) { 230 if (completion != null && completion.length > 0) {
231 suggestion = new CompletionSuggestion( 231 suggestion = new CompletionSuggestion(
232 CompletionSuggestionKind.INVOCATION, 232 CompletionSuggestionKind.INVOCATION,
233 COMPLETION_RELEVANCE_DEFAULT, 233 DART_RELEVANCE_DEFAULT,
234 completion, 234 completion,
235 completion.length, 235 completion.length,
236 0, 236 0,
237 importElem.isDeprecated, 237 importElem.isDeprecated,
238 false); 238 false);
239 LibraryElement lib = importElem.importedLibrary; 239 LibraryElement lib = importElem.importedLibrary;
240 if (lib != null) { 240 if (lib != null) {
241 suggestion.element = newElement_fromEngine(lib); 241 suggestion.element = newElement_fromEngine(lib);
242 } 242 }
243 libraryPrefixSuggestions.add(suggestion); 243 libraryPrefixSuggestions.add(suggestion);
244 _importedCompletions.add(suggestion.completion); 244 _importedCompletions.add(suggestion.completion);
245 } 245 }
246 } 246 }
247 247
248 /** 248 /**
249 * Add suggestions for all top level elements in the context 249 * Add suggestions for all top level elements in the context
250 * excluding those elemnents for which suggestions have already been added. 250 * excluding those elemnents for which suggestions have already been added.
251 */ 251 */
252 void _addNonImportedElementSuggestions(List<SearchMatch> matches, 252 void _addNonImportedElementSuggestions(List<SearchMatch> matches,
253 Set<LibraryElement> excludedLibs) { 253 Set<LibraryElement> excludedLibs) {
254 matches.forEach((SearchMatch match) { 254 matches.forEach((SearchMatch match) {
255 if (match.kind == MatchKind.DECLARATION) { 255 if (match.kind == MatchKind.DECLARATION) {
256 Element element = match.element; 256 Element element = match.element;
257 if (element.context == context && 257 if (element.context == context &&
258 element.isPublic && 258 element.isPublic &&
259 !excludedLibs.contains(element.library) && 259 !excludedLibs.contains(element.library) &&
260 !_importedCompletions.contains(element.displayName)) { 260 !_importedCompletions.contains(element.displayName)) {
261 _addSuggestion(element, COMPLETION_RELEVANCE_LOW); 261 _addSuggestion(element, DART_RELEVANCE_LOW);
262 } 262 }
263 } 263 }
264 }); 264 });
265 } 265 }
266 266
267 /** 267 /**
268 * Add a suggestion for the given element. 268 * Add a suggestion for the given element.
269 */ 269 */
270 void _addSuggestion(Element element, int relevance) { 270 void _addSuggestion(Element element, int relevance) {
271 271
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 * a source file contained in the same library but not the same as 327 * a source file contained in the same library but not the same as
328 * the source in which the completions are being requested. 328 * the source in which the completions are being requested.
329 */ 329 */
330 class _NonLocalElementCacheVisitor extends GeneralizingElementVisitor { 330 class _NonLocalElementCacheVisitor extends GeneralizingElementVisitor {
331 final DartCompletionCache cache; 331 final DartCompletionCache cache;
332 332
333 _NonLocalElementCacheVisitor(this.cache); 333 _NonLocalElementCacheVisitor(this.cache);
334 334
335 @override 335 @override
336 void visitClassElement(ClassElement element) { 336 void visitClassElement(ClassElement element) {
337 cache._addSuggestion(element, COMPLETION_RELEVANCE_DEFAULT); 337 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT);
338 } 338 }
339 339
340 @override 340 @override
341 void visitCompilationUnitElement(CompilationUnitElement element) { 341 void visitCompilationUnitElement(CompilationUnitElement element) {
342 element.visitChildren(this); 342 element.visitChildren(this);
343 } 343 }
344 344
345 @override 345 @override
346 void visitElement(Element element) { 346 void visitElement(Element element) {
347 // ignored 347 // ignored
348 } 348 }
349 349
350 @override 350 @override
351 void visitFunctionElement(FunctionElement element) { 351 void visitFunctionElement(FunctionElement element) {
352 cache._addSuggestion(element, COMPLETION_RELEVANCE_DEFAULT); 352 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT);
353 } 353 }
354 354
355 @override 355 @override
356 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { 356 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) {
357 cache._addSuggestion(element, COMPLETION_RELEVANCE_DEFAULT); 357 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT);
358 } 358 }
359 359
360 @override 360 @override
361 void visitTopLevelVariableElement(TopLevelVariableElement element) { 361 void visitTopLevelVariableElement(TopLevelVariableElement element) {
362 cache._addSuggestion(element, COMPLETION_RELEVANCE_DEFAULT); 362 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT);
363 } 363 }
364 } 364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698