OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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.completion.computer.dart.manager; |
| 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 8 show CompletionSuggestion, CompletionSuggestionKind; |
| 9 import 'package:analysis_server/src/provisional/completion/completion_dart.dart'
; |
| 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart' |
| 11 show DART_RELEVANCE_DEFAULT, DART_RELEVANCE_LOCAL_FUNCTION; |
| 12 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; |
| 13 import 'package:analyzer/src/generated/element.dart'; |
| 14 |
| 15 // TODO (danrubel) revise a move existing manager to this file |
| 16 |
| 17 /** |
| 18 * An internal implementation of [DartSuggestionCollector] for building |
| 19 * and collecting suggestions based upon elements. |
| 20 */ |
| 21 class DartSuggestionCollectorImpl implements DartSuggestionCollector { |
| 22 List<CompletionSuggestion> suggestions = <CompletionSuggestion>[]; |
| 23 |
| 24 @override |
| 25 void addCompletionSuggestion(CompletionSuggestion suggestion) { |
| 26 if (suggestion != null) { |
| 27 suggestions.add(suggestion); |
| 28 } |
| 29 } |
| 30 |
| 31 @override |
| 32 void addElementSuggestion(Element element, |
| 33 {bool includePrivateElements: false, |
| 34 String prefix, |
| 35 int relevance: DART_RELEVANCE_DEFAULT}) { |
| 36 if (element.isPrivate && !includePrivateElements) { |
| 37 return; |
| 38 } |
| 39 if (prefix == null && element.isSynthetic) { |
| 40 if ((element is PropertyAccessorElement) || |
| 41 element is FieldElement && !_isSpecialEnumField(element)) { |
| 42 return; |
| 43 } |
| 44 } |
| 45 String completion = element.displayName; |
| 46 if (prefix != null && prefix.length > 0) { |
| 47 if (completion == null || completion.length <= 0) { |
| 48 completion = prefix; |
| 49 } else { |
| 50 completion = '$prefix.$completion'; |
| 51 } |
| 52 } |
| 53 if (completion == null || completion.length <= 0) { |
| 54 return; |
| 55 } |
| 56 addCompletionSuggestion(createSuggestion(element, |
| 57 completion: completion, |
| 58 kind: CompletionSuggestionKind.IDENTIFIER, |
| 59 relevance: relevance)); |
| 60 } |
| 61 |
| 62 /** |
| 63 * Determine if the given element is one of the synthetic enum accessors |
| 64 * for which we should generate a suggestion. |
| 65 */ |
| 66 bool _isSpecialEnumField(FieldElement element) { |
| 67 Element parent = element.enclosingElement; |
| 68 if (parent is ClassElement && parent.isEnum) { |
| 69 if (element.name == 'values') { |
| 70 return true; |
| 71 } |
| 72 } |
| 73 return false; |
| 74 } |
| 75 } |
OLD | NEW |