| Index: pkg/analysis_server/lib/src/services/correction/assist_internal.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
|
| index 71f55ba2aad96ba8fda5e2baa30b9e7bb71bf212..31b05871a513f424a71b2a283175df9ac0fb53f5 100644
|
| --- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
|
| +++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
|
| @@ -81,6 +81,7 @@ class AssistProcessor {
|
| }
|
| // try to add proposals
|
| _addProposal_addTypeAnnotation_DeclaredIdentifier();
|
| + _addProposal_addTypeAnnotation_SimpleFormalParameter();
|
| _addProposal_addTypeAnnotation_VariableDeclaration();
|
| _addProposal_assignToLocalVariable();
|
| _addProposal_convertToBlockFunctionBody();
|
| @@ -314,6 +315,44 @@ class AssistProcessor {
|
| _addAssist(AssistKind.ADD_TYPE_ANNOTATION, []);
|
| }
|
|
|
| + void _addProposal_addTypeAnnotation_SimpleFormalParameter() {
|
| + AstNode node = this.node;
|
| + // should be the name of a simple parameter
|
| + if (node is! SimpleIdentifier || node.parent is! SimpleFormalParameter) {
|
| + _coverageMarker();
|
| + return;
|
| + }
|
| + SimpleIdentifier name = node;
|
| + SimpleFormalParameter parameter = node.parent;
|
| + // the parameter should not have a type
|
| + if (parameter.type != null) {
|
| + _coverageMarker();
|
| + return;
|
| + }
|
| + // prepare propagated type
|
| + DartType type = name.propagatedType;
|
| + // TODO(scheglov) If the parameter is in a method declaration, and if the
|
| + // method overrides a method that has a type for the corresponding
|
| + // parameter, it would be nice to copy down the type from the overridden
|
| + // method.
|
| + if (type is! InterfaceType) {
|
| + _coverageMarker();
|
| + return;
|
| + }
|
| + // prepare type source
|
| + String typeSource;
|
| + {
|
| + _configureTargetLocation(node);
|
| + Set<LibraryElement> librariesToImport = new Set<LibraryElement>();
|
| + typeSource = utils.getTypeSource(type, librariesToImport);
|
| + _addLibraryImports(librariesToImport);
|
| + }
|
| + // add edit
|
| + _addInsertEdit(name.offset, '$typeSource ');
|
| + // add proposal
|
| + _addAssist(AssistKind.ADD_TYPE_ANNOTATION, []);
|
| + }
|
| +
|
| void _addProposal_assignToLocalVariable() {
|
| // prepare enclosing ExpressionStatement
|
| Statement statement = node.getAncestor((node) => node is Statement);
|
|
|