if then to elvis: propose transformation to 'let' #KT-26653 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
539c55c5b2
commit
1c8e75eb34
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String?) {
|
||||
val x = <caret>if (s != null) {
|
||||
bar(s)
|
||||
}
|
||||
else {
|
||||
13
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(s: String): Int = 42
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String?) {
|
||||
val x = s?.let { bar(it) } ?: 13
|
||||
}
|
||||
|
||||
fun bar(s: String): Int = 42
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(it: String?) {
|
||||
val x = <caret>if (it != null) {
|
||||
bar(it)
|
||||
}
|
||||
else {
|
||||
13
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(s: String): Int = 42
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(it: String?) {
|
||||
val x = it?.let { it1 -> bar(it1) } ?: 13
|
||||
}
|
||||
|
||||
fun bar(s: String): Int = 42
|
||||
@@ -1,4 +1,3 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Test {
|
||||
@@ -6,9 +5,8 @@ class Test {
|
||||
return param1
|
||||
}
|
||||
|
||||
fun doAThingIfPresent(param1: String?) {
|
||||
// In theory could propose transformation to 'let'
|
||||
<caret>if (param1 != null) {
|
||||
fun doAThingIfPresent(param1: String?): String {
|
||||
return <caret>if (param1 != null) {
|
||||
doAThing(param1)
|
||||
} else {
|
||||
""
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Test {
|
||||
fun doAThing(param1: String): String {
|
||||
return param1
|
||||
}
|
||||
|
||||
fun doAThingIfPresent(param1: String?): String {
|
||||
return param1?.let { doAThing(it) } ?: ""
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,4 +1,3 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Test {
|
||||
@@ -6,9 +5,8 @@ class Test {
|
||||
return param1
|
||||
}
|
||||
|
||||
fun doAThingIfPresent(param1: String?) {
|
||||
// In theory could propose transformation to 'let'
|
||||
<caret>if (param1 is String) {
|
||||
fun doAThingIfPresent(param1: Any?): String {
|
||||
return <caret>if (param1 is String) {
|
||||
doAThing(param1)
|
||||
} else {
|
||||
""
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Test {
|
||||
fun doAThing(param1: String): String {
|
||||
return param1
|
||||
}
|
||||
|
||||
fun doAThingIfPresent(param1: Any?): String {
|
||||
return (param1 as? String)?.let { doAThing(it) } ?: ""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user