mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
invert if: don't reformat when if was removed completely
This commit is contained in:
@@ -92,13 +92,13 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
LOG.assertTrue(block != null);
|
||||
ControlFlow controlFlow = buildControlFlow(block);
|
||||
ifStatement = setupBranches(ifStatement, controlFlow);
|
||||
|
||||
if (!ifStatement.isValid()) return;
|
||||
|
||||
PsiExpression condition = Objects.requireNonNull(ifStatement.getCondition());
|
||||
if (condition != null) {
|
||||
final CommentTracker tracker = new CommentTracker();
|
||||
final String negatedCondition = BoolUtils.getNegatedExpressionText(condition, tracker);
|
||||
tracker.replaceAndRestoreComments(condition, negatedCondition);
|
||||
}
|
||||
final CommentTracker tracker = new CommentTracker();
|
||||
final String negatedCondition = BoolUtils.getNegatedExpressionText(condition, tracker);
|
||||
tracker.replaceAndRestoreComments(condition, negatedCondition);
|
||||
|
||||
formatIf(ifStatement);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
int test(int x) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
int test(int x) {
|
||||
return switch (x) {
|
||||
case 1:
|
||||
if (Math.ran<caret>dom() > 0.5) {
|
||||
br
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user