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

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

Issue 664523003: improve element parameter string returned by local suggestion computer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 2 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 }); 289 });
290 } 290 }
291 291
292 void _addClassSuggestion(ClassDeclaration declaration) { 292 void _addClassSuggestion(ClassDeclaration declaration) {
293 CompletionSuggestion suggestion = 293 CompletionSuggestion suggestion =
294 _addSuggestion(declaration.name, CompletionSuggestionKind.CLASS, null, n ull); 294 _addSuggestion(declaration.name, CompletionSuggestionKind.CLASS, null, n ull);
295 if (suggestion != null) { 295 if (suggestion != null) {
296 suggestion.element = _createElement( 296 suggestion.element = _createElement(
297 protocol.ElementKind.CLASS, 297 protocol.ElementKind.CLASS,
298 declaration.name, 298 declaration.name,
299 null,
299 NO_RETURN_TYPE, 300 NO_RETURN_TYPE,
300 declaration.isAbstract, 301 declaration.isAbstract,
301 _isDeprecated(declaration.metadata)); 302 _isDeprecated(declaration.metadata));
302 } 303 }
303 } 304 }
304 305
305 void _addFieldSuggestions(ClassDeclaration node, FieldDeclaration fieldDecl) { 306 void _addFieldSuggestions(ClassDeclaration node, FieldDeclaration fieldDecl) {
306 if (typesOnly) { 307 if (typesOnly) {
307 return; 308 return;
308 } 309 }
309 bool isDeprecated = _isDeprecated(fieldDecl.metadata); 310 bool isDeprecated = _isDeprecated(fieldDecl.metadata);
310 fieldDecl.fields.variables.forEach((VariableDeclaration varDecl) { 311 fieldDecl.fields.variables.forEach((VariableDeclaration varDecl) {
311 CompletionSuggestion suggestion = _addSuggestion( 312 CompletionSuggestion suggestion = _addSuggestion(
312 varDecl.name, 313 varDecl.name,
313 CompletionSuggestionKind.GETTER, 314 CompletionSuggestionKind.GETTER,
314 fieldDecl.fields.type, 315 fieldDecl.fields.type,
315 node); 316 node);
316 if (suggestion != null) { 317 if (suggestion != null) {
317 suggestion.element = _createElement( 318 suggestion.element = _createElement(
318 protocol.ElementKind.GETTER, 319 protocol.ElementKind.GETTER,
319 varDecl.name, 320 varDecl.name,
321 '()',
320 fieldDecl.fields.type, 322 fieldDecl.fields.type,
321 false, 323 false,
322 isDeprecated || _isDeprecated(varDecl.metadata)); 324 isDeprecated || _isDeprecated(varDecl.metadata));
323 } 325 }
324 }); 326 });
325 } 327 }
326 328
327 void _addFunctionSuggestion(FunctionDeclaration declaration) { 329 void _addFunctionSuggestion(FunctionDeclaration declaration) {
328 if (typesOnly) { 330 if (typesOnly) {
329 return; 331 return;
330 } 332 }
331 if (excludeVoidReturn && _isVoid(declaration.returnType)) { 333 if (excludeVoidReturn && _isVoid(declaration.returnType)) {
332 return; 334 return;
333 } 335 }
334 CompletionSuggestion suggestion = _addSuggestion( 336 CompletionSuggestion suggestion = _addSuggestion(
335 declaration.name, 337 declaration.name,
336 CompletionSuggestionKind.FUNCTION, 338 CompletionSuggestionKind.FUNCTION,
337 declaration.returnType, 339 declaration.returnType,
338 null); 340 null);
339 if (suggestion != null) { 341 if (suggestion != null) {
340 suggestion.element = _createElement( 342 suggestion.element = _createElement(
341 protocol.ElementKind.FUNCTION, 343 protocol.ElementKind.FUNCTION,
342 declaration.name, 344 declaration.name,
345 declaration.functionExpression.parameters.toSource(),
343 declaration.returnType, 346 declaration.returnType,
344 false, 347 false,
345 _isDeprecated(declaration.metadata)); 348 _isDeprecated(declaration.metadata));
346 } 349 }
347 } 350 }
348 351
349 void _addLocalVarSuggestion(SimpleIdentifier id, TypeName returnType) { 352 void _addLocalVarSuggestion(SimpleIdentifier id, TypeName returnType) {
350 if (typesOnly) { 353 if (typesOnly) {
351 return; 354 return;
352 } 355 }
353 CompletionSuggestion suggestion = 356 CompletionSuggestion suggestion =
354 _addSuggestion(id, CompletionSuggestionKind.LOCAL_VARIABLE, returnType, null); 357 _addSuggestion(id, CompletionSuggestionKind.LOCAL_VARIABLE, returnType, null);
355 if (suggestion != null) { 358 if (suggestion != null) {
356 suggestion.element = _createElement( 359 suggestion.element = _createElement(
357 protocol.ElementKind.LOCAL_VARIABLE, 360 protocol.ElementKind.LOCAL_VARIABLE,
358 id, 361 id,
362 null,
359 returnType, 363 returnType,
360 false, 364 false,
361 false); 365 false);
362 } 366 }
363 } 367 }
364 368
365 void _addMethodSuggestion(ClassDeclaration node, MethodDeclaration classMbr) { 369 void _addMethodSuggestion(ClassDeclaration node, MethodDeclaration classMbr) {
366 if (typesOnly) { 370 if (typesOnly) {
367 return; 371 return;
368 } 372 }
369 protocol.ElementKind kind; 373 protocol.ElementKind kind;
370 CompletionSuggestionKind csKind; 374 CompletionSuggestionKind csKind;
375 String parameters;
371 if (classMbr.isGetter) { 376 if (classMbr.isGetter) {
372 kind = protocol.ElementKind.GETTER; 377 kind = protocol.ElementKind.GETTER;
373 csKind = CompletionSuggestionKind.GETTER; 378 csKind = CompletionSuggestionKind.GETTER;
379 parameters = '()';
374 } else if (classMbr.isSetter) { 380 } else if (classMbr.isSetter) {
375 if (excludeVoidReturn) { 381 if (excludeVoidReturn) {
376 return; 382 return;
377 } 383 }
378 kind = protocol.ElementKind.SETTER; 384 kind = protocol.ElementKind.SETTER;
379 csKind = CompletionSuggestionKind.SETTER; 385 csKind = CompletionSuggestionKind.SETTER;
386 parameters = '(${classMbr.returnType.toSource()} value)';
380 } else { 387 } else {
381 if (excludeVoidReturn && _isVoid(classMbr.returnType)) { 388 if (excludeVoidReturn && _isVoid(classMbr.returnType)) {
382 return; 389 return;
383 } 390 }
384 kind = protocol.ElementKind.METHOD; 391 kind = protocol.ElementKind.METHOD;
385 csKind = CompletionSuggestionKind.METHOD; 392 csKind = CompletionSuggestionKind.METHOD;
393 parameters = classMbr.parameters.toSource();
386 } 394 }
387 CompletionSuggestion suggestion = 395 CompletionSuggestion suggestion =
388 _addSuggestion(classMbr.name, csKind, classMbr.returnType, node); 396 _addSuggestion(classMbr.name, csKind, classMbr.returnType, node);
389 if (suggestion != null) { 397 if (suggestion != null) {
390 suggestion.element = _createElement( 398 suggestion.element = _createElement(
391 kind, 399 kind,
392 classMbr.name, 400 classMbr.name,
401 parameters,
393 classMbr.returnType, 402 classMbr.returnType,
394 classMbr.isAbstract, 403 classMbr.isAbstract,
395 _isDeprecated(classMbr.metadata)); 404 _isDeprecated(classMbr.metadata));
396 } 405 }
397 } 406 }
398 407
399 void _addParamListSuggestions(FormalParameterList paramList) { 408 void _addParamListSuggestions(FormalParameterList paramList) {
400 if (typesOnly) { 409 if (typesOnly) {
401 return; 410 return;
402 } 411 }
(...skipping 18 matching lines...) Expand all
421 } 430 }
422 } 431 }
423 432
424 void _addParamSuggestion(SimpleIdentifier identifier, TypeName type) { 433 void _addParamSuggestion(SimpleIdentifier identifier, TypeName type) {
425 if (typesOnly) { 434 if (typesOnly) {
426 return; 435 return;
427 } 436 }
428 CompletionSuggestion suggestion = 437 CompletionSuggestion suggestion =
429 _addSuggestion(identifier, CompletionSuggestionKind.PARAMETER, type, nul l); 438 _addSuggestion(identifier, CompletionSuggestionKind.PARAMETER, type, nul l);
430 if (suggestion != null) { 439 if (suggestion != null) {
431 suggestion.element = 440 suggestion.element = _createElement(
432 _createElement(protocol.ElementKind.PARAMETER, identifier, type, false , false); 441 protocol.ElementKind.PARAMETER,
442 identifier,
443 null,
444 type,
445 false,
446 false);
433 } 447 }
434 } 448 }
435 449
436 CompletionSuggestion _addSuggestion(SimpleIdentifier id, 450 CompletionSuggestion _addSuggestion(SimpleIdentifier id,
437 CompletionSuggestionKind kind, TypeName typeName, ClassDeclaration classDe cl) { 451 CompletionSuggestionKind kind, TypeName typeName, ClassDeclaration classDe cl) {
438 if (id != null) { 452 if (id != null) {
439 String completion = id.name; 453 String completion = id.name;
440 if (completion != null && completion.length > 0 && completion != '_') { 454 if (completion != null && completion.length > 0 && completion != '_') {
441 CompletionSuggestion suggestion = new CompletionSuggestion( 455 CompletionSuggestion suggestion = new CompletionSuggestion(
442 kind, 456 kind,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 varList.variables.forEach((VariableDeclaration varDecl) { 494 varList.variables.forEach((VariableDeclaration varDecl) {
481 CompletionSuggestion suggestion = _addSuggestion( 495 CompletionSuggestion suggestion = _addSuggestion(
482 varDecl.name, 496 varDecl.name,
483 CompletionSuggestionKind.TOP_LEVEL_VARIABLE, 497 CompletionSuggestionKind.TOP_LEVEL_VARIABLE,
484 varList.type, 498 varList.type,
485 null); 499 null);
486 if (suggestion != null) { 500 if (suggestion != null) {
487 suggestion.element = _createElement( 501 suggestion.element = _createElement(
488 protocol.ElementKind.TOP_LEVEL_VARIABLE, 502 protocol.ElementKind.TOP_LEVEL_VARIABLE,
489 varDecl.name, 503 varDecl.name,
504 null,
490 varList.type, 505 varList.type,
491 false, 506 false,
492 isDeprecated || _isDeprecated(varDecl.metadata)); 507 isDeprecated || _isDeprecated(varDecl.metadata));
493 } 508 }
494 }); 509 });
495 } 510 }
496 } 511 }
497 512
498 bool _computeExcludeVoidReturn(AstNode node) { 513 bool _computeExcludeVoidReturn(AstNode node) {
499 if (node is Block) { 514 if (node is Block) {
500 return false; 515 return false;
501 } else if (node is SimpleIdentifier) { 516 } else if (node is SimpleIdentifier) {
502 return node.parent is ExpressionStatement ? false : true; 517 return node.parent is ExpressionStatement ? false : true;
503 } else { 518 } else {
504 return true; 519 return true;
505 } 520 }
506 } 521 }
507 522
508 /** 523 /**
509 * Create a new protocol Element for inclusion in a completion suggestion. 524 * Create a new protocol Element for inclusion in a completion suggestion.
510 */ 525 */
511 protocol.Element _createElement(protocol.ElementKind kind, 526 protocol.Element _createElement(protocol.ElementKind kind,
512 SimpleIdentifier id, TypeName returnType, bool isAbstract, bool isDeprecat ed) { 527 SimpleIdentifier id, String parameters, TypeName returnType,
528 bool isAbstract, bool isDeprecated) {
513 String name = id.name; 529 String name = id.name;
514 int flags = protocol.Element.makeFlags( 530 int flags = protocol.Element.makeFlags(
515 isAbstract: isAbstract, 531 isAbstract: isAbstract,
516 isDeprecated: isDeprecated, 532 isDeprecated: isDeprecated,
517 isPrivate: Identifier.isPrivateName(name)); 533 isPrivate: Identifier.isPrivateName(name));
518 return new protocol.Element( 534 return new protocol.Element(
519 kind, 535 kind,
520 name, 536 name,
521 flags, 537 flags,
538 parameters: parameters,
522 returnType: _nameForType(returnType)); 539 returnType: _nameForType(returnType));
523 } 540 }
524 541
525 /** 542 /**
526 * Return `true` if the @deprecated annotation is present 543 * Return `true` if the @deprecated annotation is present
527 */ 544 */
528 bool _isDeprecated(NodeList<Annotation> metadata) => 545 bool _isDeprecated(NodeList<Annotation> metadata) =>
529 metadata != null && 546 metadata != null &&
530 metadata.any( 547 metadata.any(
531 (Annotation a) => a.name is SimpleIdentifier && a.name.name == 'de precated'); 548 (Annotation a) => a.name is SimpleIdentifier && a.name.name == 'de precated');
(...skipping 26 matching lines...) Expand all
558 if (name == null || name.length <= 0) { 575 if (name == null || name.length <= 0) {
559 return DYNAMIC; 576 return DYNAMIC;
560 } 577 }
561 TypeArgumentList typeArgs = type.typeArguments; 578 TypeArgumentList typeArgs = type.typeArguments;
562 if (typeArgs != null) { 579 if (typeArgs != null) {
563 //TODO (danrubel) include type arguments 580 //TODO (danrubel) include type arguments
564 } 581 }
565 return name; 582 return name;
566 } 583 }
567 } 584 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698