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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 CompilationUnitElement unitElem = request.unit.element; | 220 CompilationUnitElement unitElem = request.unit.element; |
221 if (unitElem == null) { | 221 if (unitElem == null) { |
222 return; | 222 return; |
223 } | 223 } |
224 LibraryElement unitLibrary = unitElem.library; | 224 LibraryElement unitLibrary = unitElem.library; |
225 if (elementLibrary != unitLibrary) { | 225 if (elementLibrary != unitLibrary) { |
226 return; | 226 return; |
227 } | 227 } |
228 } | 228 } |
229 if (element.isSynthetic) { | 229 if (element.isSynthetic) { |
230 if (element is PropertyAccessorElement || element is FieldElement) { | 230 if ((element is PropertyAccessorElement) || |
| 231 element is FieldElement && !_isSpecialEnumField(element)) { |
231 return; | 232 return; |
232 } | 233 } |
233 } | 234 } |
234 String completion = element.displayName; | 235 String completion = element.displayName; |
235 if (completion == null || completion.length <= 0) { | 236 if (completion == null || completion.length <= 0) { |
236 return; | 237 return; |
237 } | 238 } |
238 CompletionSuggestion suggestion = | 239 CompletionSuggestion suggestion = |
239 createSuggestion(element, kind: kind, relevance: relevance); | 240 createSuggestion(element, kind: kind, relevance: relevance); |
240 if (suggestion != null) { | 241 if (suggestion != null) { |
241 request.addSuggestion(suggestion); | 242 request.addSuggestion(suggestion); |
242 } | 243 } |
243 } | 244 } |
| 245 |
| 246 /** |
| 247 * Determine if the given element is one of the synthetic enum accessors |
| 248 * for which we should generate a suggestion. |
| 249 */ |
| 250 bool _isSpecialEnumField(FieldElement element) { |
| 251 Element parent = element.enclosingElement; |
| 252 if (parent is ClassElement && parent.isEnum) { |
| 253 if (element.name == 'values') { |
| 254 return true; |
| 255 } |
| 256 } |
| 257 return false; |
| 258 } |
244 } | 259 } |
245 | 260 |
246 /** | 261 /** |
247 * This class provides suggestions based upon the visible instance members in | 262 * This class provides suggestions based upon the visible instance members in |
248 * an interface type. Clients should call | 263 * an interface type. Clients should call |
249 * [InterfaceTypeSuggestionBuilder.suggestionsFor]. | 264 * [InterfaceTypeSuggestionBuilder.suggestionsFor]. |
250 */ | 265 */ |
251 class InterfaceTypeSuggestionBuilder { | 266 class InterfaceTypeSuggestionBuilder { |
252 /** | 267 /** |
253 * Enumerated value indicating that we have not generated any completions for | 268 * Enumerated value indicating that we have not generated any completions for |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 * or `false` if [computeFull] should be called. | 644 * or `false` if [computeFull] should be called. |
630 */ | 645 */ |
631 bool computeFast(AstNode node); | 646 bool computeFast(AstNode node); |
632 | 647 |
633 /** | 648 /** |
634 * Return a future that computes the suggestions given a fully resolved AST. | 649 * Return a future that computes the suggestions given a fully resolved AST. |
635 * The future returns `true` if suggestions were added, else `false`. | 650 * The future returns `true` if suggestions were added, else `false`. |
636 */ | 651 */ |
637 Future<bool> computeFull(AstNode node); | 652 Future<bool> computeFull(AstNode node); |
638 } | 653 } |
OLD | NEW |