[java-intentions] Reenable side-effect extraction for bare loop and if bodies (follow-up to IDEA-356722)

GitOrigin-RevId: 8fe8b5b70f19cf1cb3b268edbacc07abcb155f3d
This commit is contained in:
Tagir Valeev
2024-12-02 15:08:54 +00:00
committed by intellij-monorepo-bot
parent 3d09381950
commit f19d9e91d8
5 changed files with 48 additions and 1 deletions
@@ -1867,7 +1867,10 @@ public final class HighlightUtil {
List<IntentionAction> registrar = new ArrayList<>();
HighlightFixUtil.registerFixesForExpressionStatement(statement, registrar);
QuickFixAction.registerQuickFixActions(error, null, registrar);
if (expressionStatement.getParent() instanceof PsiCodeBlock) {
PsiElement parent = expressionStatement.getParent();
if (parent instanceof PsiCodeBlock ||
parent instanceof PsiIfStatement ||
parent instanceof PsiLoopStatement loop && loop.getBody() == expressionStatement) {
IntentionAction action = PriorityIntentionActionWrapper
.lowPriority(getFixFactory().createDeleteSideEffectAwareFix(expressionStatement));
error.registerFix(action, null, null, null, null);
@@ -0,0 +1,14 @@
// "Extract side effects as an 'if' statement" "true-preview"
class Z {
void z() {
int i = 0;
if (true) {
if ((i < 100)) {
i++;
} else {
i--;
}
}
}
}
@@ -0,0 +1,14 @@
// "Extract side effects as an 'if' statement" "true-preview"
class Z {
void z() {
int i = 0;
for(int j=0;j<100;j++) {
if ((i < 100)) {
i++;
} else {
i--;
}
}
}
}
@@ -0,0 +1,8 @@
// "Extract side effects as an 'if' statement" "true-preview"
class Z {
void z() {
int i = 0;
if (true) (<caret>i < 100) ? i++ : i--
}
}
@@ -0,0 +1,8 @@
// "Extract side effects as an 'if' statement" "true-preview"
class Z {
void z() {
int i = 0;
for(int j=0;j<100;j++) (<caret>i < 100) ? i++ : i--
}
}