Simplify property hierarchy in reflection

Leave only 3*2 = 6 classes: KProperty0, KProperty1, KProperty2 and their
mutable analogs, depending on the number of receivers a property takes
This commit is contained in:
Alexander Udalov
2015-06-26 16:40:39 +03:00
parent c3b97e0668
commit 30794060a9
58 changed files with 374 additions and 653 deletions
@@ -1,5 +1,5 @@
import kotlin.reflect.jvm.kotlin
import kotlin.reflect.KMutableMemberProperty
import kotlin.reflect.KMutableProperty1
class A(val readonly: String) {
var mutable: String = "before"
@@ -8,12 +8,12 @@ class A(val readonly: String) {
fun box(): String {
val props = javaClass<A>().kotlin.properties
val readonly = props.single { it.name == "readonly" }
assert(readonly !is KMutableMemberProperty<A, *>) { "Fail 1: $readonly" }
assert(readonly !is KMutableProperty1<A, *>) { "Fail 1: $readonly" }
val mutable = props.single { it.name == "mutable" }
assert(mutable is KMutableMemberProperty<A, *>) { "Fail 2: $mutable" }
assert(mutable is KMutableProperty1<A, *>) { "Fail 2: $mutable" }
val a = A("")
mutable as KMutableMemberProperty<A, String>
mutable as KMutableProperty1<A, String>
assert(mutable[a] == "before") { "Fail 3: ${mutable.get(a)}" }
mutable[a] = "OK"
return mutable.get(a)