mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Java: Add conditional return when replacing duplicate fragment (IDEA-180601)
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
class Conditional {
|
||||
int[] bar(String[] s) {
|
||||
<selection>
|
||||
if (s != null) {
|
||||
int[] n = new int[s.length];
|
||||
for (int i = 0; i < s.length; i++) {
|
||||
n[i] = s[i].length();
|
||||
}
|
||||
return n;
|
||||
}</selection>
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
int[] baz(String[] z) {
|
||||
if (z != null) {
|
||||
int[] n = new int[z.length];
|
||||
for (int i = 0; i < z.length; i++) {
|
||||
n[i] = z[i].length();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
class Conditional {
|
||||
int[] bar(String[] s) {
|
||||
|
||||
int[] n = newMethod(s);
|
||||
if (n != null) return n;
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
private int[] newMethod(String[] s) {
|
||||
if (s != null) {
|
||||
int[] n = new int[s.length];
|
||||
for (int i = 0; i < s.length; i++) {
|
||||
n[i] = s[i].length();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
int[] baz(String[] z) {
|
||||
int[] n = newMethod(z);
|
||||
if (n != null) return n;
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
class Conditional {
|
||||
int bar(String s) {<selection>
|
||||
if (s != null) {
|
||||
int n = s.length;
|
||||
return n;
|
||||
}</selection>
|
||||
return 0;
|
||||
}
|
||||
|
||||
int baz(String z) {
|
||||
int x = -1;
|
||||
if (z != null) {
|
||||
int n = z.length;
|
||||
x = n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Conditional {
|
||||
int bar(String s) {
|
||||
Integer n = newMethod(s);
|
||||
if (n != null) return n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Integer newMethod(String s) {
|
||||
if (s != null) {
|
||||
int n = s.length;
|
||||
return n;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
int baz(String z) {
|
||||
int x = -1;
|
||||
if (z != null) {
|
||||
int n = z.length;
|
||||
x = n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -843,6 +843,15 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testConditionalReturnInDuplicate() throws Exception {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
// todo DuplicatesFinder.canBeEquivalent() should see the difference between 'return' and assignment
|
||||
public void _testConditionalReturnVsAssignDuplicate() throws Exception {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testSuggestChangeSignatureWithChangedParameterName() throws Exception {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
boolean success = performExtractMethod(true, true, getEditor(), getFile(), getProject(), false, null, false, "p");
|
||||
|
||||
Reference in New Issue
Block a user