mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
Java: Don't extract method where it's not safe because of nullable result (IDEA-167391)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
class C {
|
||||
private int[] list;
|
||||
|
||||
private Integer find(int id) {
|
||||
<selection>
|
||||
int n = 0;
|
||||
for (int n1 : list) {
|
||||
n = n1;
|
||||
if (n == id) {
|
||||
return n <= 0 ? null : n;
|
||||
}
|
||||
}
|
||||
</selection>
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class C {
|
||||
private int[] list;
|
||||
|
||||
private int find(int id) {
|
||||
<selection>for (int n : list) {
|
||||
if (n == id) {
|
||||
return n <= 0 ? 0 : n;
|
||||
}
|
||||
}</selection>
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class C {
|
||||
private int[] list;
|
||||
|
||||
private int find(int id) {
|
||||
Integer n = newMethod(id);
|
||||
if (n != null) return n;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Integer newMethod(int id) {
|
||||
for (int n : list) {
|
||||
if (n == id) {
|
||||
return n <= 0 ? 0 : n;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,14 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExitPoints10() throws Exception {
|
||||
doExitPointsTest(false);
|
||||
}
|
||||
|
||||
public void testExitPoints11() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotNullCheckNameConflicts() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user