Chromium Code Reviews| 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 f58469d036c2709916a1b8704125cde9e7601300..3c1373d481f64504b6485a96dd8b82cb4a31170e 100644 |
| --- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart |
| +++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart |
| @@ -97,6 +97,7 @@ class AssistProcessor { |
| _addProposal_addTypeAnnotation_SimpleFormalParameter(); |
| _addProposal_addTypeAnnotation_VariableDeclaration(); |
| _addProposal_assignToLocalVariable(); |
| + _addProposal_convertIntoFinalField(); |
| _addProposal_convertDocumentationIntoBlock(); |
| _addProposal_convertDocumentationIntoLine(); |
| _addProposal_convertToBlockFunctionBody(); |
| @@ -481,6 +482,41 @@ class AssistProcessor { |
| _addAssist(DartAssistKind.CONVERT_DOCUMENTATION_INTO_LINE, []); |
| } |
| + void _addProposal_convertIntoFinalField() { |
| + // Find the enclosing getter. |
| + MethodDeclaration getter; |
| + for (AstNode n = node; n != null; n = n.parent) { |
| + if (n is MethodDeclaration) { |
| + getter = n; |
| + break; |
| + } |
| + if (n is SimpleIdentifier || n is TypeName || n is TypeArgumentList) { |
| + continue; |
| + } |
| + break; |
| + } |
| + if (getter == null || !getter.isGetter) { |
| + return; |
| + } |
| + // The getter body must be an expression. |
|
Brian Wilkerson
2016/07/12 19:52:24
We could eventually support block function bodies
scheglov
2016/07/12 20:26:28
Done.
|
| + FunctionBody body = getter.body; |
| + if (body is ExpressionFunctionBody) { |
| + AstNode beginNodeToReplace = getter.name; |
| + String code = 'final'; |
| + if (getter.returnType != null) { |
| + beginNodeToReplace = getter.returnType; |
| + code += ' ' + _getNodeText(getter.returnType); |
| + } |
| + code += ' ' + _getNodeText(getter.name); |
| + if (body.expression is! NullLiteral) { |
| + code += ' = ' + _getNodeText(body.expression); |
| + } |
| + code += ';'; |
| + _addReplaceEdit(rangeStartEnd(beginNodeToReplace, getter), code); |
| + _addAssist(DartAssistKind.CONVERT_INTO_FINAL_FIELD, []); |
| + } |
| + } |
| + |
| void _addProposal_convertToBlockFunctionBody() { |
| FunctionBody body = getEnclosingFunctionBody(); |
| // prepare expression body |