Implement KClass.getProperties()

#KT-6570 In Progress
This commit is contained in:
Alexander Udalov
2015-02-20 19:40:47 +03:00
parent fdfd808d80
commit da209e673c
7 changed files with 125 additions and 1 deletions
@@ -0,0 +1,20 @@
import kotlin.reflect.jvm.kotlin
import kotlin.reflect.KMutableMemberProperty
class A(val readonly: String) {
var mutable: String = "before"
}
fun box(): String {
val props = javaClass<A>().kotlin.getProperties()
val readonly = props.single { it.name == "readonly" }
assert(readonly !is KMutableMemberProperty<A, *>) { "Fail 1: $readonly" }
val mutable = props.single { it.name == "mutable" }
assert(mutable is KMutableMemberProperty<A, *>) { "Fail 2: $mutable" }
val a = A("")
mutable as KMutableMemberProperty<A, String>
assert(mutable[a] == "before") { "Fail 3: ${mutable.get(a)}" }
mutable[a] = "OK"
return mutable.get(a)
}