Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/prefixed_element_contributor.dart

Issue 1507513002: extract field formal contributor from prefixed element contributor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.contributor.dart.invocation; 5 library services.completion.contributor.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';
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 InterfaceTypeSuggestionBuilder.suggestionsFor(request, node.bestType, 90 InterfaceTypeSuggestionBuilder.suggestionsFor(request, node.bestType,
91 isSuper: isSuper, containingMethodName: containingMethodName); 91 isSuper: isSuper, containingMethodName: containingMethodName);
92 return new Future.value(true); 92 return new Future.value(true);
93 } 93 }
94 return new Future.value(false); 94 return new Future.value(false);
95 } 95 }
96 } 96 }
97 97
98 /** 98 /**
99 * A suggestion builder for 'this.' constructor arguments.
100 */
101 class _FieldFormalSuggestionBuilder implements SuggestionBuilder {
102 final DartCompletionRequest request;
103
104 _FieldFormalSuggestionBuilder(this.request);
105
106 @override
107 bool computeFast(AstNode node) {
108 if (node is FieldFormalParameter) {
109 ConstructorDeclaration constructorDecl =
110 node.getAncestor((p) => p is ConstructorDeclaration);
111 if (constructorDecl != null) {
112 // Compute fields already referenced
113 List<String> referencedFields = new List<String>();
114 for (FormalParameter param in constructorDecl.parameters.parameters) {
115 if (param is FieldFormalParameter) {
116 SimpleIdentifier fieldId = param.identifier;
117 if (fieldId != null && fieldId != request.target.entity) {
118 String fieldName = fieldId.name;
119 if (fieldName != null && fieldName.length > 0) {
120 referencedFields.add(fieldName);
121 }
122 }
123 }
124 }
125
126 // Add suggestions for fields that are not already referenced
127 ClassDeclaration classDecl =
128 constructorDecl.getAncestor((p) => p is ClassDeclaration);
129 for (ClassMember member in classDecl.members) {
130 if (member is FieldDeclaration && !member.isStatic) {
131 for (VariableDeclaration varDecl in member.fields.variables) {
132 SimpleIdentifier fieldId = varDecl.name;
133 if (fieldId != null) {
134 String fieldName = fieldId.name;
135 if (fieldName != null && fieldName.length > 0) {
136 if (!referencedFields.contains(fieldName)) {
137 CompletionSuggestion suggestion =
138 createFieldSuggestion(request.source, member, varDecl);
139 if (suggestion != null) {
140 request.addSuggestion(suggestion);
141 }
142 }
143 }
144 }
145 }
146 }
147 }
148 }
149 } else {
150 // This should never be called with a case not handled above.
151 assert(false);
152 }
153 return true;
154 }
155
156 @override
157 Future<bool> computeFull(AstNode node) {
158 // This should never be called; we should always be able to compute
159 // suggestions and return true in computeFast method.
160 assert(false);
161 return null;
162 }
163 }
164
165 /**
166 * An [AstNode] vistor for determining which suggestion builder 99 * An [AstNode] vistor for determining which suggestion builder
167 * should be used to build invocation/access suggestions. 100 * should be used to build invocation/access suggestions.
168 */ 101 */
169 class _InvocationAstVisitor extends GeneralizingAstVisitor<SuggestionBuilder> { 102 class _InvocationAstVisitor extends GeneralizingAstVisitor<SuggestionBuilder> {
170 final DartCompletionRequest request; 103 final DartCompletionRequest request;
171 104
172 _InvocationAstVisitor(this.request); 105 _InvocationAstVisitor(this.request);
173 106
174 @override 107 @override
175 SuggestionBuilder visitConstructorName(ConstructorName node) { 108 SuggestionBuilder visitConstructorName(ConstructorName node) {
176 // some PrefixedIdentifier nodes are transformed into 109 // some PrefixedIdentifier nodes are transformed into
177 // ConstructorName nodes during the resolution process. 110 // ConstructorName nodes during the resolution process.
178 return new _PrefixedIdentifierSuggestionBuilder(request); 111 return new _PrefixedIdentifierSuggestionBuilder(request);
179 } 112 }
180 113
181 @override 114 @override
182 SuggestionBuilder visitFieldFormalParameter(FieldFormalParameter node) {
183 return new _FieldFormalSuggestionBuilder(request);
184 }
185
186 @override
187 SuggestionBuilder visitMethodInvocation(MethodInvocation node) { 115 SuggestionBuilder visitMethodInvocation(MethodInvocation node) {
188 return new _ExpressionSuggestionBuilder(request); 116 return new _ExpressionSuggestionBuilder(request);
189 } 117 }
190 118
191 @override 119 @override
192 SuggestionBuilder visitNode(AstNode node) { 120 SuggestionBuilder visitNode(AstNode node) {
193 return null; 121 return null;
194 } 122 }
195 123
196 @override 124 @override
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 361 }
434 return new Future.value(false); 362 return new Future.value(false);
435 } 363 }
436 364
437 @override 365 @override
438 Future<bool> visitVariableElement(VariableElement element) { 366 Future<bool> visitVariableElement(VariableElement element) {
439 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type); 367 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type);
440 return new Future.value(true); 368 return new Future.value(true);
441 } 369 }
442 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698