| 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.computer.dart.invocation; | 5 library services.completion.computer.dart.invocation; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 9 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 10 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; | 10 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; |
| 11 import 'package:analysis_server/src/services/completion/optype.dart'; | 11 import 'package:analysis_server/src/services/completion/optype.dart'; |
| 12 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; | 12 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; |
| 13 import 'package:analyzer/src/generated/ast.dart'; | 13 import 'package:analyzer/src/generated/ast.dart'; |
| 14 import 'package:analyzer/src/generated/element.dart'; | 14 import 'package:analyzer/src/generated/element.dart'; |
| 15 | 15 |
| 16 import '../../protocol_server.dart' show CompletionSuggestionKind; | 16 import '../../protocol_server.dart' show CompletionSuggestionKind; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * A computer for calculating invocation / access suggestions | 19 * A computer for calculating invocation / access suggestions |
| 20 * `completion.getSuggestions` request results. | 20 * `completion.getSuggestions` request results. |
| 21 */ | 21 */ |
| 22 class InvocationComputer extends DartCompletionComputer { | 22 class InvocationComputer extends DartCompletionComputer { |
| 23 SuggestionBuilder builder; | 23 SuggestionBuilder builder; |
| 24 | 24 |
| 25 @override | 25 @override |
| 26 bool computeFast(DartCompletionRequest request) { | 26 bool computeFast(DartCompletionRequest request) { |
| 27 OpType optype = request.optype; | 27 OpType optype = request.optype; |
| 28 if (optype.includeInvocationSuggestions) { | 28 if (optype.includeInvocationSuggestions) { |
| 29 builder = request.node.accept(new _InvocationAstVisitor(request)); | 29 builder = request.target.containingNode |
| 30 .accept(new _InvocationAstVisitor(request)); |
| 30 if (builder != null) { | 31 if (builder != null) { |
| 31 return builder.computeFast(request.node); | 32 return builder.computeFast(request.target.containingNode); |
| 32 } | 33 } |
| 33 } | 34 } |
| 34 | 35 |
| 35 return true; | 36 return true; |
| 36 } | 37 } |
| 37 | 38 |
| 38 @override | 39 @override |
| 39 Future<bool> computeFull(DartCompletionRequest request) { | 40 Future<bool> computeFull(DartCompletionRequest request) { |
| 40 if (builder != null) { | 41 if (builder != null) { |
| 41 return builder.computeFull(request.node); | 42 return builder.computeFull(request.target.containingNode); |
| 42 } | 43 } |
| 43 return new Future.value(false); | 44 return new Future.value(false); |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| 47 class _ExpressionSuggestionBuilder implements SuggestionBuilder { | 48 class _ExpressionSuggestionBuilder implements SuggestionBuilder { |
| 48 final DartCompletionRequest request; | 49 final DartCompletionRequest request; |
| 49 | 50 |
| 50 _ExpressionSuggestionBuilder(this.request); | 51 _ExpressionSuggestionBuilder(this.request); |
| 51 | 52 |
| 52 @override | 53 @override |
| 53 bool computeFast(AstNode node) { | 54 bool computeFast(AstNode node) { |
| 54 return false; | 55 return false; |
| 55 } | 56 } |
| 56 | 57 |
| 57 @override | 58 @override |
| 58 Future<bool> computeFull(AstNode node) { | 59 Future<bool> computeFull(AstNode node) { |
| 59 if (node is SimpleIdentifier) { | |
| 60 node = node.parent; | |
| 61 } | |
| 62 if (node is MethodInvocation) { | 60 if (node is MethodInvocation) { |
| 63 node = (node as MethodInvocation).realTarget; | 61 node = (node as MethodInvocation).realTarget; |
| 64 } else if (node is PropertyAccess) { | 62 } else if (node is PropertyAccess) { |
| 65 node = (node as PropertyAccess).realTarget; | 63 node = (node as PropertyAccess).realTarget; |
| 66 } | 64 } |
| 67 if (node is Identifier) { | 65 if (node is Identifier) { |
| 68 Element elem = node.bestElement; | 66 Element elem = node.bestElement; |
| 69 if (elem is ClassElement || elem is PrefixElement) { | 67 if (elem is ClassElement || elem is PrefixElement) { |
| 70 elem.accept(new _PrefixedIdentifierSuggestionBuilder(request)); | 68 elem.accept(new _PrefixedIdentifierSuggestionBuilder(request)); |
| 71 return new Future.value(true); | 69 return new Future.value(true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 /** | 80 /** |
| 83 * An [AstNode] vistor for determining which suggestion builder | 81 * An [AstNode] vistor for determining which suggestion builder |
| 84 * should be used to build invocation/access suggestions. | 82 * should be used to build invocation/access suggestions. |
| 85 */ | 83 */ |
| 86 class _InvocationAstVisitor extends GeneralizingAstVisitor<SuggestionBuilder> { | 84 class _InvocationAstVisitor extends GeneralizingAstVisitor<SuggestionBuilder> { |
| 87 final DartCompletionRequest request; | 85 final DartCompletionRequest request; |
| 88 | 86 |
| 89 _InvocationAstVisitor(this.request); | 87 _InvocationAstVisitor(this.request); |
| 90 | 88 |
| 91 @override | 89 @override |
| 92 visitConstructorName(ConstructorName node) { | 90 SuggestionBuilder visitConstructorName(ConstructorName node) { |
| 93 // some PrefixedIdentifier nodes are transformed into | 91 // some PrefixedIdentifier nodes are transformed into |
| 94 // ConstructorName nodes during the resolution process. | 92 // ConstructorName nodes during the resolution process. |
| 95 return new _PrefixedIdentifierSuggestionBuilder(request); | 93 return new _PrefixedIdentifierSuggestionBuilder(request); |
| 96 } | 94 } |
| 97 | 95 |
| 98 @override | 96 @override |
| 99 SuggestionBuilder visitMethodInvocation(MethodInvocation node) { | 97 SuggestionBuilder visitMethodInvocation(MethodInvocation node) { |
| 100 return new _ExpressionSuggestionBuilder(request); | 98 return new _ExpressionSuggestionBuilder(request); |
| 101 } | 99 } |
| 102 | 100 |
| 103 @override | 101 @override |
| 104 SuggestionBuilder visitNode(AstNode node) { | 102 SuggestionBuilder visitNode(AstNode node) { |
| 105 return null; | 103 return null; |
| 106 } | 104 } |
| 107 | 105 |
| 108 @override | 106 @override |
| 109 SuggestionBuilder visitPrefixedIdentifier(PrefixedIdentifier node) { | 107 SuggestionBuilder visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 110 // some PrefixedIdentifier nodes are transformed into | 108 // some PrefixedIdentifier nodes are transformed into |
| 111 // ConstructorName nodes during the resolution process. | 109 // ConstructorName nodes during the resolution process. |
| 112 return new _PrefixedIdentifierSuggestionBuilder(request); | 110 return new _PrefixedIdentifierSuggestionBuilder(request); |
| 113 } | 111 } |
| 114 | 112 |
| 115 @override | 113 @override |
| 116 SuggestionBuilder visitPropertyAccess(PropertyAccess node) { | 114 SuggestionBuilder visitPropertyAccess(PropertyAccess node) { |
| 117 return new _ExpressionSuggestionBuilder(request); | 115 return new _ExpressionSuggestionBuilder(request); |
| 118 } | 116 } |
| 119 | |
| 120 @override | |
| 121 SuggestionBuilder visitSimpleIdentifier(SimpleIdentifier node) { | |
| 122 return node.parent.accept(this); | |
| 123 } | |
| 124 } | 117 } |
| 125 | 118 |
| 126 /** | 119 /** |
| 127 * An [AstVisitor] which looks for a declaration with the given name | 120 * An [AstVisitor] which looks for a declaration with the given name |
| 128 * and if found, tries to determine a type for that declaration. | 121 * and if found, tries to determine a type for that declaration. |
| 129 */ | 122 */ |
| 130 class _LocalBestTypeVisitor extends LocalDeclarationVisitor { | 123 class _LocalBestTypeVisitor extends LocalDeclarationVisitor { |
| 131 | 124 |
| 132 /** | 125 /** |
| 133 * The name for the declaration to be found. | 126 * The name for the declaration to be found. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 240 |
| 248 _PrefixedIdentifierSuggestionBuilder(this.request); | 241 _PrefixedIdentifierSuggestionBuilder(this.request); |
| 249 | 242 |
| 250 @override | 243 @override |
| 251 bool computeFast(AstNode node) { | 244 bool computeFast(AstNode node) { |
| 252 return false; | 245 return false; |
| 253 } | 246 } |
| 254 | 247 |
| 255 @override | 248 @override |
| 256 Future<bool> computeFull(AstNode node) { | 249 Future<bool> computeFull(AstNode node) { |
| 257 if (node is SimpleIdentifier) { | |
| 258 node = node.parent; | |
| 259 } | |
| 260 if (node is ConstructorName) { | 250 if (node is ConstructorName) { |
| 261 // some PrefixedIdentifier nodes are transformed into | 251 // some PrefixedIdentifier nodes are transformed into |
| 262 // ConstructorName nodes during the resolution process. | 252 // ConstructorName nodes during the resolution process. |
| 263 return new NamedConstructorSuggestionBuilder(request).computeFull(node); | 253 return new NamedConstructorSuggestionBuilder(request).computeFull(node); |
| 264 } | 254 } |
| 265 if (node is PrefixedIdentifier) { | 255 if (node is PrefixedIdentifier) { |
| 266 SimpleIdentifier prefix = node.prefix; | 256 SimpleIdentifier prefix = node.prefix; |
| 267 if (prefix != null) { | 257 if (prefix != null) { |
| 268 Element element = prefix.bestElement; | 258 Element element = prefix.bestElement; |
| 269 DartType type = prefix.bestType; | 259 DartType type = prefix.bestType; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 335 } |
| 346 return new Future.value(false); | 336 return new Future.value(false); |
| 347 } | 337 } |
| 348 | 338 |
| 349 @override | 339 @override |
| 350 Future<bool> visitVariableElement(VariableElement element) { | 340 Future<bool> visitVariableElement(VariableElement element) { |
| 351 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type); | 341 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type); |
| 352 return new Future.value(true); | 342 return new Future.value(true); |
| 353 } | 343 } |
| 354 } | 344 } |
| OLD | NEW |