IDEA-211473 Inline method: process some boolean methods with multiple exits specially

GitOrigin-RevId: 5e3bc7e8577a346059192cb7d68bef7eef818ffd
This commit is contained in:
Tagir Valeev
2019-04-23 13:20:13 +03:00
committed by intellij-monorepo-bot
parent 8f4ed82473
commit 92507ef9b6
18 changed files with 426 additions and 41 deletions
@@ -0,0 +1,20 @@
class Test {
private boolean test(String s) {
if(s != null) {
s = s.trim();
if (s.isEmpty()) {
return true;
}
}
return false;
}
String use(String[] list) {
for(String str : list) {
if (<caret>test(str)) continue;
System.out.println("Ok string: "+str);
}
}
}
@@ -0,0 +1,16 @@
class Test {
String use(String[] list) {
for(String str : list) {
String s = str;
if(s != null) {
s = s.trim();
if (s.isEmpty()) {
continue;
}
}
System.out.println("Ok string: "+str);
}
}
}
@@ -0,0 +1,24 @@
class Test {
private boolean test(String s) {
if (s == null) return false;
s = s.trim();
if (s.isEmpty()) return false;
int i;
try {
i = Integer.parseInt(s);
}
catch (NumberFormatException ex) {
return false;
}
return i > 0;
}
String use(String[] list) {
for(String str : list) {
if (!<caret>test(str)) break;
System.out.println("Ok string: "+str);
}
}
}
@@ -0,0 +1,23 @@
class Test {
String use(String[] list) {
for(String str : list) {
String s = str;
if (s == null) break;
s = s.trim();
if (s.isEmpty()) break;
int i;
try {
i = Integer.parseInt(s);
}
catch (NumberFormatException ex) {
break;
}
if (i <= 0) {
break;
}
System.out.println("Ok string: "+str);
}
}
}
@@ -0,0 +1,17 @@
class Test {
private boolean test(String s) {
if(s != null) {
s = s.trim();
if (s.isEmpty()) {
return true;
}
}
return false;
}
String use(String s) {
if(<caret>test(s+s)) throw new IllegalArgumentException();
else return "nice";
}
}
@@ -0,0 +1,13 @@
class Test {
String use(String s) {
String s1 = s+s;
if(s1 != null) {
s1 = s1.trim();
if (s1.isEmpty()) {
throw new IllegalArgumentException();
}
}
return "nice";
}
}
@@ -0,0 +1,17 @@
class Test {
private boolean test() {
for(int i=0; i<10; i++) {
if (Math.random() > 0.5) return true;
}
return false;
}
String useTest() {
if(<caret>test()) {
return "foo".trim();
} else {
return "bar".trim();
}
}
}
@@ -0,0 +1,9 @@
class Test {
String useTest() {
for(int i=0; i<10; i++) {
if (Math.random() > 0.5) return "foo".trim();
}
return "bar".trim();
}
}
@@ -0,0 +1,14 @@
class Test {
private boolean test(String s) {
if (s == null) return false;
s = s.trim();
if (s.isEmpty()) return false;
return true;
}
void use(String s) {
if(!<caret>test(s+s)) return;
System.out.println("woohoo");
}
}
@@ -0,0 +1,10 @@
class Test {
void use(String s) {
String s1 = s+s;
if (s1 == null) return;
s1 = s1.trim();
if (s1.isEmpty()) return;
System.out.println("woohoo");
}
}
@@ -0,0 +1,17 @@
class Test {
private boolean test(String s) {
if(s != null) {
s = s.trim();
if (s.isEmpty()) {
return true;
}
}
return false;
}
void use(String s) {
if(<caret>test(s+s)) throw new IllegalArgumentException();
System.out.println("woohoo");
}
}
@@ -0,0 +1,13 @@
class Test {
void use(String s) {
String s1 = s+s;
if(s1 != null) {
s1 = s1.trim();
if (s1.isEmpty()) {
throw new IllegalArgumentException();
}
}
System.out.println("woohoo");
}
}