Convert "lift return / assignment" intentions into a single inspection
Also includes minor test fix, related to KT-14900
This commit is contained in:
committed by
Mikhail Glukhikh
parent
8f33bd0768
commit
2d1abda9a1
@@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<body>
|
||||
This inspection reports if and when statements that can be converted to expressions
|
||||
by lifting return or assignment out. Typical example:
|
||||
<code><pre>
|
||||
<b>fun</b> foo(arg: Boolean): String {
|
||||
<b>when</b> (arg) {
|
||||
<b>true</b> -> <b>return</b> "Truth"
|
||||
<b>false</b> -> <b>return</b> "Falsehood"
|
||||
}
|
||||
}
|
||||
</pre></code>
|
||||
</body>
|
||||
</html>
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
res = if (ok) {
|
||||
"ok"
|
||||
} else {
|
||||
"failed"
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
if (ok) {
|
||||
res = "ok"
|
||||
} else {
|
||||
res = "failed"
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
return if (ok) {
|
||||
"ok"
|
||||
} else {
|
||||
"failed"
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
if (ok) {
|
||||
return "ok"
|
||||
} else {
|
||||
return "failed"
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
res = when (n) {
|
||||
1 -> "one"
|
||||
2 -> "two"
|
||||
else -> "many"
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
when (n) {
|
||||
1 -> res = "one"
|
||||
2 -> res = "two"
|
||||
else -> res = "many"
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
return when (n) {
|
||||
1 -> "one"
|
||||
2 -> "two"
|
||||
else -> "many"
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
when (n) {
|
||||
1 -> return "one"
|
||||
2 -> return "two"
|
||||
else -> return "many"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
res = if (ok) {
|
||||
"ok"
|
||||
} else {
|
||||
"failed"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
if (ok) {
|
||||
res = "ok"
|
||||
} else {
|
||||
res = "failed"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention converts 'if' expression where each branch is terminated with assignment into a single assignment with 'if' expression as a right-hand side
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +0,0 @@
|
||||
return if (ok) {
|
||||
"ok"
|
||||
} else {
|
||||
"failed"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
if (ok) {
|
||||
return "ok"
|
||||
} else {
|
||||
return "failed"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention converts 'if' expression where each branch is terminated with 'return' into a single 'return' with 'if' expression as a right-hand side
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +0,0 @@
|
||||
res = when (n) {
|
||||
1 -> "one"
|
||||
2 -> "two"
|
||||
else -> "many"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
when (n) {
|
||||
1 -> res = "one"
|
||||
2 -> res = "two"
|
||||
else -> res = "many"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention converts 'when' expression where each branch is terminated with assignment into a single assignment with 'when' expression as right-hand side
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +0,0 @@
|
||||
return when (n) {
|
||||
1 -> "one"
|
||||
2 -> "two"
|
||||
else -> "many"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
when (n) {
|
||||
1 -> return "one"
|
||||
2 -> return "two"
|
||||
else -> return "many"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention converts 'when' expression where each branch is terminated with 'return' into a single 'return' with 'when' expression as a right-hand side
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user