IDEA-209056 Switch, try-catch, synchronized support; avoid conflicting var names; fix reads of uninitialized vars

This commit is contained in:
Tagir Valeev
2019-03-19 17:35:03 +07:00
parent c9e006acda
commit 38f4026184
18 changed files with 245 additions and 24 deletions
@@ -6,8 +6,8 @@ class Test {
if (strings.length > 2) {
String string = strings[0];
if (string.equals(strings[1])) {
finished = true;
res = foo(string);
finished = true;
}
}
if (!finished) {
@@ -6,8 +6,8 @@ class Test {
if (strings.length > 2) {
String string = strings[0];
if (string.equals(strings[1])) {
finished = true;
result = foo(string);
finished = true;
}
}
if (!finished) {
@@ -6,8 +6,8 @@ class Test {
for (String s : list) {
for (int i = 0; i < 10; i++) {
if (s.length() == i) {
finished = true;
result = foo;
finished = true;
break;
}
}
@@ -0,0 +1,20 @@
// "Transform body to single exit-point form" "true"
class Test {
String test(int x) {
String result = "foo";
switch (x) {
case 1:
break;
case 2:
result = "bar";
break;
case 3:
result = "baz";
break;
default:
result = "qux";
break;
}
return result;
}
}
@@ -0,0 +1,16 @@
// "Transform body to single exit-point form" "true"
class Test {
String test(int x) {
String result = "foo";
synchronized (this) {
if (x != 0) {
if (x == 1) {
result = "bar";
} else {
result = "baz";
}
}
}
return result;
}
}
@@ -0,0 +1,19 @@
// "Transform body to single exit-point form" "true"
class Test {
String test(int x) {
String result = null;
synchronized (this) {
if (x == 0) {
result = "foo";
} else {
if (x == 1) {
result = "bar";
}
}
}
if (result == null) {
result = "baz";
}
return result;
}
}
@@ -0,0 +1,11 @@
// "Transform body to single exit-point form" "true"
class Test {
int test(String s) {
int result = -1;
try {
result = Integer.parseInt(s);
} catch (NumberFormatException ex) {
}
return result;
}
}
@@ -0,0 +1,21 @@
// "Transform body to single exit-point form" "true"
class Test {
int test(String s) {
int res = -1;
boolean finished = false;
try {
res = Integer.parseInt(s);
finished = true;
} catch (NumberFormatException ex) {
boolean result = s.isEmpty();
if (result) {
finished = true;
}
}
if (!finished) {
System.out.println("oops");
res = -2;
}
return res;
}
}
@@ -0,0 +1,19 @@
// "Transform body to single exit-point form" "true"
class Test {
void test(String s) {
boolean finished = false;
if (s != null) {
int a = 0;
synchronized (this) {
if (s.isEmpty()) {
finished = true;
} else {
a = s.length();
}
}
if (!finished) {
System.out.println(a);
}
}
}
}
@@ -0,0 +1,11 @@
// "Transform body to single exit-point form" "true"
class Test {
String <caret>test(int x) {
switch (x) {
case 1:return "foo";
case 2:return "bar";
case 3:return "baz";
default:return "qux";
}
}
}
@@ -0,0 +1,10 @@
// "Transform body to single exit-point form" "true"
class Test {
String <caret>test(int x) {
synchronized(this) {
if(x == 0) return "foo";
if(x == 1) return "bar";
return "baz";
}
}
}
@@ -0,0 +1,10 @@
// "Transform body to single exit-point form" "true"
class Test {
String <caret>test(int x) {
synchronized(this) {
if(x == 0) return "foo";
if(x == 1) return "bar";
}
return "baz";
}
}
@@ -0,0 +1,11 @@
// "Transform body to single exit-point form" "true"
class Test {
int <caret>test(String s) {
try {
return Integer.parseInt(s);
}
catch(NumberFormatException ex) {
return -1;
}
}
}
@@ -0,0 +1,14 @@
// "Transform body to single exit-point form" "true"
class Test {
int <caret>test(String s) {
try {
return Integer.parseInt(s);
}
catch(NumberFormatException ex) {
boolean result = s.isEmpty();
if (result) return -1;
}
System.out.println("oops");
return -2;
}
}
@@ -0,0 +1,13 @@
// "Transform body to single exit-point form" "true"
class Test {
void <caret>test(String s) {
if (s != null) {
int a;
synchronized (this) {
if (s.isEmpty()) return;
a = s.length();
}
System.out.println(a);
}
}
}