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 a6f30996f764cb4478efd28223f74ccd7307b9ab..0ad6b878ae190c370606d2c05608626e5fdd6b03 100644 |
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
@@ -159,6 +159,9 @@ class FixProcessor { |
_addFix_createPartUri(); |
_addFix_replaceImportUri(); |
} |
+ if (errorCode == HintCode.CAN_BE_NULL_AFTER_NULL_AWARE) { |
+ _addFix_canBeNullAfterNullAware(); |
+ } |
if (errorCode == HintCode.DEAD_CODE) { |
_addFix_removeDeadCode(); |
} |
@@ -445,6 +448,25 @@ class FixProcessor { |
_addFix(DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, []); |
} |
+ void _addFix_canBeNullAfterNullAware() { |
+ AstNode node = coveredNode; |
+ if (node is Expression) { |
+ AstNode parent = node.parent; |
+ while (parent != null) { |
+ if (parent is MethodInvocation && parent.target == node) { |
+ _addReplaceEdit(rf.rangeToken(parent.operator), '?.'); |
+ } else if (parent is PropertyAccess && parent.target == node) { |
+ _addReplaceEdit(rf.rangeToken(parent.operator), '?.'); |
+ } else { |
+ break; |
+ } |
+ node = parent; |
+ parent = node.parent; |
+ } |
+ _addFix(DartFixKind.REPLACE_WITH_NULL_AWARE, []); |
+ } |
+ } |
+ |
void _addFix_createClass() { |
Element prefixElement = null; |
String name = null; |