Index: pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
index eba635ff26ffc439c35e353eef55e1e949635319..f068b3bd1e5317403078091d4f23614afba7b6b5 100644 |
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
@@ -292,6 +292,9 @@ class FixProcessor { |
_addFix_useStaticAccess_method(); |
_addFix_useStaticAccess_property(); |
} |
+ if (errorCode == StaticTypeWarningCode.INVALID_ASSIGNMENT) { |
+ _addFix_changeTypeAnnotation(); |
+ } |
if (errorCode == StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION) { |
_addFix_removeParentheses_inGetterInvocation(); |
} |
@@ -493,6 +496,29 @@ class FixProcessor { |
} |
} |
+ void _addFix_changeTypeAnnotation() { |
+ AstNode declaration = coveredNode.parent; |
+ if (declaration is VariableDeclaration && |
+ declaration.initializer == coveredNode) { |
+ AstNode variableList = declaration.parent; |
+ if (variableList is VariableDeclarationList && |
+ variableList.variables.length == 1) { |
+ TypeName typeNode = variableList.type; |
+ if (typeNode != null) { |
+ Expression initializer = coveredNode; |
+ DartType newType = initializer.bestType; |
+ if (newType is InterfaceType || newType is FunctionType) { |
+ String newTypeSource = |
+ utils.getTypeSource(newType, librariesToImport); |
+ _addReplaceEdit(rf.rangeNode(typeNode), newTypeSource); |
+ _addFix(DartFixKind.CHANGE_TYPE_ANNOTATION, |
+ [typeNode.type.displayName, newTypeSource]); |
+ } |
+ } |
+ } |
+ } |
+ } |
+ |
void _addFix_createClass() { |
Element prefixElement = null; |
String name = null; |