| 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; |
| 11 import 'package:analysis_server/src/protocol_server.dart' hide Element, | 11 import 'package:analysis_server/src/protocol_server.dart' hide Element, |
| 12 ElementKind; | 12 ElementKind; |
| 13 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 13 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 14 import 'package:analyzer/src/generated/ast.dart'; | 14 import 'package:analyzer/src/generated/ast.dart'; |
| 15 import 'package:analyzer/src/generated/element.dart'; | 15 import 'package:analyzer/src/generated/element.dart'; |
| 16 import 'package:analyzer/src/generated/utilities_dart.dart'; | 16 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 17 | 17 |
| 18 const String DYNAMIC = 'dynamic'; | 18 const String DYNAMIC = 'dynamic'; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Return a suggestion based upon the given element | 21 * Return a suggestion based upon the given element |
| 22 * or `null` if a suggestion is not appropriate for the given element. | 22 * or `null` if a suggestion is not appropriate for the given element. |
| 23 */ | 23 */ |
| 24 CompletionSuggestion createSuggestion(Element element, | 24 CompletionSuggestion createSuggestion(Element element, |
| 25 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 25 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 26 int relevance: COMPLETION_RELEVANCE_DEFAULT}) { | 26 int relevance: DART_RELEVANCE_DEFAULT}) { |
| 27 | 27 |
| 28 String nameForType(DartType type) { | 28 String nameForType(DartType type) { |
| 29 if (type == null) { | 29 if (type == null) { |
| 30 return DYNAMIC; | 30 return DYNAMIC; |
| 31 } | 31 } |
| 32 String name = type.displayName; | 32 String name = type.displayName; |
| 33 if (name == null || name.length <= 0) { | 33 if (name == null || name.length <= 0) { |
| 34 return DYNAMIC; | 34 return DYNAMIC; |
| 35 } | 35 } |
| 36 //TODO (danrubel) include type arguments ?? | 36 //TODO (danrubel) include type arguments ?? |
| (...skipping 14 matching lines...) Expand all Loading... |
| 51 } else if (element is VariableElement) { | 51 } else if (element is VariableElement) { |
| 52 returnType = nameForType(element.type); | 52 returnType = nameForType(element.type); |
| 53 } else if (element is FunctionTypeAliasElement) { | 53 } else if (element is FunctionTypeAliasElement) { |
| 54 returnType = nameForType(element.returnType); | 54 returnType = nameForType(element.returnType); |
| 55 } | 55 } |
| 56 | 56 |
| 57 String completion = element.displayName; | 57 String completion = element.displayName; |
| 58 bool isDeprecated = element.isDeprecated; | 58 bool isDeprecated = element.isDeprecated; |
| 59 CompletionSuggestion suggestion = new CompletionSuggestion( | 59 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 60 kind, | 60 kind, |
| 61 isDeprecated ? COMPLETION_RELEVANCE_LOW : relevance, | 61 isDeprecated ? DART_RELEVANCE_LOW : relevance, |
| 62 completion, | 62 completion, |
| 63 completion.length, | 63 completion.length, |
| 64 0, | 64 0, |
| 65 isDeprecated, | 65 isDeprecated, |
| 66 false); | 66 false); |
| 67 suggestion.element = protocol.newElement_fromEngine(element); | 67 suggestion.element = protocol.newElement_fromEngine(element); |
| 68 Element enclosingElement = element.enclosingElement; | 68 Element enclosingElement = element.enclosingElement; |
| 69 if (enclosingElement is ClassElement) { | 69 if (enclosingElement is ClassElement) { |
| 70 suggestion.declaringType = enclosingElement.displayName; | 70 suggestion.declaringType = enclosingElement.displayName; |
| 71 } | 71 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 CompletionSuggestionKind get kind; | 179 CompletionSuggestionKind get kind; |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * Return the request on which the builder is operating. | 182 * Return the request on which the builder is operating. |
| 183 */ | 183 */ |
| 184 DartCompletionRequest get request; | 184 DartCompletionRequest get request; |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * Add a suggestion based upon the given element. | 187 * Add a suggestion based upon the given element. |
| 188 */ | 188 */ |
| 189 void addSuggestion(Element element, {int relevance: COMPLETION_RELEVANCE_DEFAU
LT}) { | 189 void addSuggestion(Element element, {int relevance: DART_RELEVANCE_DEFAULT}) { |
| 190 if (element.isPrivate) { | 190 if (element.isPrivate) { |
| 191 LibraryElement elementLibrary = element.library; | 191 LibraryElement elementLibrary = element.library; |
| 192 LibraryElement unitLibrary = request.unit.element.library; | 192 LibraryElement unitLibrary = request.unit.element.library; |
| 193 if (elementLibrary != unitLibrary) { | 193 if (elementLibrary != unitLibrary) { |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 if (element.isSynthetic) { | 197 if (element.isSynthetic) { |
| 198 if (element is PropertyAccessorElement || element is FieldElement) { | 198 if (element is PropertyAccessorElement || element is FieldElement) { |
| 199 return; | 199 return; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 * or `false` if [computeFull] should be called. | 573 * or `false` if [computeFull] should be called. |
| 574 */ | 574 */ |
| 575 bool computeFast(AstNode node); | 575 bool computeFast(AstNode node); |
| 576 | 576 |
| 577 /** | 577 /** |
| 578 * Return a future that computes the suggestions given a fully resolved AST. | 578 * Return a future that computes the suggestions given a fully resolved AST. |
| 579 * The future returns `true` if suggestions were added, else `false`. | 579 * The future returns `true` if suggestions were added, else `false`. |
| 580 */ | 580 */ |
| 581 Future<bool> computeFull(AstNode node); | 581 Future<bool> computeFull(AstNode node); |
| 582 } | 582 } |
| OLD | NEW |