IG: fix "'try finally' replaceable with 'try' with resources" inspection quickfix problem

This commit is contained in:
Bas Leijdekkers
2015-07-02 17:52:28 +02:00
parent 67520a55f5
commit 3e428407ca
4 changed files with 29 additions and 0 deletions
@@ -142,6 +142,12 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
}
separator = true;
}
int j = 1;
while (!unwantedChildren.contains(Integer.valueOf(j)) && j < tryBlockChildren.length - 1) {
tryStatement.getParent().addBefore(tryBlockChildren[j], tryStatement);
unwantedChildren.add(Integer.valueOf(j));
j++;
}
newTryStatementText.append(") {");
final int tryBlockStatementsLength = tryBlockChildren.length - 1;
for (int i = 1; i < tryBlockStatementsLength; i++) {
@@ -0,0 +1,9 @@
import java.io.*;
class Dependents {
void m() throws IOException {
String filename = "filename";
try (InputStream in = new FileInputStream(filename)) {
}
}
}
@@ -0,0 +1,13 @@
import java.io.*;
class Dependents {
void m() throws IOException {
InputStream in = null;
try<caret> {
String filename = "filename";
in = new FileInputStream(filename);
}finally{
in.close();
}
}
}
@@ -23,6 +23,7 @@ public class TryFinallyCanBeTryWithResourcesFixTest extends IGQuickFixesTestCase
public void testComments() { doTest(); }
public void testMultiple() { doTest(); }
public void testDependents() { doTest(); }
@Override
public void setUp() throws Exception {