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

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

Issue 1082233003: suggest "this." local fields in constructor param (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 8 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/local_suggestion_builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.local; 5 library services.completion.contributor.dart.local;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' as protocol 9 import 'package:analysis_server/src/protocol.dart' as protocol
10 show Element, ElementKind; 10 show Element, ElementKind;
11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind;
12 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 12 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
13 import 'package:analysis_server/src/services/completion/local_declaration_visito r.dart'; 13 import 'package:analysis_server/src/services/completion/local_declaration_visito r.dart';
14 import 'package:analysis_server/src/services/completion/local_suggestion_builder .dart';
14 import 'package:analysis_server/src/services/completion/optype.dart'; 15 import 'package:analysis_server/src/services/completion/optype.dart';
15 import 'package:analyzer/src/generated/ast.dart'; 16 import 'package:analyzer/src/generated/ast.dart';
16 import 'package:analyzer/src/generated/scanner.dart';
17 import 'package:analyzer/src/generated/utilities_dart.dart'; 17 import 'package:analyzer/src/generated/utilities_dart.dart';
18 18
19 const _DYNAMIC = 'dynamic';
20
21 final TypeName _NO_RETURN_TYPE = new TypeName(
22 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null);
23
24 /**
25 * Create a new protocol Element for inclusion in a completion suggestion.
26 */
27 protocol.Element _createElement(protocol.ElementKind kind, SimpleIdentifier id,
28 {String parameters, TypeName returnType, bool isAbstract: false,
29 bool isDeprecated: false}) {
30 String name = id != null ? id.name : '';
31 int flags = protocol.Element.makeFlags(
32 isAbstract: isAbstract,
33 isDeprecated: isDeprecated,
34 isPrivate: Identifier.isPrivateName(name));
35 return new protocol.Element(kind, name, flags,
36 parameters: parameters, returnType: _nameForType(returnType));
37 }
38
39 /**
40 * Return `true` if the @deprecated annotation is present
41 */
42 bool _isDeprecated(AnnotatedNode node) {
43 if (node != null) {
44 NodeList<Annotation> metadata = node.metadata;
45 if (metadata != null) {
46 return metadata.any((Annotation a) {
47 return a.name is SimpleIdentifier && a.name.name == 'deprecated';
48 });
49 }
50 }
51 return false;
52 }
53
54 /**
55 * Return the name for the given type.
56 */
57 String _nameForType(TypeName type) {
58 if (type == _NO_RETURN_TYPE) {
59 return null;
60 }
61 if (type == null) {
62 return _DYNAMIC;
63 }
64 Identifier id = type.name;
65 if (id == null) {
66 return _DYNAMIC;
67 }
68 String name = id.name;
69 if (name == null || name.length <= 0) {
70 return _DYNAMIC;
71 }
72 TypeArgumentList typeArgs = type.typeArguments;
73 if (typeArgs != null) {
74 //TODO (danrubel) include type arguments
75 }
76 return name;
77 }
78
79 /** 19 /**
80 * A contributor for calculating `completion.getSuggestions` request results 20 * A contributor for calculating `completion.getSuggestions` request results
81 * for the local library in which the completion is requested. 21 * for the local library in which the completion is requested.
82 */ 22 */
83 class LocalReferenceContributor extends DartCompletionContributor { 23 class LocalReferenceContributor extends DartCompletionContributor {
84 @override 24 @override
85 bool computeFast(DartCompletionRequest request) { 25 bool computeFast(DartCompletionRequest request) {
86 OpType optype = request.optype; 26 OpType optype = request.optype;
87 27
88 // Collect suggestions from the specific child [AstNode] that contains 28 // Collect suggestions from the specific child [AstNode] that contains
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 String completion = classDecl.name.name; 150 String completion = classDecl.name.name;
211 if (constructorDecl != null) { 151 if (constructorDecl != null) {
212 elemId = constructorDecl.name; 152 elemId = constructorDecl.name;
213 if (elemId != null) { 153 if (elemId != null) {
214 String name = elemId.name; 154 String name = elemId.name;
215 if (name != null && name.length > 0) { 155 if (name != null && name.length > 0) {
216 completion = '$completion.$name'; 156 completion = '$completion.$name';
217 } 157 }
218 } 158 }
219 } 159 }
220 bool isDeprecated = 160 bool deprecated = constructorDecl != null && isDeprecated(constructorDecl);
221 constructorDecl != null && _isDeprecated(constructorDecl);
222 List<String> parameterNames = new List<String>(); 161 List<String> parameterNames = new List<String>();
223 List<String> parameterTypes = new List<String>(); 162 List<String> parameterTypes = new List<String>();
224 int requiredParameterCount = 0; 163 int requiredParameterCount = 0;
225 bool hasNamedParameters = false; 164 bool hasNamedParameters = false;
226 StringBuffer paramBuf = new StringBuffer(); 165 StringBuffer paramBuf = new StringBuffer();
227 paramBuf.write('('); 166 paramBuf.write('(');
228 int paramCount = 0; 167 int paramCount = 0;
229 if (constructorDecl != null) { 168 if (constructorDecl != null) {
230 for (FormalParameter param in constructorDecl.parameters.parameters) { 169 for (FormalParameter param in constructorDecl.parameters.parameters) {
231 if (paramCount > 0) { 170 if (paramCount > 0) {
(...skipping 21 matching lines...) Expand all
253 paramBuf.write(typeName); 192 paramBuf.write(typeName);
254 paramBuf.write(' '); 193 paramBuf.write(' ');
255 paramBuf.write(paramName); 194 paramBuf.write(paramName);
256 ++paramCount; 195 ++paramCount;
257 } 196 }
258 } 197 }
259 if (paramCount > requiredParameterCount) { 198 if (paramCount > requiredParameterCount) {
260 paramBuf.write(hasNamedParameters ? '}' : ']'); 199 paramBuf.write(hasNamedParameters ? '}' : ']');
261 } 200 }
262 paramBuf.write(')'); 201 paramBuf.write(')');
263 protocol.Element element = _createElement( 202 protocol.Element element = createElement(
264 protocol.ElementKind.CONSTRUCTOR, elemId, 203 protocol.ElementKind.CONSTRUCTOR, elemId,
265 parameters: paramBuf.toString()); 204 parameters: paramBuf.toString());
266 element.returnType = classDecl.name.name; 205 element.returnType = classDecl.name.name;
267 CompletionSuggestion suggestion = new CompletionSuggestion( 206 CompletionSuggestion suggestion = new CompletionSuggestion(
268 CompletionSuggestionKind.INVOCATION, 207 CompletionSuggestionKind.INVOCATION,
269 isDeprecated ? DART_RELEVANCE_LOW : DART_RELEVANCE_DEFAULT, completion, 208 deprecated ? DART_RELEVANCE_LOW : DART_RELEVANCE_DEFAULT, completion,
270 completion.length, 0, isDeprecated, false, 209 completion.length, 0, deprecated, false,
271 declaringType: classDecl.name.name, 210 declaringType: classDecl.name.name,
272 element: element, 211 element: element,
273 parameterNames: parameterNames, 212 parameterNames: parameterNames,
274 parameterTypes: parameterTypes, 213 parameterTypes: parameterTypes,
275 requiredParameterCount: requiredParameterCount, 214 requiredParameterCount: requiredParameterCount,
276 hasNamedParameters: hasNamedParameters); 215 hasNamedParameters: hasNamedParameters);
277 request.addSuggestion(suggestion); 216 request.addSuggestion(suggestion);
278 return suggestion; 217 return suggestion;
279 } 218 }
280 219
281 /** 220 /**
282 * Determine the name of the type for the given constructor parameter. 221 * Determine the name of the type for the given constructor parameter.
283 */ 222 */
284 String _nameForParamType(NormalFormalParameter param) { 223 String _nameForParamType(NormalFormalParameter param) {
285 if (param is SimpleFormalParameter) { 224 if (param is SimpleFormalParameter) {
286 return _nameForType(param.type); 225 return nameForType(param.type);
287 } 226 }
288 SimpleIdentifier id = param.identifier; 227 SimpleIdentifier id = param.identifier;
289 if (param is FieldFormalParameter && id != null) { 228 if (param is FieldFormalParameter && id != null) {
290 String fieldName = id.name; 229 String fieldName = id.name;
291 AstNode classDecl = param.getAncestor((p) => p is ClassDeclaration); 230 AstNode classDecl = param.getAncestor((p) => p is ClassDeclaration);
292 if (classDecl is ClassDeclaration) { 231 if (classDecl is ClassDeclaration) {
293 for (ClassMember member in classDecl.members) { 232 for (ClassMember member in classDecl.members) {
294 if (member is FieldDeclaration) { 233 if (member is FieldDeclaration) {
295 for (VariableDeclaration field in member.fields.variables) { 234 for (VariableDeclaration field in member.fields.variables) {
296 if (field.name.name == fieldName) { 235 if (field.name.name == fieldName) {
297 return _nameForType(member.fields.type); 236 return nameForType(member.fields.type);
298 } 237 }
299 } 238 }
300 } 239 }
301 } 240 }
302 } 241 }
303 } 242 }
304 return _DYNAMIC; 243 return DYNAMIC;
305 } 244 }
306 } 245 }
307 246
308 /** 247 /**
309 * A visitor for collecting suggestions for break and continue labels. 248 * A visitor for collecting suggestions for break and continue labels.
310 */ 249 */
311 class _LabelVisitor extends LocalDeclarationVisitor { 250 class _LabelVisitor extends LocalDeclarationVisitor {
312 final DartCompletionRequest request; 251 final DartCompletionRequest request;
313 252
314 /** 253 /**
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 */ 368 */
430 class _LocalVisitor extends LocalDeclarationVisitor { 369 class _LocalVisitor extends LocalDeclarationVisitor {
431 final DartCompletionRequest request; 370 final DartCompletionRequest request;
432 final OpType optype; 371 final OpType optype;
433 372
434 _LocalVisitor(this.request, int offset, this.optype) : super(offset); 373 _LocalVisitor(this.request, int offset, this.optype) : super(offset);
435 374
436 @override 375 @override
437 void declaredClass(ClassDeclaration declaration) { 376 void declaredClass(ClassDeclaration declaration) {
438 if (optype.includeTypeNameSuggestions) { 377 if (optype.includeTypeNameSuggestions) {
439 bool isDeprecated = _isDeprecated(declaration); 378 bool deprecated = isDeprecated(declaration);
440 CompletionSuggestion suggestion = _addSuggestion(declaration.name, 379 CompletionSuggestion suggestion = _addSuggestion(
441 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); 380 declaration.name, NO_RETURN_TYPE, deprecated, DART_RELEVANCE_DEFAULT);
442 if (suggestion != null) { 381 if (suggestion != null) {
443 suggestion.element = _createElement( 382 suggestion.element = createElement(
444 protocol.ElementKind.CLASS, declaration.name, 383 protocol.ElementKind.CLASS, declaration.name,
445 returnType: _NO_RETURN_TYPE, 384 returnType: NO_RETURN_TYPE,
446 isAbstract: declaration.isAbstract, 385 isAbstract: declaration.isAbstract,
447 isDeprecated: isDeprecated); 386 isDeprecated: deprecated);
448 } 387 }
449 } 388 }
450 } 389 }
451 390
452 @override 391 @override
453 void declaredClassTypeAlias(ClassTypeAlias declaration) { 392 void declaredClassTypeAlias(ClassTypeAlias declaration) {
454 if (optype.includeTypeNameSuggestions) { 393 if (optype.includeTypeNameSuggestions) {
455 bool isDeprecated = _isDeprecated(declaration); 394 bool deprecated = isDeprecated(declaration);
456 CompletionSuggestion suggestion = _addSuggestion(declaration.name, 395 CompletionSuggestion suggestion = _addSuggestion(
457 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); 396 declaration.name, NO_RETURN_TYPE, deprecated, DART_RELEVANCE_DEFAULT);
458 if (suggestion != null) { 397 if (suggestion != null) {
459 suggestion.element = _createElement( 398 suggestion.element = createElement(
460 protocol.ElementKind.CLASS_TYPE_ALIAS, declaration.name, 399 protocol.ElementKind.CLASS_TYPE_ALIAS, declaration.name,
461 returnType: _NO_RETURN_TYPE, 400 returnType: NO_RETURN_TYPE,
462 isAbstract: true, 401 isAbstract: true,
463 isDeprecated: isDeprecated); 402 isDeprecated: deprecated);
464 } 403 }
465 } 404 }
466 } 405 }
467 406
468 @override 407 @override
469 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { 408 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
470 if (optype.includeReturnValueSuggestions) { 409 if (optype.includeReturnValueSuggestions) {
471 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl); 410 CompletionSuggestion suggestion =
472 TypeName type = fieldDecl.fields.type; 411 createFieldSuggestion(fieldDecl, varDecl);
473 CompletionSuggestion suggestion = _addSuggestion(
474 varDecl.name, type, isDeprecated, DART_RELEVANCE_LOCAL_FIELD,
475 classDecl: fieldDecl.parent);
476 if (suggestion != null) { 412 if (suggestion != null) {
477 suggestion.element = _createElement( 413 request.addSuggestion(suggestion);
478 protocol.ElementKind.FIELD, varDecl.name,
479 returnType: type, isDeprecated: isDeprecated);
480 } 414 }
481 } 415 }
482 } 416 }
483 417
484 @override 418 @override
485 void declaredFunction(FunctionDeclaration declaration) { 419 void declaredFunction(FunctionDeclaration declaration) {
486 if (optype.includeReturnValueSuggestions || 420 if (optype.includeReturnValueSuggestions ||
487 optype.includeVoidReturnSuggestions) { 421 optype.includeVoidReturnSuggestions) {
488 TypeName returnType = declaration.returnType; 422 TypeName returnType = declaration.returnType;
489 bool isDeprecated = _isDeprecated(declaration); 423 bool deprecated = isDeprecated(declaration);
490 protocol.ElementKind kind; 424 protocol.ElementKind kind;
491 int defaultRelevance = DART_RELEVANCE_DEFAULT; 425 int defaultRelevance = DART_RELEVANCE_DEFAULT;
492 if (declaration.isGetter) { 426 if (declaration.isGetter) {
493 kind = protocol.ElementKind.GETTER; 427 kind = protocol.ElementKind.GETTER;
494 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; 428 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
495 } else if (declaration.isSetter) { 429 } else if (declaration.isSetter) {
496 if (!optype.includeVoidReturnSuggestions) { 430 if (!optype.includeVoidReturnSuggestions) {
497 return; 431 return;
498 } 432 }
499 kind = protocol.ElementKind.SETTER; 433 kind = protocol.ElementKind.SETTER;
500 returnType = _NO_RETURN_TYPE; 434 returnType = NO_RETURN_TYPE;
501 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; 435 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
502 } else { 436 } else {
503 if (!optype.includeVoidReturnSuggestions && _isVoid(returnType)) { 437 if (!optype.includeVoidReturnSuggestions && _isVoid(returnType)) {
504 return; 438 return;
505 } 439 }
506 kind = protocol.ElementKind.FUNCTION; 440 kind = protocol.ElementKind.FUNCTION;
507 defaultRelevance = DART_RELEVANCE_LOCAL_FUNCTION; 441 defaultRelevance = DART_RELEVANCE_LOCAL_FUNCTION;
508 } 442 }
509 CompletionSuggestion suggestion = _addSuggestion( 443 CompletionSuggestion suggestion = _addSuggestion(
510 declaration.name, returnType, isDeprecated, defaultRelevance); 444 declaration.name, returnType, deprecated, defaultRelevance);
511 if (suggestion != null) { 445 if (suggestion != null) {
512 FormalParameterList param = declaration.functionExpression.parameters; 446 FormalParameterList param = declaration.functionExpression.parameters;
513 suggestion.element = _createElement(kind, declaration.name, 447 suggestion.element = createElement(kind, declaration.name,
514 parameters: param != null ? param.toSource() : null, 448 parameters: param != null ? param.toSource() : null,
515 returnType: returnType, 449 returnType: returnType,
516 isDeprecated: isDeprecated); 450 isDeprecated: deprecated);
517 if (kind == protocol.ElementKind.FUNCTION) { 451 if (kind == protocol.ElementKind.FUNCTION) {
518 _addParameterInfo( 452 _addParameterInfo(
519 suggestion, declaration.functionExpression.parameters); 453 suggestion, declaration.functionExpression.parameters);
520 } 454 }
521 } 455 }
522 } 456 }
523 } 457 }
524 458
525 @override 459 @override
526 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { 460 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {
527 if (optype.includeTypeNameSuggestions) { 461 if (optype.includeTypeNameSuggestions) {
528 bool isDeprecated = _isDeprecated(declaration); 462 bool deprecated = isDeprecated(declaration);
529 TypeName returnType = declaration.returnType; 463 TypeName returnType = declaration.returnType;
530 CompletionSuggestion suggestion = _addSuggestion( 464 CompletionSuggestion suggestion = _addSuggestion(
531 declaration.name, returnType, isDeprecated, DART_RELEVANCE_DEFAULT); 465 declaration.name, returnType, deprecated, DART_RELEVANCE_DEFAULT);
532 if (suggestion != null) { 466 if (suggestion != null) {
533 // TODO (danrubel) determine parameters and return type 467 // TODO (danrubel) determine parameters and return type
534 suggestion.element = _createElement( 468 suggestion.element = createElement(
535 protocol.ElementKind.FUNCTION_TYPE_ALIAS, declaration.name, 469 protocol.ElementKind.FUNCTION_TYPE_ALIAS, declaration.name,
536 returnType: returnType, 470 returnType: returnType, isAbstract: true, isDeprecated: deprecated);
537 isAbstract: true,
538 isDeprecated: isDeprecated);
539 } 471 }
540 } 472 }
541 } 473 }
542 474
543 @override 475 @override
544 void declaredLabel(Label label, bool isCaseLabel) { 476 void declaredLabel(Label label, bool isCaseLabel) {
545 // ignored 477 // ignored
546 } 478 }
547 479
548 @override 480 @override
549 void declaredLocalVar(SimpleIdentifier name, TypeName type) { 481 void declaredLocalVar(SimpleIdentifier name, TypeName type) {
550 if (optype.includeReturnValueSuggestions) { 482 if (optype.includeReturnValueSuggestions) {
551 CompletionSuggestion suggestion = 483 CompletionSuggestion suggestion =
552 _addSuggestion(name, type, false, DART_RELEVANCE_LOCAL_VARIABLE); 484 _addSuggestion(name, type, false, DART_RELEVANCE_LOCAL_VARIABLE);
553 if (suggestion != null) { 485 if (suggestion != null) {
554 suggestion.element = _createElement( 486 suggestion.element = createElement(
555 protocol.ElementKind.LOCAL_VARIABLE, name, returnType: type); 487 protocol.ElementKind.LOCAL_VARIABLE, name, returnType: type);
556 } 488 }
557 } 489 }
558 } 490 }
559 491
560 @override 492 @override
561 void declaredMethod(MethodDeclaration declaration) { 493 void declaredMethod(MethodDeclaration declaration) {
562 if (optype.includeReturnValueSuggestions || 494 if (optype.includeReturnValueSuggestions ||
563 optype.includeVoidReturnSuggestions) { 495 optype.includeVoidReturnSuggestions) {
564 protocol.ElementKind kind; 496 protocol.ElementKind kind;
565 String parameters; 497 String parameters;
566 TypeName returnType = declaration.returnType; 498 TypeName returnType = declaration.returnType;
567 int defaultRelevance = DART_RELEVANCE_DEFAULT; 499 int defaultRelevance = DART_RELEVANCE_DEFAULT;
568 if (declaration.isGetter) { 500 if (declaration.isGetter) {
569 kind = protocol.ElementKind.GETTER; 501 kind = protocol.ElementKind.GETTER;
570 parameters = null; 502 parameters = null;
571 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; 503 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
572 } else if (declaration.isSetter) { 504 } else if (declaration.isSetter) {
573 if (!optype.includeVoidReturnSuggestions) { 505 if (!optype.includeVoidReturnSuggestions) {
574 return; 506 return;
575 } 507 }
576 kind = protocol.ElementKind.SETTER; 508 kind = protocol.ElementKind.SETTER;
577 returnType = _NO_RETURN_TYPE; 509 returnType = NO_RETURN_TYPE;
578 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; 510 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
579 } else { 511 } else {
580 if (!optype.includeVoidReturnSuggestions && _isVoid(returnType)) { 512 if (!optype.includeVoidReturnSuggestions && _isVoid(returnType)) {
581 return; 513 return;
582 } 514 }
583 kind = protocol.ElementKind.METHOD; 515 kind = protocol.ElementKind.METHOD;
584 parameters = declaration.parameters.toSource(); 516 parameters = declaration.parameters.toSource();
585 defaultRelevance = DART_RELEVANCE_LOCAL_METHOD; 517 defaultRelevance = DART_RELEVANCE_LOCAL_METHOD;
586 } 518 }
587 bool isDeprecated = _isDeprecated(declaration); 519 bool deprecated = isDeprecated(declaration);
588 CompletionSuggestion suggestion = _addSuggestion( 520 CompletionSuggestion suggestion = _addSuggestion(
589 declaration.name, returnType, isDeprecated, defaultRelevance, 521 declaration.name, returnType, deprecated, defaultRelevance,
590 classDecl: declaration.parent); 522 classDecl: declaration.parent);
591 if (suggestion != null) { 523 if (suggestion != null) {
592 suggestion.element = _createElement(kind, declaration.name, 524 suggestion.element = createElement(kind, declaration.name,
593 parameters: parameters, 525 parameters: parameters,
594 returnType: returnType, 526 returnType: returnType,
595 isAbstract: declaration.isAbstract, 527 isAbstract: declaration.isAbstract,
596 isDeprecated: isDeprecated); 528 isDeprecated: deprecated);
597 if (kind == protocol.ElementKind.METHOD) { 529 if (kind == protocol.ElementKind.METHOD) {
598 _addParameterInfo(suggestion, declaration.parameters); 530 _addParameterInfo(suggestion, declaration.parameters);
599 } 531 }
600 } 532 }
601 } 533 }
602 } 534 }
603 535
604 @override 536 @override
605 void declaredParam(SimpleIdentifier name, TypeName type) { 537 void declaredParam(SimpleIdentifier name, TypeName type) {
606 if (optype.includeReturnValueSuggestions) { 538 if (optype.includeReturnValueSuggestions) {
607 CompletionSuggestion suggestion = 539 CompletionSuggestion suggestion =
608 _addSuggestion(name, type, false, DART_RELEVANCE_PARAMETER); 540 _addSuggestion(name, type, false, DART_RELEVANCE_PARAMETER);
609 if (suggestion != null) { 541 if (suggestion != null) {
610 suggestion.element = _createElement( 542 suggestion.element = createElement(protocol.ElementKind.PARAMETER, name,
611 protocol.ElementKind.PARAMETER, name, returnType: type); 543 returnType: type);
612 } 544 }
613 } 545 }
614 } 546 }
615 547
616 @override 548 @override
617 void declaredTopLevelVar( 549 void declaredTopLevelVar(
618 VariableDeclarationList varList, VariableDeclaration varDecl) { 550 VariableDeclarationList varList, VariableDeclaration varDecl) {
619 if (optype.includeReturnValueSuggestions) { 551 if (optype.includeReturnValueSuggestions) {
620 bool isDeprecated = _isDeprecated(varList) || _isDeprecated(varDecl); 552 bool deprecated = isDeprecated(varList) || isDeprecated(varDecl);
621 CompletionSuggestion suggestion = _addSuggestion(varDecl.name, 553 CompletionSuggestion suggestion = _addSuggestion(varDecl.name,
622 varList.type, isDeprecated, DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE); 554 varList.type, deprecated, DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
623 if (suggestion != null) { 555 if (suggestion != null) {
624 suggestion.element = _createElement( 556 suggestion.element = createElement(
625 protocol.ElementKind.TOP_LEVEL_VARIABLE, varDecl.name, 557 protocol.ElementKind.TOP_LEVEL_VARIABLE, varDecl.name,
626 returnType: varList.type, isDeprecated: isDeprecated); 558 returnType: varList.type, isDeprecated: deprecated);
627 } 559 }
628 } 560 }
629 } 561 }
630 562
631 void _addParameterInfo( 563 void _addParameterInfo(
632 CompletionSuggestion suggestion, FormalParameterList parameters) { 564 CompletionSuggestion suggestion, FormalParameterList parameters) {
633 var paramList = parameters.parameters; 565 var paramList = parameters.parameters;
634 suggestion.parameterNames = paramList 566 suggestion.parameterNames = paramList
635 .map((FormalParameter param) => param.identifier.name) 567 .map((FormalParameter param) => param.identifier.name)
636 .toList(); 568 .toList();
(...skipping 22 matching lines...) Expand all
659 return typeId.name; 591 return typeId.name;
660 }).toList(); 592 }).toList();
661 suggestion.requiredParameterCount = paramList.where( 593 suggestion.requiredParameterCount = paramList.where(
662 (FormalParameter param) => param is! DefaultFormalParameter).length; 594 (FormalParameter param) => param is! DefaultFormalParameter).length;
663 suggestion.hasNamedParameters = paramList 595 suggestion.hasNamedParameters = paramList
664 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); 596 .any((FormalParameter param) => param.kind == ParameterKind.NAMED);
665 } 597 }
666 598
667 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, 599 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType,
668 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { 600 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) {
669 if (id != null) { 601 CompletionSuggestion suggestion = createSuggestion(
670 String completion = id.name; 602 id, isDeprecated, defaultRelevance, returnType, classDecl: classDecl);
671 if (completion != null && completion.length > 0 && completion != '_') { 603 if (suggestion != null) {
672 CompletionSuggestion suggestion = new CompletionSuggestion( 604 request.addSuggestion(suggestion);
673 CompletionSuggestionKind.INVOCATION,
674 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion,
675 completion.length, 0, isDeprecated, false,
676 returnType: _nameForType(returnType));
677 if (classDecl != null) {
678 SimpleIdentifier identifier = classDecl.name;
679 if (identifier != null) {
680 String name = identifier.name;
681 if (name != null && name.length > 0) {
682 suggestion.declaringType = name;
683 }
684 }
685 }
686 request.addSuggestion(suggestion);
687 return suggestion;
688 }
689 } 605 }
690 return null; 606 return suggestion;
691 } 607 }
692 608
693 bool _isVoid(TypeName returnType) { 609 bool _isVoid(TypeName returnType) {
694 if (returnType != null) { 610 if (returnType != null) {
695 Identifier id = returnType.name; 611 Identifier id = returnType.name;
696 if (id != null && id.name == 'void') { 612 if (id != null && id.name == 'void') {
697 return true; 613 return true;
698 } 614 }
699 } 615 }
700 return false; 616 return false;
701 } 617 }
702 } 618 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/local_suggestion_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698