Introduce subject to when: suggest for qualified, not for obj / constant

#KT-18772 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-09-26 12:21:14 +03:00
committed by Mikhail Glukhikh
parent 2cde0a800a
commit fdf9acfb6a
10 changed files with 140 additions and 3 deletions
@@ -0,0 +1,13 @@
import Platform.JvmPlatform
sealed class Platform {
object JvmPlatform : Platform()
class Another(val name: String) : Platform()
}
class ModuleInfo(val platform: Platform)
fun foo(moduleInfo: ModuleInfo) = <caret>when {
moduleInfo.platform == JvmPlatform -> 1
else -> 0
}
@@ -0,0 +1,13 @@
import Platform.JvmPlatform
sealed class Platform {
object JvmPlatform : Platform()
class Another(val name: String) : Platform()
}
class ModuleInfo(val platform: Platform)
fun foo(moduleInfo: ModuleInfo) = <caret>when (moduleInfo.platform) {
JvmPlatform -> 1
else -> 0
}
@@ -0,0 +1,13 @@
import Platform.JvmPlatform
sealed class Platform {
object JvmPlatform : Platform()
class Another(val name: String) : Platform()
}
class ModuleInfo(val platform: Platform)
fun foo(moduleInfo: ModuleInfo) = <caret>when {
JvmPlatform == moduleInfo.platform -> 1
else -> 0
}
@@ -0,0 +1,13 @@
import Platform.JvmPlatform
sealed class Platform {
object JvmPlatform : Platform()
class Another(val name: String) : Platform()
}
class ModuleInfo(val platform: Platform)
fun foo(moduleInfo: ModuleInfo) = <caret>when (moduleInfo.platform) {
JvmPlatform -> 1
else -> 0
}
@@ -0,0 +1,11 @@
class Foo {
val bar = 1
}
fun test(foo: Foo): Int {
return <caret>when {
foo.bar == 1 -> 10
foo.bar == 2 -> 20
else -> 30
}
}
@@ -0,0 +1,11 @@
class Foo {
val bar = 1
}
fun test(foo: Foo): Int {
return <caret>when (foo.bar) {
1 -> 10
2 -> 20
else -> 30
}
}
@@ -0,0 +1,14 @@
class Foo {
val bar = 1
}
const val A = 1
const val B = 2
fun test(foo: Foo): Int {
return <caret>when {
A == foo.bar -> 10
B == foo.bar -> 20
else -> 30
}
}
@@ -0,0 +1,14 @@
class Foo {
val bar = 1
}
const val A = 1
const val B = 2
fun test(foo: Foo): Int {
return <caret>when (foo.bar) {
A -> 10
B -> 20
else -> 30
}
}