Implement 'when' transformations (flatten, introduce subject, eliminate subject)

This commit is contained in:
Alexey Sedunov
2013-04-26 14:33:59 +04:00
parent 3c691062ad
commit a1613d8b81
16 changed files with 825 additions and 0 deletions
@@ -0,0 +1,11 @@
when {
n == 1 -> {
res = "one"
}
n == 2 -> {
res = "two"
}
else -> {
res = "???"
}
}
@@ -0,0 +1,11 @@
when (n) {
1 -> {
res = "one"
}
2 -> {
res = "two"
}
else -> {
res = "???"
}
}
@@ -0,0 +1,5 @@
<html>
<body>
This intention eliminates argument of 'when' expression transforming its pattern-matching conditions into boolean expressions
</body>
</html>
@@ -0,0 +1,17 @@
when (n) {
1 -> {
res = "one"
}
2 -> {
res = "two"
}
3 -> {
res = "three"
}
4 -> {
res = "four"
}
else -> {
res = "???"
}
}
@@ -0,0 +1,19 @@
when (n) {
1 -> {
res = "one"
}
2 -> {
res = "two"
}
else -> when (n) {
3 -> {
res = "thress"
}
4 -> {
res = "four"
}
else -> {
res = "???"
}
}
}
@@ -0,0 +1,5 @@
<html>
<body>
This intention merges branches of nested 'when' expression into enclosing one
</body>
</html>
@@ -0,0 +1,11 @@
when (n) {
1 -> {
res = "one"
}
2 -> {
res = "two"
}
else -> {
res = "???"
}
}
@@ -0,0 +1,11 @@
when {
n == 1 -> {
res = "one"
}
n == 2 -> {
res = "two"
}
else -> {
res = "???"
}
}
@@ -0,0 +1,5 @@
<html>
<body>
This intention introduces argument into 'when' expression simplifying conditions of its branches
</body>
</html>