preserve comments: invert if in case when else branch become empty

This commit is contained in:
Anna.Kozlova
2018-10-10 18:18:09 +02:00
parent e8582863dd
commit 4f4012fecf
3 changed files with 20 additions and 1 deletions
@@ -142,7 +142,7 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
elseBranch = Objects.requireNonNull(ifStatement.getElseBranch()).replace(elseBranch);
if (emptyBlock(((PsiBlockStatement)elseBranch).getCodeBlock())) {
ifStatement.getElseBranch().delete();
new CommentTracker().deleteAndRestoreComments(ifStatement.getElseBranch());
}
}
}
@@ -0,0 +1,10 @@
// "Invert 'if' condition" "true"
class A {
public void foo() {
if (c) {
}
//c1
System.out.println();
}
}
@@ -0,0 +1,9 @@
// "Invert 'if' condition" "true"
class A {
public void foo() {
<caret>if (!c) {
continue;
}//c1
System.out.println();
}
}