| 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 'package:analysis_server/src/protocol_server.dart' as protocol; | 7 import 'package:analysis_server/src/protocol_server.dart' as protocol; |
| 8 import 'package:analysis_server/src/protocol_server.dart' hide Element, | 8 import 'package:analysis_server/src/protocol_server.dart' hide Element, |
| 9 ElementKind; | 9 ElementKind; |
| 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 return element.accept(new ClassElementSuggestionBuilder(request)); | 75 return element.accept(new ClassElementSuggestionBuilder(request)); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * This class visits elements in a library and provides suggestions based upon | 81 * This class visits elements in a library and provides suggestions based upon |
| 82 * the visible members in that library. Clients should call | 82 * the visible members in that library. Clients should call |
| 83 * [LibraryElementSuggestionBuilder.suggestionsFor]. | 83 * [LibraryElementSuggestionBuilder.suggestionsFor]. |
| 84 */ | 84 */ |
| 85 class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor { | 85 class LibraryElementSuggestionBuilder extends _AbstractSuggestionBuilder { |
| 86 | 86 |
| 87 final DartCompletionRequest request; | 87 LibraryElementSuggestionBuilder(DartCompletionRequest request) |
| 88 | 88 : super(request); |
| 89 LibraryElementSuggestionBuilder(this.request); | |
| 90 | 89 |
| 91 @override | 90 @override |
| 92 visitClassElement(ClassElement element) { | 91 visitClassElement(ClassElement element) { |
| 93 _addSuggestion(element); | 92 _addElementSuggestion(element, CompletionSuggestionKind.CLASS, null, null); |
| 94 } | 93 } |
| 95 | 94 |
| 96 @override | 95 @override |
| 97 visitCompilationUnitElement(CompilationUnitElement element) { | 96 visitCompilationUnitElement(CompilationUnitElement element) { |
| 98 element.visitChildren(this); | 97 element.visitChildren(this); |
| 99 } | 98 } |
| 100 | 99 |
| 101 @override | 100 @override |
| 102 visitElement(Element element) { | 101 visitElement(Element element) { |
| 103 // ignored | 102 // ignored |
| 104 } | 103 } |
| 105 | 104 |
| 106 @override | 105 @override |
| 106 visitFunctionElement(FunctionElement element) { |
| 107 _addElementSuggestion( |
| 108 element, |
| 109 CompletionSuggestionKind.FUNCTION, |
| 110 element.returnType, |
| 111 null); |
| 112 } |
| 113 |
| 114 @override |
| 107 visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { | 115 visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { |
| 108 _addSuggestion(element); | 116 _addElementSuggestion( |
| 117 element, |
| 118 CompletionSuggestionKind.FUNCTION_TYPE_ALIAS, |
| 119 element.returnType, |
| 120 null); |
| 109 } | 121 } |
| 110 | 122 |
| 111 @override | 123 @override |
| 112 visitTopLevelVariableElement(TopLevelVariableElement element) { | 124 visitTopLevelVariableElement(TopLevelVariableElement element) { |
| 113 _addSuggestion(element); | 125 _addElementSuggestion( |
| 114 } | 126 element, |
| 115 | 127 CompletionSuggestionKind.TOP_LEVEL_VARIABLE, |
| 116 void _addSuggestion(Element element) { | 128 element.type, |
| 117 if (element != null) { | 129 null); |
| 118 String completion = element.name; | |
| 119 if (completion != null && completion.length > 0) { | |
| 120 CompletionSuggestion suggestion = new CompletionSuggestion( | |
| 121 protocol.newCompletionSuggestionKind_fromElementKind(element.kind), | |
| 122 CompletionRelevance.DEFAULT, | |
| 123 completion, | |
| 124 completion.length, | |
| 125 0, | |
| 126 element.isDeprecated, | |
| 127 false); | |
| 128 | |
| 129 suggestion.element = newElement_fromEngine(element); | |
| 130 | |
| 131 request.suggestions.add(suggestion); | |
| 132 } | |
| 133 } | |
| 134 } | 130 } |
| 135 | 131 |
| 136 /** | 132 /** |
| 137 * Add suggestions for the visible members in the given library | 133 * Add suggestions for the visible members in the given library |
| 138 */ | 134 */ |
| 139 static void suggestionsFor(DartCompletionRequest request, | 135 static void suggestionsFor(DartCompletionRequest request, |
| 140 LibraryElement library) { | 136 LibraryElement library) { |
| 141 if (library != null) { | 137 if (library != null) { |
| 142 library.visitChildren(new LibraryElementSuggestionBuilder(request)); | 138 library.visitChildren(new LibraryElementSuggestionBuilder(request)); |
| 143 } | 139 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 227 } |
| 232 if (type != null) { | 228 if (type != null) { |
| 233 String typeName = type.displayName; | 229 String typeName = type.displayName; |
| 234 if (typeName != null && typeName.length > 0 && typeName != 'dynamic') { | 230 if (typeName != null && typeName.length > 0 && typeName != 'dynamic') { |
| 235 suggestion.returnType = typeName; | 231 suggestion.returnType = typeName; |
| 236 } | 232 } |
| 237 } | 233 } |
| 238 request.suggestions.add(suggestion); | 234 request.suggestions.add(suggestion); |
| 239 } | 235 } |
| 240 } | 236 } |
| OLD | NEW |