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

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

Issue 1127643003: suggest only superclass elements for "super." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix test Created 5 years, 7 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.suggestion.builder; 5 library services.completion.suggestion.builder;
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' as protocol; 10 import 'package:analysis_server/src/protocol_server.dart' as protocol;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // Unexpected element type; skip it. 338 // Unexpected element type; skip it.
339 assert(false); 339 assert(false);
340 return; 340 return;
341 } 341 }
342 CompletionSuggestion suggestion = createSuggestion(element, kind: kind); 342 CompletionSuggestion suggestion = createSuggestion(element, kind: kind);
343 if (suggestion != null) { 343 if (suggestion != null) {
344 request.addSuggestion(suggestion); 344 request.addSuggestion(suggestion);
345 } 345 }
346 } 346 }
347 347
348 void _buildSuggestions(InterfaceType type, LibraryElement library) { 348 void _buildSuggestions(
349 InterfaceType type, LibraryElement library, bool isSuper) {
349 // Visit all of the types in the class hierarchy, collecting possible 350 // Visit all of the types in the class hierarchy, collecting possible
350 // completions. If multiple elements are found that complete to the same 351 // completions. If multiple elements are found that complete to the same
351 // identifier, addSuggestion will discard all but the first (with a few 352 // identifier, addSuggestion will discard all but the first (with a few
352 // exceptions to handle getter/setter pairs). 353 // exceptions to handle getter/setter pairs).
353 for (InterfaceType targetType in _getTypeOrdering(type)) { 354 List<InterfaceType> types = _getTypeOrdering(type);
355 if (isSuper) {
356 // Do not suggest members from the target type if the target is "super"
Paul Berry 2015/05/05 02:41:27 If the target is "super", then members from interf
danrubel 2015/05/05 20:03:18 Great point. Fixed.
357 types.remove(type);
358 }
359 for (InterfaceType targetType in types) {
354 for (MethodElement method in targetType.methods) { 360 for (MethodElement method in targetType.methods) {
355 // Exclude static methods when completion on an instance 361 // Exclude static methods when completion on an instance
356 if (!method.isStatic) { 362 if (!method.isStatic) {
357 addSuggestion(method); 363 addSuggestion(method);
358 } 364 }
359 } 365 }
360 for (PropertyAccessorElement propertyAccessor in targetType.accessors) { 366 for (PropertyAccessorElement propertyAccessor in targetType.accessors) {
361 if (!propertyAccessor.isStatic) { 367 if (!propertyAccessor.isStatic) {
362 if (propertyAccessor.isSynthetic) { 368 if (propertyAccessor.isSynthetic) {
363 // Avoid visiting a field twice 369 // Avoid visiting a field twice
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 typesToVisit.add(nextType.superclass); 411 typesToVisit.add(nextType.superclass);
406 } 412 }
407 typesToVisit.addAll(nextType.mixins); 413 typesToVisit.addAll(nextType.mixins);
408 } 414 }
409 return result; 415 return result;
410 } 416 }
411 417
412 /** 418 /**
413 * Add suggestions for the visible members in the given interface 419 * Add suggestions for the visible members in the given interface
414 */ 420 */
415 static void suggestionsFor(DartCompletionRequest request, DartType type) { 421 static void suggestionsFor(DartCompletionRequest request, DartType type,
422 {bool isSuper: false}) {
416 CompilationUnit compilationUnit = 423 CompilationUnit compilationUnit =
417 request.target.containingNode.getAncestor((n) => n is CompilationUnit); 424 request.target.containingNode.getAncestor((n) => n is CompilationUnit);
418 LibraryElement library = compilationUnit.element.library; 425 LibraryElement library = compilationUnit.element.library;
419 if (type is DynamicTypeImpl) { 426 if (type is DynamicTypeImpl) {
420 type = request.cache.objectClassElement.type; 427 type = request.cache.objectClassElement.type;
421 } 428 }
422 if (type is InterfaceType) { 429 if (type is InterfaceType) {
423 return new InterfaceTypeSuggestionBuilder(request)._buildSuggestions( 430 return new InterfaceTypeSuggestionBuilder(request)._buildSuggestions(
424 type, library); 431 type, library, isSuper);
425 } 432 }
426 } 433 }
427 } 434 }
428 435
429 /** 436 /**
430 * This class visits elements in a library and provides suggestions based upon 437 * This class visits elements in a library and provides suggestions based upon
431 * the visible members in that library. Clients should call 438 * the visible members in that library. Clients should call
432 * [LibraryElementSuggestionBuilder.suggestionsFor]. 439 * [LibraryElementSuggestionBuilder.suggestionsFor].
433 */ 440 */
434 class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor 441 class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 * or `false` if [computeFull] should be called. 622 * or `false` if [computeFull] should be called.
616 */ 623 */
617 bool computeFast(AstNode node); 624 bool computeFast(AstNode node);
618 625
619 /** 626 /**
620 * Return a future that computes the suggestions given a fully resolved AST. 627 * Return a future that computes the suggestions given a fully resolved AST.
621 * The future returns `true` if suggestions were added, else `false`. 628 * The future returns `true` if suggestions were added, else `false`.
622 */ 629 */
623 Future<bool> computeFull(AstNode node); 630 Future<bool> computeFull(AstNode node);
624 } 631 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698