OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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_ref; | 5 library services.completion.contributor.dart.local_ref; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol |
10 show Element, ElementKind; | 10 show Element, ElementKind; |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 if (type is TypeName) { | 463 if (type is TypeName) { |
464 Identifier typeId = type.name; | 464 Identifier typeId = type.name; |
465 if (typeId == null) { | 465 if (typeId == null) { |
466 return 'dynamic'; | 466 return 'dynamic'; |
467 } | 467 } |
468 return typeId.name; | 468 return typeId.name; |
469 } | 469 } |
470 // TODO(brianwilkerson) Support function types. | 470 // TODO(brianwilkerson) Support function types. |
471 return 'dynamic'; | 471 return 'dynamic'; |
472 }).toList(); | 472 }).toList(); |
473 suggestion.requiredParameterCount = paramList | 473 |
474 .where((FormalParameter param) => param is! DefaultFormalParameter) | 474 Iterable<ParameterElement> requiredParameters = paramList |
475 .length; | 475 .where((FormalParameter param) => param.kind == ParameterKind.REQUIRED) |
476 suggestion.hasNamedParameters = paramList | 476 .map((p) => p.element); |
477 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); | 477 suggestion.requiredParameterCount = requiredParameters.length; |
| 478 |
| 479 Iterable<ParameterElement> namedParameters = paramList |
| 480 .where((FormalParameter param) => param.kind == ParameterKind.NAMED) |
| 481 .map((p) => p.element); |
| 482 suggestion.hasNamedParameters = namedParameters.isNotEmpty; |
| 483 |
| 484 suggestion.defaultArgumentListString = |
| 485 _buildDefaultArgList(requiredParameters, namedParameters); |
| 486 } |
| 487 |
| 488 String _buildDefaultArgList(Iterable<ParameterElement> requiredParams, |
| 489 Iterable<ParameterElement> namedParams) { |
| 490 List<String> args = requiredParams.map((p) => p.name).toList(); |
| 491 List<String> requiredArgs = namedParams |
| 492 .where((p) => p.isRequired) |
| 493 .map((p) => '${p.name}: null') |
| 494 .toList(); |
| 495 args.addAll(requiredArgs); |
| 496 return args.join(', '); |
478 } | 497 } |
479 | 498 |
480 bool _isVoid(TypeAnnotation returnType) { | 499 bool _isVoid(TypeAnnotation returnType) { |
481 if (returnType is TypeName) { | 500 if (returnType is TypeName) { |
482 Identifier id = returnType.name; | 501 Identifier id = returnType.name; |
483 if (id != null && id.name == 'void') { | 502 if (id != null && id.name == 'void') { |
484 return true; | 503 return true; |
485 } | 504 } |
486 } | 505 } |
487 return false; | 506 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
505 String text = documentationComment.tokens | 524 String text = documentationComment.tokens |
506 .map((Token t) => t.toString()) | 525 .map((Token t) => t.toString()) |
507 .join('\n') | 526 .join('\n') |
508 .replaceAll('\r\n', '\n'); | 527 .replaceAll('\r\n', '\n'); |
509 String doc = removeDartDocDelimiters(text); | 528 String doc = removeDartDocDelimiters(text); |
510 suggestion.docComplete = doc; | 529 suggestion.docComplete = doc; |
511 suggestion.docSummary = getDartDocSummary(doc); | 530 suggestion.docSummary = getDartDocSummary(doc); |
512 } | 531 } |
513 } | 532 } |
514 } | 533 } |
OLD | NEW |