Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Issue 1423993005: Quick Fix for CAN_BE_NULL_AFTER_NULL_AWARE. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;

Powered by Google App Engine
This is Rietveld 408576698