change signature: don't unwrap try-with-resources with non-empty resource list (IDEA-202731)

This commit is contained in:
Anna.Kozlova
2018-11-23 11:30:45 +01:00
parent 6cdf4b195f
commit df9d11e89d
4 changed files with 34 additions and 1 deletions
@@ -399,7 +399,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
PsiCodeBlock tryBlock = tryStatement.getTryBlock();
if (tryBlock != null) {
if (tryStatement.getCatchSections().length == 0 &&
tryStatement.getFinallyBlock() == null) {
tryStatement.getFinallyBlock() == null &&
tryStatement.getResourceList() == null) {
PsiElement firstBodyElement = tryBlock.getFirstBodyElement();
if (firstBodyElement != null) {
tryStatement.getParent().addRangeAfter(firstBodyElement, tryBlock.getLastBodyElement(), tryStatement);
@@ -0,0 +1,14 @@
class Scratch {
static class C implements AutoCloseable {
public void close() {}
}
public static void main(String[] args) throws Exception {
try (C c = new C()) {
foo();
}
}
static void f<caret>oo() throws Exception { }
}
@@ -0,0 +1,14 @@
class Scratch {
static class C implements AutoCloseable {
public void close() {}
}
public static void main(String[] args) throws Exception {
try (C c = new C()) {
foo();
}
}
static void foo() { }
}
@@ -445,6 +445,10 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
doTest(null, null, null, new ParameterInfoImpl[0], new ThrownExceptionInfo[0], false);
}
public void testKeepTryWithResources() {
doTest(null, null, null, new ParameterInfoImpl[0], new ThrownExceptionInfo[0], false);
}
public void testVisibilityOfOverriddenMethod() {
doTest(PsiModifier.PACKAGE_LOCAL, "foo", "void", new ParameterInfoImpl[0], new ThrownExceptionInfo[0], false);
}