Code transformation: if statement with assignments <-> assignment with if expression

This commit is contained in:
Alexey Sedunov
2013-04-03 18:01:08 +04:00
parent d843608298
commit 9f828b8f41
13 changed files with 372 additions and 13 deletions
@@ -0,0 +1,11 @@
public class MyClass {
public method(a: Int): String {
var res: String
if (a == 1) res = "one";
else if (a == 2) res = "two";
else res = "too many";
return res;
}
}
@@ -0,0 +1,11 @@
public class MyClass {
public method(a: Int): String {
var res: String
res = if (a == 1) "one";
else if (a == 2) "two";
else "too many";
return res;
}
}
@@ -0,0 +1,6 @@
<html>
<body>
This intention converts assignment with 'if' expression as right-hand side
into 'if' statement where each branch is terminated with assignment to the original variable
</body>
</html>
@@ -0,0 +1,11 @@
public class MyClass {
public method(a: Int): String {
var res: String
res = if (a == 1) "one";
else if (a == 2) "two";
else "too many";
return res;
}
}
@@ -0,0 +1,11 @@
public class MyClass {
public method(a: Int): String {
var res: String
if (a == 1) res = "one";
else if (a == 2) res = "two";
else res = "too many";
return res;
}
}
@@ -0,0 +1,6 @@
<html>
<body>
This intention converts 'if' statement where each branch is terminated with assignment to the same variable
into single assignment with 'if' expression
</body>
</html>
@@ -1,8 +0,0 @@
import jet.runtime.typeinfo.KotlinSignature;
public class MyClass {
<spot>@KotlinSignature("fun method() : jet.String?")</spot>
public String method() {
return "";
}
}
@@ -1,5 +0,0 @@
public class MyClass {
public String method() {
return "";
}
}