| 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/optype_ast_visitor.dart'
; |
| 10 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; | 11 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; |
| 11 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 12 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 13 import 'package:analyzer/src/generated/scanner.dart'; | 14 import 'package:analyzer/src/generated/scanner.dart'; |
| 14 | 15 |
| 15 import '../../protocol_server.dart' show CompletionSuggestionKind; | 16 import '../../protocol_server.dart' show CompletionSuggestionKind; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * A computer for calculating invocation / access suggestions | 19 * A computer for calculating invocation / access suggestions |
| 19 * `completion.getSuggestions` request results. | 20 * `completion.getSuggestions` request results. |
| 20 */ | 21 */ |
| 21 class InvocationComputer extends DartCompletionComputer { | 22 class InvocationComputer extends DartCompletionComputer { |
| 22 SuggestionBuilder builder; | 23 SuggestionBuilder builder; |
| 23 | 24 |
| 24 @override | 25 @override |
| 25 bool computeFast(DartCompletionRequest request) { | 26 bool computeFast(DartCompletionRequest request) { |
| 26 builder = request.node.accept(new _InvocationAstVisitor(request)); | 27 |
| 27 if (builder != null) { | 28 // Determine the type of suggestions to be made |
| 28 return builder.computeFast(request.node); | 29 OpTypeAstVisitor opTypeVisitor = new OpTypeAstVisitor(request.offset); |
| 30 request.node.accept(opTypeVisitor); |
| 31 |
| 32 // Build the suggestions |
| 33 if (opTypeVisitor.includeInvocationSuggestions) { |
| 34 builder = request.node.accept(new _InvocationAstVisitor(request)); |
| 35 if (builder != null) { |
| 36 return builder.computeFast(request.node); |
| 37 } |
| 29 } | 38 } |
| 39 |
| 30 return true; | 40 return true; |
| 31 } | 41 } |
| 32 | 42 |
| 33 @override | 43 @override |
| 34 Future<bool> computeFull(DartCompletionRequest request) { | 44 Future<bool> computeFull(DartCompletionRequest request) { |
| 35 if (builder != null) { | 45 if (builder != null) { |
| 36 return builder.computeFull(request.node); | 46 return builder.computeFull(request.node); |
| 37 } | 47 } |
| 38 return new Future.value(false); | 48 return new Future.value(false); |
| 39 } | 49 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 */ | 86 */ |
| 77 class _InvocationAstVisitor extends GeneralizingAstVisitor<SuggestionBuilder> { | 87 class _InvocationAstVisitor extends GeneralizingAstVisitor<SuggestionBuilder> { |
| 78 final DartCompletionRequest request; | 88 final DartCompletionRequest request; |
| 79 | 89 |
| 80 _InvocationAstVisitor(this.request); | 90 _InvocationAstVisitor(this.request); |
| 81 | 91 |
| 82 @override | 92 @override |
| 83 visitConstructorName(ConstructorName node) { | 93 visitConstructorName(ConstructorName node) { |
| 84 // some PrefixedIdentifier nodes are transformed into | 94 // some PrefixedIdentifier nodes are transformed into |
| 85 // ConstructorName nodes during the resolution process. | 95 // ConstructorName nodes during the resolution process. |
| 86 Token period = node.period; | 96 return new _PrefixedIdentifierSuggestionBuilder(request); |
| 87 if (period != null && request.offset > period.offset) { | |
| 88 TypeName type = node.type; | |
| 89 if (type != null) { | |
| 90 SimpleIdentifier prefix = type.name; | |
| 91 if (prefix != null) { | |
| 92 return new _PrefixedIdentifierSuggestionBuilder(request); | |
| 93 } | |
| 94 } | |
| 95 } | |
| 96 return null; | |
| 97 } | 97 } |
| 98 | 98 |
| 99 @override | 99 @override |
| 100 SuggestionBuilder visitMethodInvocation(MethodInvocation node) { | 100 SuggestionBuilder visitMethodInvocation(MethodInvocation node) { |
| 101 Token period = node.period; | 101 return new _ExpressionSuggestionBuilder(request); |
| 102 if (period == null || period.offset < request.offset) { | |
| 103 return new _ExpressionSuggestionBuilder(request); | |
| 104 } | |
| 105 return null; | |
| 106 } | 102 } |
| 107 | 103 |
| 108 @override | 104 @override |
| 109 SuggestionBuilder visitNode(AstNode node) { | 105 SuggestionBuilder visitNode(AstNode node) { |
| 110 return null; | 106 return null; |
| 111 } | 107 } |
| 112 | 108 |
| 113 @override | 109 @override |
| 114 SuggestionBuilder visitPrefixedIdentifier(PrefixedIdentifier node) { | 110 SuggestionBuilder visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 115 // some PrefixedIdentifier nodes are transformed into | 111 // some PrefixedIdentifier nodes are transformed into |
| 116 // ConstructorName nodes during the resolution process. | 112 // ConstructorName nodes during the resolution process. |
| 117 Token period = node.period; | 113 return new _PrefixedIdentifierSuggestionBuilder(request); |
| 118 if (period != null && request.offset > period.offset) { | |
| 119 SimpleIdentifier prefix = node.prefix; | |
| 120 if (prefix != null) { | |
| 121 return new _PrefixedIdentifierSuggestionBuilder(request); | |
| 122 } | |
| 123 } | |
| 124 return null; | |
| 125 } | 114 } |
| 126 | 115 |
| 127 @override | 116 @override |
| 128 SuggestionBuilder visitPropertyAccess(PropertyAccess node) { | 117 SuggestionBuilder visitPropertyAccess(PropertyAccess node) { |
| 129 Token operator = node.operator; | 118 return new _ExpressionSuggestionBuilder(request); |
| 130 if (operator != null && operator.offset < request.offset) { | |
| 131 return new _ExpressionSuggestionBuilder(request); | |
| 132 } | |
| 133 return null; | |
| 134 } | 119 } |
| 135 | 120 |
| 136 @override | 121 @override |
| 137 SuggestionBuilder visitSimpleIdentifier(SimpleIdentifier node) { | 122 SuggestionBuilder visitSimpleIdentifier(SimpleIdentifier node) { |
| 138 return node.parent.accept(this); | 123 return node.parent.accept(this); |
| 139 } | 124 } |
| 140 } | 125 } |
| 141 | 126 |
| 142 /** | 127 /** |
| 143 * An [Element] visitor for determining the appropriate invocation/access | 128 * An [Element] visitor for determining the appropriate invocation/access |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 222 |
| 238 @override | 223 @override |
| 239 Future<bool> visitVariableElement(VariableElement element) { | 224 Future<bool> visitVariableElement(VariableElement element) { |
| 240 DartType type = element.type; | 225 DartType type = element.type; |
| 241 if (type != null) { | 226 if (type != null) { |
| 242 ClassElementSuggestionBuilder.suggestionsFor(request, type.element); | 227 ClassElementSuggestionBuilder.suggestionsFor(request, type.element); |
| 243 } | 228 } |
| 244 return new Future.value(true); | 229 return new Future.value(true); |
| 245 } | 230 } |
| 246 } | 231 } |
| OLD | NEW |