| OLD | NEW |
| 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 Loading... |
| 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) { |
| 350 if (isSuper) { |
| 351 // Suggest members from superclass if the target is "super" |
| 352 type = type.superclass; |
| 353 if (type == null) { |
| 354 return; |
| 355 } |
| 356 } |
| 349 // Visit all of the types in the class hierarchy, collecting possible | 357 // Visit all of the types in the class hierarchy, collecting possible |
| 350 // completions. If multiple elements are found that complete to the same | 358 // completions. If multiple elements are found that complete to the same |
| 351 // identifier, addSuggestion will discard all but the first (with a few | 359 // identifier, addSuggestion will discard all but the first (with a few |
| 352 // exceptions to handle getter/setter pairs). | 360 // exceptions to handle getter/setter pairs). |
| 353 for (InterfaceType targetType in _getTypeOrdering(type)) { | 361 for (InterfaceType targetType in _getTypeOrdering(type)) { |
| 354 for (MethodElement method in targetType.methods) { | 362 for (MethodElement method in targetType.methods) { |
| 355 // Exclude static methods when completion on an instance | 363 // Exclude static methods when completion on an instance |
| 356 if (!method.isStatic) { | 364 if (!method.isStatic) { |
| 357 addSuggestion(method); | 365 addSuggestion(method); |
| 358 } | 366 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 typesToVisit.add(nextType.superclass); | 413 typesToVisit.add(nextType.superclass); |
| 406 } | 414 } |
| 407 typesToVisit.addAll(nextType.mixins); | 415 typesToVisit.addAll(nextType.mixins); |
| 408 } | 416 } |
| 409 return result; | 417 return result; |
| 410 } | 418 } |
| 411 | 419 |
| 412 /** | 420 /** |
| 413 * Add suggestions for the visible members in the given interface | 421 * Add suggestions for the visible members in the given interface |
| 414 */ | 422 */ |
| 415 static void suggestionsFor(DartCompletionRequest request, DartType type) { | 423 static void suggestionsFor(DartCompletionRequest request, DartType type, |
| 424 {bool isSuper: false}) { |
| 416 CompilationUnit compilationUnit = | 425 CompilationUnit compilationUnit = |
| 417 request.target.containingNode.getAncestor((n) => n is CompilationUnit); | 426 request.target.containingNode.getAncestor((n) => n is CompilationUnit); |
| 418 LibraryElement library = compilationUnit.element.library; | 427 LibraryElement library = compilationUnit.element.library; |
| 419 if (type is DynamicTypeImpl) { | 428 if (type is DynamicTypeImpl) { |
| 420 type = request.cache.objectClassElement.type; | 429 type = request.cache.objectClassElement.type; |
| 421 } | 430 } |
| 422 if (type is InterfaceType) { | 431 if (type is InterfaceType) { |
| 423 return new InterfaceTypeSuggestionBuilder(request)._buildSuggestions( | 432 return new InterfaceTypeSuggestionBuilder(request)._buildSuggestions( |
| 424 type, library); | 433 type, library, isSuper); |
| 425 } | 434 } |
| 426 } | 435 } |
| 427 } | 436 } |
| 428 | 437 |
| 429 /** | 438 /** |
| 430 * This class visits elements in a library and provides suggestions based upon | 439 * This class visits elements in a library and provides suggestions based upon |
| 431 * the visible members in that library. Clients should call | 440 * the visible members in that library. Clients should call |
| 432 * [LibraryElementSuggestionBuilder.suggestionsFor]. | 441 * [LibraryElementSuggestionBuilder.suggestionsFor]. |
| 433 */ | 442 */ |
| 434 class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor | 443 class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 * or `false` if [computeFull] should be called. | 624 * or `false` if [computeFull] should be called. |
| 616 */ | 625 */ |
| 617 bool computeFast(AstNode node); | 626 bool computeFast(AstNode node); |
| 618 | 627 |
| 619 /** | 628 /** |
| 620 * Return a future that computes the suggestions given a fully resolved AST. | 629 * Return a future that computes the suggestions given a fully resolved AST. |
| 621 * The future returns `true` if suggestions were added, else `false`. | 630 * The future returns `true` if suggestions were added, else `false`. |
| 622 */ | 631 */ |
| 623 Future<bool> computeFull(AstNode node); | 632 Future<bool> computeFull(AstNode node); |
| 624 } | 633 } |
| OLD | NEW |