Extract Function: Extract smart-cast value as parameter

#KT-7576 Fixed
This commit is contained in:
Alexey Sedunov
2015-05-21 19:06:25 +03:00
parent e20a5121c7
commit 9e69b74a15
14 changed files with 214 additions and 46 deletions
@@ -0,0 +1,14 @@
// SUGGESTED_NAMES: i, getKm
// PARAM_TYPES: A
// PARAM_DESCRIPTOR: val a: A defined in test
class A {
}
val A.meters: Int? get() = 1
fun test() {
val a = A()
if (a.meters == null) return
val km = <selection>a.meters / 10</selection>
}
@@ -0,0 +1,16 @@
// SUGGESTED_NAMES: i, getKm
// PARAM_TYPES: A
// PARAM_DESCRIPTOR: val a: A defined in test
class A {
}
val A.meters: Int? get() = 1
fun test() {
val a = A()
if (a.meters == null) return
val km = i(a)
}
private fun i(a: A) = a.meters / 10
@@ -0,0 +1,12 @@
// SUGGESTED_NAMES: i, getKm
// PARAM_TYPES: kotlin.Int
// PARAM_DESCRIPTOR: internal final val meters: kotlin.Int? defined in A
class A {
val meters: Int? = 1
}
fun test() {
val a = A()
if (a.meters == null) return
val km = <selection>a.meters / 10</selection>
}
@@ -0,0 +1,14 @@
// SUGGESTED_NAMES: i, getKm
// PARAM_TYPES: kotlin.Int
// PARAM_DESCRIPTOR: internal final val meters: kotlin.Int? defined in A
class A {
val meters: Int? = 1
}
fun test() {
val a = A()
if (a.meters == null) return
val km = i(a.meters)
}
private fun i(meters: Int) = meters / 10
@@ -0,0 +1,15 @@
// WITH_RUNTIME
// SUGGESTED_NAMES: i, getKm
// PARAM_TYPES: kotlin.Int
// PARAM_DESCRIPTOR: internal final val meters: kotlin.Int? defined in A
class A {
val meters: Int? = 1
}
fun test() {
val a = A()
with (a) {
if (meters == null) return
val km = <selection>meters / 10</selection>
}
}
@@ -0,0 +1,17 @@
// WITH_RUNTIME
// SUGGESTED_NAMES: i, getKm
// PARAM_TYPES: kotlin.Int
// PARAM_DESCRIPTOR: internal final val meters: kotlin.Int? defined in A
class A {
val meters: Int? = 1
}
fun test() {
val a = A()
with (a) {
if (meters == null) return
val km = i(meters)
}
}
private fun i(meters: Int) = meters / 10
@@ -0,0 +1,9 @@
// SUGGESTED_NAMES: i, getKm
// PARAM_TYPES: kotlin.Int
// PARAM_DESCRIPTOR: internal val meters: kotlin.Int? defined in root package
val meters: Int? = 1
fun test() {
if (meters == null) return
val km = <selection>meters / 10</selection>
}
@@ -0,0 +1,11 @@
// SUGGESTED_NAMES: i, getKm
// PARAM_TYPES: kotlin.Int
// PARAM_DESCRIPTOR: internal val meters: kotlin.Int? defined in root package
val meters: Int? = 1
fun test() {
if (meters == null) return
val km = i(meters)
}
private fun i(meters: Int) = meters / 10