mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-235649 'Unwrap if statement' of 'if' statement inside 'case' statement removes subsequent 'case' statements
GitOrigin-RevId: 16a50c6f792fb2d30956e72fdcaaca3ed2d5b985
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d84fd8b7dd
commit
32967db59d
+5
-2
@@ -339,9 +339,12 @@ public class SimplifyBooleanExpressionFix extends LocalQuickFixOnPsiElement {
|
||||
|
||||
private static void removeFollowingStatements(@NotNull PsiStatement anchor, @NotNull PsiCodeBlock parentBlock) {
|
||||
PsiStatement[] siblingStatements = parentBlock.getStatements();
|
||||
int ifIndex = Arrays.asList(siblingStatements).indexOf(anchor);
|
||||
List<PsiStatement> statements = Arrays.asList(siblingStatements);
|
||||
int ifIndex = statements.indexOf(anchor);
|
||||
if (ifIndex >= 0 && ifIndex < siblingStatements.length - 1) {
|
||||
parentBlock.deleteChildRange(siblingStatements[ifIndex + 1], siblingStatements[siblingStatements.length - 1]);
|
||||
int labelIndex = ContainerUtil.indexOf(statements.subList(ifIndex, statements.size()), st -> st instanceof PsiSwitchLabelStatement);
|
||||
int limit = labelIndex != -1 ? labelIndex + ifIndex : siblingStatements.length;
|
||||
parentBlock.deleteChildRange(siblingStatements[ifIndex + 1], siblingStatements[limit - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Unwrap 'if' statement" "true"
|
||||
class X {
|
||||
public String testUnwrap(String f) {
|
||||
switch (f) {
|
||||
case "A":
|
||||
return "A";
|
||||
case "B":
|
||||
return "b";
|
||||
case "D":
|
||||
return "D";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Unwrap 'if' statement" "true"
|
||||
class X {
|
||||
public String testUnwrap(String f) {
|
||||
switch (f) {
|
||||
case "A":
|
||||
return "A";
|
||||
case "B":
|
||||
if (t<caret>rue) {
|
||||
return "b";
|
||||
}
|
||||
return "B";
|
||||
case "D":
|
||||
return "D";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2611,6 +2611,14 @@ public class ContainerUtil extends ContainerUtilRt {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first element in the list that satisfies given condition.
|
||||
*
|
||||
* @param list list to scan
|
||||
* @param condition condition that should be satisfied
|
||||
* @param <T> type of the list elements
|
||||
* @return index of the first element in the list that satisfies the condition; -1 if no element in the list satisfies the condition.
|
||||
*/
|
||||
@Contract(pure=true)
|
||||
public static <T> int indexOf(@NotNull List<? extends T> list, @NotNull Condition<? super T> condition) {
|
||||
for (int i = 0, listSize = list.size(); i < listSize; i++) {
|
||||
|
||||
Reference in New Issue
Block a user