[java-intentions] IDEA-312732 Invert 'if' doesn't work if branches have 'yield'

GitOrigin-RevId: 500a77bff4f250dbcd4779293e678d262227014f
This commit is contained in:
Mikhail Pyltsin
2023-02-23 14:33:18 +01:00
committed by intellij-monorepo-bot
parent ca3fa43d58
commit 06dfb15bc0
3 changed files with 32 additions and 1 deletions

View File

@@ -419,7 +419,10 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
endOffset = controlFlow.getSize();
}
while (endOffset < instructions.size() && instructions.get(endOffset) instanceof GoToInstruction &&
!((GoToInstruction) instructions.get(endOffset)).isReturn && !(controlFlow.getElement(endOffset) instanceof PsiBreakStatement) && !(controlFlow.getElement(endOffset) instanceof PsiContinueStatement)) {
!((GoToInstruction) instructions.get(endOffset)).isReturn &&
!(controlFlow.getElement(endOffset) instanceof PsiYieldStatement) &&
!(controlFlow.getElement(endOffset) instanceof PsiBreakStatement) &&
!(controlFlow.getElement(endOffset) instanceof PsiContinueStatement)) {
endOffset = ((BranchingInstruction)instructions.get(endOffset)).offset;
}

View File

@@ -0,0 +1,15 @@
// "Invert 'if' condition" "true-preview"
class A {
int test(int x, int y) {
return switch (y) {
default -> {
if (x <= 10) {
yield 21;
}
else {
yield 11;
}
}
};
}
}

View File

@@ -0,0 +1,13 @@
// "Invert 'if' condition" "true-preview"
class A {
int test(int x, int y) {
return switch (y) {
default -> {
if (<caret>x > 10) {
yield 11;
}
yield 21;
}
};
}
}