mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
IDEA-175018 Unwrap if produces red code
This commit is contained in:
+9
-1
@@ -189,9 +189,16 @@ public class SimplifyBooleanExpressionFix extends LocalQuickFixOnPsiElement {
|
||||
PsiElement parent = orig.getParent();
|
||||
if (parent == null) return;
|
||||
|
||||
PsiElement grandParent = parent.getParent();
|
||||
if (parent instanceof PsiCodeBlock && blockAlwaysReturns(statement)) {
|
||||
removeFollowingStatements(orig, (PsiCodeBlock)parent);
|
||||
}
|
||||
else if (grandParent instanceof PsiCodeBlock && parent instanceof PsiIfStatement) {
|
||||
PsiIfStatement ifStmt = (PsiIfStatement)parent;
|
||||
if (ifStmt.getElseBranch() == orig && blockAlwaysReturns(ifStmt.getThenBranch()) && blockAlwaysReturns(statement)) {
|
||||
removeFollowingStatements(ifStmt, (PsiCodeBlock)grandParent);
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof PsiCodeBlock) {
|
||||
if (statement instanceof PsiBlockStatement &&
|
||||
@@ -246,7 +253,8 @@ public class SimplifyBooleanExpressionFix extends LocalQuickFixOnPsiElement {
|
||||
orig.delete();
|
||||
}
|
||||
|
||||
private static boolean blockAlwaysReturns(@NotNull PsiStatement statement) {
|
||||
private static boolean blockAlwaysReturns(@Nullable PsiStatement statement) {
|
||||
if (statement == null) return false;
|
||||
try {
|
||||
return ControlFlowUtil.returnPresent(HighlightControlFlowUtil.getControlFlowNoConstantEvaluate(statement));
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Unwrap 'if' statement" "true"
|
||||
class X {
|
||||
boolean f(int[] a) {
|
||||
if (a.length == 0) return false;
|
||||
if (a.length == 1) {
|
||||
System.out.println();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
System.out.println("2");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Unwrap 'if' statement" "true"
|
||||
class X {
|
||||
boolean f(int[] a) {
|
||||
if (a.length == 0) return false;
|
||||
if (a.length == 1) {
|
||||
System.out.println();
|
||||
return true;
|
||||
}
|
||||
else if (a.<caret>length > 1) {
|
||||
System.out.println("2");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user