do not delete finally section when catch section is replaced with throws (IDEA-145842)

This commit is contained in:
Anna Kozlova
2015-10-01 20:11:58 +02:00
parent 0a60a99e6c
commit 0bc58af9e6
4 changed files with 24 additions and 1 deletions
@@ -61,7 +61,7 @@ public class ConvertCatchToThrowsIntention extends Intention {
addToThrowsList(throwsList, catchType);
final PsiTryStatement tryStatement = catchSection.getTryStatement();
final PsiCatchSection[] catchSections = tryStatement.getCatchSections();
if (catchSections.length > 1 || tryStatement.getResourceList() != null) {
if (catchSections.length > 1 || tryStatement.getResourceList() != null || tryStatement.getFinallyBlock() != null) {
catchSection.delete();
}
else {
@@ -0,0 +1,13 @@
class C {
void f() {
try {
System.out.println();
}
cat<caret>ch (Exception exception) {
exception.printStackTrace();
}
finally {
System.out.println();
}
}
}
@@ -0,0 +1,9 @@
class C {
void f() throws Exception {
try {
System.out.println();
} finally {
System.out.println();
}
}
}
@@ -26,6 +26,7 @@ public class ConvertCatchToThrowsTest extends IPPTestCase {
public void testArmWithSingleCatch() { doTest(); }
public void testExistingThrows() { doTest(); }
public void testLambda() { doTest(); }
public void testLeaveFinallySection() { doTest(); }
@Override
protected String getIntentionName() {