mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ControlFlowUtils#isReachable: switch expression handling fixed
Fixes IDEA-192129 Logic is changed when an 'if' statement is simplified
This commit is contained in:
+6
-2
@@ -993,8 +993,12 @@ public class ControlFlowUtils {
|
||||
*/
|
||||
public static boolean isReachable(@NotNull PsiStatement statement) {
|
||||
ControlFlow flow;
|
||||
PsiCodeBlock block = PsiTreeUtil.getParentOfType(statement, PsiCodeBlock.class);
|
||||
if (block == null) return true;
|
||||
PsiElement block = statement;
|
||||
do {
|
||||
block = PsiTreeUtil.getParentOfType(block, PsiCodeBlock.class);
|
||||
if (block == null) return true;
|
||||
}
|
||||
while (block.getParent() instanceof PsiSwitchStatement);
|
||||
try {
|
||||
flow = ControlFlowFactory.getInstance(statement.getProject())
|
||||
.getControlFlow(block, LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance());
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o.
|
||||
// Use of this source code is governed by the Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
class InCodeBlock {
|
||||
private static boolean original(boolean first, boolean second, int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return false;
|
||||
case 1:
|
||||
if (first)
|
||||
return second;
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o.
|
||||
// Use of this source code is governed by the Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
class InCodeBlock {
|
||||
private static boolean original(boolean first, boolean second, int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return false;
|
||||
case 1:
|
||||
if (first)
|
||||
i<caret>f (second)
|
||||
return true;
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,4 +37,5 @@ public class TrivialIfFixTest extends IGQuickFixesTestCase {
|
||||
public void testParentheses() { doTest(); }
|
||||
public void testNested() { doTest(); }
|
||||
public void testInCodeBlock() { doTest(); }
|
||||
public void testInSwitch() { doTest(); }
|
||||
}
|
||||
Reference in New Issue
Block a user