Files
kotlin-fork/compiler/testData/ir/irText/firProblems/readWriteProperty.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

33 lines
903 B
Kotlin
Vendored

// WITH_STDLIB
// WITH_REFLECT
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KClass
import kotlin.reflect.KProperty
class SettingType<out V : Any>(
val type : KClass<out V>
)
class SettingReference<V : Any, T : SettingType<V>>(
var t : T
var v : V
)
class IdeWizard {
var projectTemplate by setting(SettingReference(SettingType(42::class), 42))
private fun <V : Any, T : SettingType<V>> setting(reference: SettingReference<V, T>) =
object : ReadWriteProperty<Any?, V?> {
override fun setValue(thisRef: Any?, property: KProperty<*>, value: V?) {
if (value == null) return
reference.t = SettingType(value::class) as T
reference.v = value
}
override fun getValue(thisRef: Any?, property: KProperty<*>): V? {
return reference.v
}
}
}