diff --git a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowUtil.java b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowUtil.java index 7d757cbfe931..576f231b4a1d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1056,35 +1056,9 @@ public class ControlFlowUtil { if (nextOffset > flow.getSize()) nextOffset = flow.getSize(); if (offset > endOffset) return; int throwToOffset = instruction.offset; - boolean isNormal = false; + boolean isNormal; if (throwToOffset == nextOffset) { - - if (nextOffset == endOffset) { - int lastOffset = endOffset - 1; - Instruction lastInstruction = flow.getInstructions().get(lastOffset); - while (lastInstruction instanceof GoToInstruction && - ((GoToInstruction)lastInstruction).role == BranchingInstruction.Role.END && - !((GoToInstruction)lastInstruction).isReturn) { - if (((GoToInstruction)lastInstruction).offset == startOffset) { - lastOffset = -1; - break; - } - else { - lastOffset--; - if (lastOffset < 0) { - break; - } - lastInstruction = flow.getInstructions().get(lastOffset); - } - } - - if (lastOffset >= 0) { - isNormal = !(lastInstruction instanceof GoToInstruction && ((GoToInstruction)lastInstruction).isReturn) && - !(lastInstruction instanceof ThrowToInstruction); - } - } - - isNormal |= throwToOffset <= endOffset && !isLeaf(nextOffset) && canCompleteNormally[nextOffset]; + isNormal = throwToOffset <= endOffset && !isLeaf(nextOffset) && canCompleteNormally[nextOffset]; } else { isNormal = canCompleteNormally[nextOffset]; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/afterNotCompletesNormally.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/afterNotCompletesNormally.java new file mode 100644 index 000000000000..9c2e48605c53 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/afterNotCompletesNormally.java @@ -0,0 +1,14 @@ +// "Replace 'switch' with 'if'" "true" +class X { + + void m(String s, int a) throws IOException { + if ("a".equals(s)) { + a(); + } else { + d(); + } + } + + void a() throws IOException { } + void d() throws IOException { } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/afterNotCompletesNormally2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/afterNotCompletesNormally2.java new file mode 100644 index 000000000000..0e80684a1153 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/afterNotCompletesNormally2.java @@ -0,0 +1,17 @@ +// "Replace 'switch' with 'if'" "true" +class X { + void test4() throws IOException { + String variable = "abc"; + if ("abc".equals(variable)) { + String s1 = "abcd"; + } else if ("def".equals(variable)) { + String s1 = "abcd"; + myFunction(s1); + } else { + throw new IllegalArgumentException(); + } + } + + public void myFunction(Object o1) throws IOException { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/beforeNotCompletesNormally.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/beforeNotCompletesNormally.java new file mode 100644 index 000000000000..c660a18be354 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/beforeNotCompletesNormally.java @@ -0,0 +1,18 @@ +// "Replace 'switch' with 'if'" "true" +class X { + + void m(String s, int a) throws IOException { + switch (s) { + case "a": { + a(); + break; + } + default: { + d(); + } + } + } + + void a() throws IOException { } + void d() throws IOException { } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/beforeNotCompletesNormally2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/beforeNotCompletesNormally2.java new file mode 100644 index 000000000000..c6553e746193 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/beforeNotCompletesNormally2.java @@ -0,0 +1,22 @@ +// "Replace 'switch' with 'if'" "true" +class X { + void test4() throws IOException { + String variable = "abc"; + switch (variable) { + case "abc": { + String s1 = "abcd"; + break; + } + case "def": { + String s1 = "abcd"; + myFunction(s1); + break; + } + default: + throw new IllegalArgumentException(); + } + } + + public void myFunction(Object o1) throws IOException { + } +} \ No newline at end of file