preserve comments: invert if with comment after then branch

This commit is contained in:
Anna.Kozlova
2018-10-10 18:18:09 +02:00
parent b4ea426c90
commit 4831eed1ce
3 changed files with 21 additions and 2 deletions
@@ -248,8 +248,8 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
if (element instanceof PsiReturnStatement) {
PsiReturnStatement returnStatement = (PsiReturnStatement) element;
ifStatement = addAfterWithinCodeBlock(ifStatement, ct.markUnchanged(thenBranch));
ct.replaceAndRestoreComments(Objects.requireNonNull(ifStatement.getThenBranch()), returnStatement.copy());
ifStatement = addAfterWithinCodeBlock(ifStatement, thenBranch);
ct.replaceAndRestoreComments(Objects.requireNonNull(ifStatement.getThenBranch()), ct.markUnchanged(returnStatement).copy());
ControlFlow flow2 = buildControlFlow(findCodeBlock(ifStatement));
if (!ControlFlowUtil.isInstructionReachable(flow2, flow2.getStartOffset(returnStatement), 0)) returnStatement.delete();
@@ -0,0 +1,10 @@
// "Invert 'if' condition" "true"
public class C {
public boolean isAcceptable(Object element) {
if (element == null) {
return false;//c1
}
System.out.println();
return false;
}
}
@@ -0,0 +1,9 @@
// "Invert 'if' condition" "true"
public class C {
public boolean isAcceptable(Object element) {
i<caret>f (element != null) {
System.out.println();
}//c1
return false;
}
}