mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-209056 Action to transform method with multiple returns into the method with single exit point
First implementation
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean noEmptyStrings(String[][] list) {
|
||||
boolean result = true;
|
||||
for (String[] inner : list) {
|
||||
for (String s : inner) {
|
||||
if (s.isEmpty()) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!result) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean hasEmptyString(List<String> list) {
|
||||
boolean result = false;
|
||||
for (String s : list) {
|
||||
if (s.isEmpty()) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean test(String[] arr) {
|
||||
boolean result = false;
|
||||
boolean finished = false;
|
||||
if (arr != null) {
|
||||
System.out.println("ok");
|
||||
for (String s : arr) {
|
||||
if (s.isEmpty()) {
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
System.out.println(s);
|
||||
}
|
||||
if (!finished) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean test(String[] arr) {
|
||||
boolean result = true;
|
||||
if (arr == null) {
|
||||
result = false;
|
||||
} else {
|
||||
String s = arr[0];
|
||||
if (s == null) {
|
||||
result = false;
|
||||
} else {
|
||||
s = arr[1];
|
||||
if (s == null) {
|
||||
result = false;
|
||||
} else {
|
||||
if (arr.length > 3) {
|
||||
s = arr[2];
|
||||
if (s != null && s.isEmpty()) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean test(String s) {
|
||||
boolean result = false;
|
||||
if (s != null) {
|
||||
if (!s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String test2(List<String> list, String foo, String bar) {
|
||||
String result = foo;
|
||||
boolean finished = false;
|
||||
for (String s : list) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
bar = s;
|
||||
if (s.length() == i) {
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (finished) break;
|
||||
}
|
||||
if (!finished) {
|
||||
result = bar;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
native String get(String s);
|
||||
|
||||
String test(String[] data) {
|
||||
String result = null;
|
||||
boolean finished = false;
|
||||
if (data == null) {
|
||||
result = get("foo");
|
||||
} else {
|
||||
String s = data[0];
|
||||
int i = 0;
|
||||
if (data.length > 2) {
|
||||
if (data[2] != null) {
|
||||
if (data[2].isEmpty()) {
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
if (!finished) {
|
||||
while (true) {
|
||||
if (!s.isEmpty()) {
|
||||
if (s.length() > 2) {
|
||||
result = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println(s);
|
||||
s = data[i++];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
int test(String s) {
|
||||
int result = 2;
|
||||
if (s == null) {
|
||||
if (!(Math.random() > 0.5)) {
|
||||
result = 4;
|
||||
}
|
||||
} else {
|
||||
if (s.isEmpty()) {
|
||||
result = 3;
|
||||
} else {
|
||||
System.out.println(s);
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
int test(String s) {
|
||||
int result = 1;
|
||||
if (s == null) {
|
||||
if (Math.random() > 0.5) {
|
||||
result = 2;
|
||||
} else {
|
||||
System.out.println("going further");
|
||||
}
|
||||
}
|
||||
if (result == 1) {
|
||||
if (s.isEmpty()) {
|
||||
result = 3;
|
||||
} else {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
int test(String[] strings) {
|
||||
int result = 0;
|
||||
for (String string : strings) {
|
||||
if (!string.isEmpty()) {
|
||||
result = string.length();
|
||||
break;// positive number
|
||||
}
|
||||
}
|
||||
if (result == 0) {
|
||||
result = strings.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
int test(String[] strings) {
|
||||
int result = -1;
|
||||
for (String string : strings) {
|
||||
if (!string.equal("foo")) {
|
||||
result = string.length();
|
||||
break;// non-negative number
|
||||
}
|
||||
}
|
||||
if (result == -1) {
|
||||
result = strings.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String test(String[] strings) {
|
||||
String result = "";
|
||||
if (strings.length > 2) {
|
||||
String string = strings[0];
|
||||
if (string.equals(strings[1])) {
|
||||
result = foo(string);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String test(String[] strings) {
|
||||
String res = null;
|
||||
boolean finished = false;
|
||||
if (strings.length > 2) {
|
||||
String string = strings[0];
|
||||
if (string.equals(strings[1])) {
|
||||
finished = true;
|
||||
res = foo(string);
|
||||
}
|
||||
}
|
||||
if (!finished) {
|
||||
String result = bar();
|
||||
res = result;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String test(String[] strings) {
|
||||
String result = null;
|
||||
boolean finished = false;
|
||||
if (strings.length > 2) {
|
||||
String string = strings[0];
|
||||
if (string.equals(strings[1])) {
|
||||
finished = true;
|
||||
result = foo(string);
|
||||
}
|
||||
}
|
||||
if (!finished) {
|
||||
result = bar();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String test2(List<String> list, String foo, String bar) {
|
||||
String result = bar;
|
||||
boolean finished = false;
|
||||
for (String s : list) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (s.length() == i) {
|
||||
finished = true;
|
||||
result = foo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (finished) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String process(String s, int x) {
|
||||
String result = null;
|
||||
if (x > 0) {
|
||||
if (x == 2) {
|
||||
result = s.trim();
|
||||
} else {
|
||||
System.out.println(s.substring(0));
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
result = s.substring(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String process(String s, int x) {
|
||||
String result;
|
||||
if (x > 0) {
|
||||
if (x == 2) {
|
||||
result = s.trim();
|
||||
} else {
|
||||
result = s.substring(0);
|
||||
}
|
||||
} else {
|
||||
result = s.substring(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String process(String s) {
|
||||
String res = null;
|
||||
if (s != null) {
|
||||
s = s.trim();
|
||||
if (!s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
String result = s + s;
|
||||
res = result;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String process(String s) {
|
||||
String res = null;
|
||||
if (s != null) {
|
||||
s = s.trim();
|
||||
if (!s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
String result = s + s;
|
||||
res = result;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
void test2(String[] arr) {
|
||||
for (String s : arr) {
|
||||
if (s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
void test2(String[] arr) {
|
||||
boolean finished = false;
|
||||
for (String s : arr) {
|
||||
if (s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!finished) {
|
||||
System.out.println("Not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
void test2(String s) {
|
||||
if (s != null) {
|
||||
if (!s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean <caret>noEmptyStrings(String[][] list) {
|
||||
for (String[] inner : list) {
|
||||
for (String s : inner) {
|
||||
if (s.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean <caret>hasEmptyString(List<String> list) {
|
||||
for (String s : list) {
|
||||
if(s.isEmpty()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean <caret>test(String[] arr) {
|
||||
if (arr != null) {
|
||||
System.out.println("ok");
|
||||
for(String s : arr) {
|
||||
if (s.isEmpty()) return false;
|
||||
System.out.println(s);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean <caret>test(String[] arr) {
|
||||
if (arr == null) return false;
|
||||
String s = arr[0];
|
||||
if (s == null) return false;
|
||||
s = arr[1];
|
||||
if (s == null) return false;
|
||||
if (arr.length > 3) {
|
||||
s = arr[2];
|
||||
if (s != null && s.isEmpty()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
boolean <caret>test(String s) {
|
||||
if(s == null) return false;
|
||||
if(s.isEmpty()) return false;
|
||||
System.out.println(s);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String <caret>test2(List<String> list, String foo, String bar) {
|
||||
for(String s : list)
|
||||
for(int i=0; i<10; i++) {
|
||||
bar = s;
|
||||
if(s.length() == i) return foo;
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
native String get(String s);
|
||||
|
||||
String <caret>test(String[] data) {
|
||||
if (data == null) {
|
||||
return get("foo");
|
||||
}
|
||||
String s = data[0];
|
||||
int i=0;
|
||||
if (data.length > 2) {
|
||||
if (data[2] != null) {
|
||||
if(data[2].isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
if (!s.isEmpty()) {
|
||||
if (s.length() > 2) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
System.out.println(s);
|
||||
s = data[i++];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
int <caret>test(String s) {
|
||||
if(s == null) {
|
||||
if (Math.random() > 0.5) return 2;
|
||||
return 4;
|
||||
}
|
||||
if(s.isEmpty()) return 3;
|
||||
System.out.println(s);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
int <caret>test(String s) {
|
||||
if(s == null) {
|
||||
if (Math.random() > 0.5) return 2;
|
||||
System.out.println("going further");
|
||||
}
|
||||
if(s.isEmpty()) return 3;
|
||||
System.out.println(s);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
int <caret>test(String[] strings) {
|
||||
for (String string : strings) {
|
||||
if (!string.isEmpty()) {
|
||||
return string.length(); // positive number
|
||||
}
|
||||
}
|
||||
return strings.length;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
int <caret>test(String[] strings) {
|
||||
for (String string : strings) {
|
||||
if (!string.equal("foo")) {
|
||||
return string.length(); // non-negative number
|
||||
}
|
||||
}
|
||||
return strings.length;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String <caret>test(String[] strings) {
|
||||
if (strings.length > 2) {
|
||||
String string = strings[0];
|
||||
if (string.equals(strings[1])) {
|
||||
return foo(string);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String <caret>test(String[] strings) {
|
||||
if (strings.length > 2) {
|
||||
String string = strings[0];
|
||||
if (string.equals(strings[1])) {
|
||||
return foo(string);
|
||||
}
|
||||
}
|
||||
String result = bar();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String <caret>test(String[] strings) {
|
||||
if (strings.length > 2) {
|
||||
String string = strings[0];
|
||||
if (string.equals(strings[1])) {
|
||||
return foo(string);
|
||||
}
|
||||
}
|
||||
return bar();
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String <caret>test2(List<String> list, String foo, String bar) {
|
||||
for(String s : list)
|
||||
for(int i=0; i<10; i++) {
|
||||
if(s.length() == i) return foo;
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String<caret> process(String s, int x) {
|
||||
if (x > 0) {
|
||||
if (x == 2) {
|
||||
return s.trim();
|
||||
}
|
||||
System.out.println(s.substring(0));
|
||||
}
|
||||
return s.substring(1);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String<caret> process(String s, int x) {
|
||||
if (x > 0) {
|
||||
if (x == 2) {
|
||||
return s.trim();
|
||||
}
|
||||
return s.substring(0);
|
||||
}
|
||||
return s.substring(1);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String<caret> process(String s) {
|
||||
if (s == null) return null;
|
||||
s = s.trim();
|
||||
if (s.isEmpty()) return null;
|
||||
System.out.println(s);
|
||||
String result = s + s;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
String<caret> process(String s) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
s = s.trim();
|
||||
if (s.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
System.out.println(s);
|
||||
String result = s + s;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
void <caret>test2(String[] arr) {
|
||||
for(String s : arr) {
|
||||
if (s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
void <caret>test2(String[] arr) {
|
||||
for(String s : arr) {
|
||||
if (s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("Not found");
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Transform body to single exit-point form" "true"
|
||||
class Test {
|
||||
void <caret>test2(String s) {
|
||||
if(s == null) return;
|
||||
if(s.isEmpty()) return;
|
||||
System.out.println(s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user