mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-142617 (Replace with 'try' with resources produces bad code)
This commit is contained in:
+6
-4
@@ -143,10 +143,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(j);
|
||||
j++;
|
||||
if (!unwantedChildren.isEmpty()) {
|
||||
while (!unwantedChildren.contains(Integer.valueOf(j)) && j < tryBlockChildren.length - 1) {
|
||||
tryStatement.getParent().addBefore(tryBlockChildren[j], tryStatement);
|
||||
unwantedChildren.add(j);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
newTryStatementText.append(") {");
|
||||
final int tryBlockStatementsLength = tryBlockChildren.length - 1;
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import java.io.Reader;
|
||||
|
||||
class X {
|
||||
public void test() throws Exception {
|
||||
|
||||
try (Reader r = new FileReader("")) {
|
||||
r.read();
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import java.io.Reader;
|
||||
|
||||
class X {
|
||||
public void test() throws Exception {
|
||||
Reader r = new FileReader("");
|
||||
|
||||
<caret>try {
|
||||
r.read();
|
||||
}
|
||||
finally {
|
||||
r.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -24,6 +24,7 @@ public class TryFinallyCanBeTryWithResourcesFixTest extends IGQuickFixesTestCase
|
||||
public void testComments() { doTest(); }
|
||||
public void testMultiple() { doTest(); }
|
||||
public void testDependents() { doTest(); }
|
||||
public void testKeepResourceCallInBlock() { doTest(); }
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user