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

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

Issue 791553007: suggest fields rather than synthetic getters (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 11 months 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 | Annotate | Revision Log
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.computer.dart.local; 5 library services.completion.computer.dart.local;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element,
10 ElementKind; 10 ElementKind;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 final bool excludeVoidReturn; 183 final bool excludeVoidReturn;
184 184
185 _LocalVisitor(this.request, int offset, this.typesOnly, 185 _LocalVisitor(this.request, int offset, this.typesOnly,
186 this.excludeVoidReturn) 186 this.excludeVoidReturn)
187 : super(offset); 187 : super(offset);
188 188
189 @override 189 @override
190 void declaredClass(ClassDeclaration declaration) { 190 void declaredClass(ClassDeclaration declaration) {
191 bool isDeprecated = _isDeprecated(declaration); 191 bool isDeprecated = _isDeprecated(declaration);
192 CompletionSuggestion suggestion = 192 CompletionSuggestion suggestion =
193 _addSuggestion(declaration.name, null, null, isDeprecated); 193 _addSuggestion(declaration.name, NO_RETURN_TYPE, null, isDeprecated);
194 if (suggestion != null) { 194 if (suggestion != null) {
195 suggestion.element = _createElement( 195 suggestion.element = _createElement(
196 protocol.ElementKind.CLASS, 196 protocol.ElementKind.CLASS,
197 declaration.name, 197 declaration.name,
198 null, 198 null,
199 _LocalVisitor.NO_RETURN_TYPE, 199 NO_RETURN_TYPE,
200 declaration.isAbstract, 200 declaration.isAbstract,
201 isDeprecated); 201 isDeprecated);
202 } 202 }
203 } 203 }
204 204
205 @override 205 @override
206 void declaredClassTypeAlias(ClassTypeAlias declaration) { 206 void declaredClassTypeAlias(ClassTypeAlias declaration) {
207 bool isDeprecated = _isDeprecated(declaration); 207 bool isDeprecated = _isDeprecated(declaration);
208 CompletionSuggestion suggestion = 208 CompletionSuggestion suggestion =
209 _addSuggestion(declaration.name, null, null, isDeprecated); 209 _addSuggestion(declaration.name, NO_RETURN_TYPE, null, isDeprecated);
210 if (suggestion != null) { 210 if (suggestion != null) {
211 suggestion.element = _createElement( 211 suggestion.element = _createElement(
212 protocol.ElementKind.CLASS_TYPE_ALIAS, 212 protocol.ElementKind.CLASS_TYPE_ALIAS,
213 declaration.name, 213 declaration.name,
214 null, 214 null,
215 NO_RETURN_TYPE, 215 NO_RETURN_TYPE,
216 true, 216 true,
217 isDeprecated); 217 isDeprecated);
218 } 218 }
219 } 219 }
220 220
221 @override 221 @override
222 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { 222 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
223 if (typesOnly) { 223 if (typesOnly) {
224 return; 224 return;
225 } 225 }
226 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl); 226 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl);
227 TypeName type = fieldDecl.fields.type;
227 CompletionSuggestion suggestion = 228 CompletionSuggestion suggestion =
228 _addSuggestion(varDecl.name, null, fieldDecl.parent, isDeprecated); 229 _addSuggestion(varDecl.name, type, fieldDecl.parent, isDeprecated);
229 if (suggestion != null) { 230 if (suggestion != null) {
230 suggestion.element = _createElement( 231 suggestion.element = _createElement(
231 protocol.ElementKind.FIELD, 232 protocol.ElementKind.FIELD,
232 varDecl.name, 233 varDecl.name,
233 null, 234 null,
234 null, 235 type,
235 false, 236 false,
236 isDeprecated); 237 isDeprecated);
237 } 238 }
238 } 239 }
239 240
240 @override 241 @override
241 void declaredFunction(FunctionDeclaration declaration) { 242 void declaredFunction(FunctionDeclaration declaration) {
242 if (typesOnly) { 243 if (typesOnly) {
243 return; 244 return;
244 } 245 }
245 if (excludeVoidReturn && _isVoid(declaration.returnType)) { 246 TypeName returnType = declaration.returnType;
246 return; 247 bool isDeprecated = _isDeprecated(declaration);
248 protocol.ElementKind kind;
249 if (declaration.isGetter) {
250 kind = protocol.ElementKind.GETTER;
251 } else if (declaration.isSetter) {
252 if (excludeVoidReturn) {
253 return;
254 }
255 kind = protocol.ElementKind.SETTER;
256 returnType = NO_RETURN_TYPE;
257 } else {
258 if (excludeVoidReturn && _isVoid(returnType)) {
259 return;
260 }
261 kind = protocol.ElementKind.FUNCTION;
247 } 262 }
248 bool isDeprecated = _isDeprecated(declaration);
249 CompletionSuggestion suggestion = 263 CompletionSuggestion suggestion =
250 _addSuggestion(declaration.name, declaration.returnType, null, isDepreca ted); 264 _addSuggestion(declaration.name, returnType, null, isDeprecated);
251 if (suggestion != null) { 265 if (suggestion != null) {
252 FormalParameterList param = declaration.functionExpression.parameters; 266 FormalParameterList param = declaration.functionExpression.parameters;
253 protocol.ElementKind kind;
254 if (declaration.isGetter) {
255 kind = protocol.ElementKind.GETTER;
256 } else if (declaration.isSetter) {
257 kind = protocol.ElementKind.SETTER;
258 } else {
259 kind = protocol.ElementKind.FUNCTION;
260 }
261 suggestion.element = _createElement( 267 suggestion.element = _createElement(
262 kind, 268 kind,
263 declaration.name, 269 declaration.name,
264 param != null ? param.toSource() : null, 270 param != null ? param.toSource() : null,
265 declaration.returnType, 271 returnType,
266 false, 272 false,
267 isDeprecated); 273 isDeprecated);
268 } 274 }
269 } 275 }
270 276
271 @override 277 @override
272 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { 278 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {
273 bool isDeprecated = _isDeprecated(declaration); 279 bool isDeprecated = _isDeprecated(declaration);
280 TypeName returnType = declaration.returnType;
274 CompletionSuggestion suggestion = 281 CompletionSuggestion suggestion =
275 _addSuggestion(declaration.name, declaration.returnType, null, isDepreca ted); 282 _addSuggestion(declaration.name, returnType, null, isDeprecated);
276 if (suggestion != null) { 283 if (suggestion != null) {
277 // TODO (danrubel) determine parameters and return type 284 // TODO (danrubel) determine parameters and return type
278 suggestion.element = _createElement( 285 suggestion.element = _createElement(
279 protocol.ElementKind.FUNCTION_TYPE_ALIAS, 286 protocol.ElementKind.FUNCTION_TYPE_ALIAS,
280 declaration.name, 287 declaration.name,
281 null, 288 null,
282 NO_RETURN_TYPE, 289 returnType,
283 true, 290 true,
284 isDeprecated); 291 isDeprecated);
285 } 292 }
286 } 293 }
287 294
288 @override 295 @override
289 void declaredLabel(Label label) { 296 void declaredLabel(Label label) {
290 // ignored 297 // ignored
291 } 298 }
292 299
(...skipping 23 matching lines...) Expand all
316 String parameters; 323 String parameters;
317 TypeName returnType = declaration.returnType; 324 TypeName returnType = declaration.returnType;
318 if (declaration.isGetter) { 325 if (declaration.isGetter) {
319 kind = protocol.ElementKind.GETTER; 326 kind = protocol.ElementKind.GETTER;
320 parameters = null; 327 parameters = null;
321 } else if (declaration.isSetter) { 328 } else if (declaration.isSetter) {
322 if (excludeVoidReturn) { 329 if (excludeVoidReturn) {
323 return; 330 return;
324 } 331 }
325 kind = protocol.ElementKind.SETTER; 332 kind = protocol.ElementKind.SETTER;
326 returnType = null; 333 returnType = NO_RETURN_TYPE;
327 } else { 334 } else {
328 if (excludeVoidReturn && _isVoid(returnType)) { 335 if (excludeVoidReturn && _isVoid(returnType)) {
329 return; 336 return;
330 } 337 }
331 kind = protocol.ElementKind.METHOD; 338 kind = protocol.ElementKind.METHOD;
332 parameters = declaration.parameters.toSource(); 339 parameters = declaration.parameters.toSource();
333 } 340 }
334 bool isDeprecated = _isDeprecated(declaration); 341 bool isDeprecated = _isDeprecated(declaration);
335 CompletionSuggestion suggestion = 342 CompletionSuggestion suggestion =
336 _addSuggestion(declaration.name, returnType, declaration.parent, isDepre cated); 343 _addSuggestion(declaration.name, returnType, declaration.parent, isDepre cated);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (id != null) { 389 if (id != null) {
383 String completion = id.name; 390 String completion = id.name;
384 if (completion != null && completion.length > 0 && completion != '_') { 391 if (completion != null && completion.length > 0 && completion != '_') {
385 CompletionSuggestion suggestion = new CompletionSuggestion( 392 CompletionSuggestion suggestion = new CompletionSuggestion(
386 CompletionSuggestionKind.INVOCATION, 393 CompletionSuggestionKind.INVOCATION,
387 isDeprecated ? COMPLETION_RELEVANCE_LOW : COMPLETION_RELEVANCE_DEFAU LT, 394 isDeprecated ? COMPLETION_RELEVANCE_LOW : COMPLETION_RELEVANCE_DEFAU LT,
388 completion, 395 completion,
389 completion.length, 396 completion.length,
390 0, 397 0,
391 false, 398 false,
392 false); 399 false,
400 returnType: _nameForType(returnType));
393 if (classDecl != null) { 401 if (classDecl != null) {
394 SimpleIdentifier identifier = classDecl.name; 402 SimpleIdentifier identifier = classDecl.name;
395 if (identifier != null) { 403 if (identifier != null) {
396 String name = identifier.name; 404 String name = identifier.name;
397 if (name != null && name.length > 0) { 405 if (name != null && name.length > 0) {
398 suggestion.declaringType = name; 406 suggestion.declaringType = name;
399 } 407 }
400 } 408 }
401 } 409 }
402 if (returnType != null) {
403 Identifier identifier = returnType.name;
404 if (identifier != null) {
405 String name = identifier.name;
406 if (name != null && name.length > 0) {
407 suggestion.returnType = name;
408 }
409 }
410 }
411 request.suggestions.add(suggestion); 410 request.suggestions.add(suggestion);
412 return suggestion; 411 return suggestion;
413 } 412 }
414 } 413 }
415 return null; 414 return null;
416 } 415 }
417 416
418 417
419 /** 418 /**
420 * Create a new protocol Element for inclusion in a completion suggestion. 419 * Create a new protocol Element for inclusion in a completion suggestion.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 if (name == null || name.length <= 0) { 477 if (name == null || name.length <= 0) {
479 return DYNAMIC; 478 return DYNAMIC;
480 } 479 }
481 TypeArgumentList typeArgs = type.typeArguments; 480 TypeArgumentList typeArgs = type.typeArguments;
482 if (typeArgs != null) { 481 if (typeArgs != null) {
483 //TODO (danrubel) include type arguments 482 //TODO (danrubel) include type arguments
484 } 483 }
485 return name; 484 return name;
486 } 485 }
487 } 486 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698