Rename KClass.properties and extensionProperties: prepend 'member'

To better emphasize the fact that all returned properties require an instance
of the class they are declared in. Another issue was that
'Some::class.extensionProperties' was sometimes incorrectly perceived as
"get all extension properties available on the class Some"
This commit is contained in:
Alexander Udalov
2015-07-23 22:37:08 +03:00
parent 6b24cfa3e4
commit 8f0885ca03
22 changed files with 53 additions and 36 deletions
@@ -7,7 +7,7 @@ class A(private var result: String)
fun box(): String {
val a = A("abc")
val p = A::class.declaredProperties.single() as KMutableProperty1<A, String>
val p = A::class.declaredMemberProperties.single() as KMutableProperty1<A, String>
p.accessible = true
assertEquals("abc", p.call(a))
assertEquals(Unit, p.setter.call(a, "def"))
@@ -26,7 +26,7 @@ fun box(): String {
assertEquals(1, (::p0).getter.call())
assertEquals(2, (Int::p1).call(2))
assertEquals(2, (Int::p1).getter.call(2))
val p2 = A::class.extensionProperties.single()
val p2 = A::class.memberExtensionProperties.single()
assertEquals(3, p2.call(A(), 3))
assertEquals(3, p2.getter.call(A(), 3))
@@ -34,7 +34,7 @@ fun box(): String {
assertEquals(1, (::mp0).getter.call())
assertEquals(2, (Int::mp1).call(2))
assertEquals(2, (Int::mp1).getter.call(2))
val mp2 = B::class.extensionProperties.single() as KMutableProperty2
val mp2 = B::class.memberExtensionProperties.single() as KMutableProperty2
assertEquals(3, mp2.call(B(), 3))
assertEquals(3, mp2.getter.call(B(), 3))
@@ -10,7 +10,7 @@ class A {
}
fun box(): String {
val p = javaClass<A>().kotlin.extensionProperties.single()
val p = javaClass<A>().kotlin.memberExtensionProperties.single()
return if ("$p" == "var A.(kotlin.String.)id") "OK" else "Fail $p"
val q = javaClass<A>().kotlin.declaredFunctions.single()
@@ -22,7 +22,7 @@ fun box(): String {
assertEquals("<get-baz>", A::baz.getter.name)
assertEquals("<set-baz>", A::baz.setter.name)
val me = A::class.extensionProperties.single() as KMutableProperty2<A, String, String>
val me = A::class.memberExtensionProperties.single() as KMutableProperty2<A, String, String>
assertEquals("<get-quux>", me.getter.name)
assertEquals("<set-quux>", me.setter.name)
@@ -8,7 +8,7 @@ class C(var state: String) {
}
fun box(): String {
val prop = C::class.extensionProperties.single() as KMutableProperty2<C, String, String>
val prop = C::class.memberExtensionProperties.single() as KMutableProperty2<C, String, String>
val c = C("")
assertEquals("3", prop.getter.invoke(c, "abc"))
@@ -14,10 +14,10 @@ class Sub : Super() {
fun box(): String {
val sub = Sub::class
assertEquals(listOf("a", "c"), sub.properties.map { it.name }.sort())
assertEquals(listOf("b", "d"), sub.extensionProperties.map { it.name }.sort())
assertEquals(listOf("c"), sub.declaredProperties.map { it.name })
assertEquals(listOf("d"), sub.declaredExtensionProperties.map { it.name })
assertEquals(listOf("a", "c"), sub.memberProperties.map { it.name }.sort())
assertEquals(listOf("b", "d"), sub.memberExtensionProperties.map { it.name }.sort())
assertEquals(listOf("c"), sub.declaredMemberProperties.map { it.name })
assertEquals(listOf("d"), sub.declaredMemberExtensionProperties.map { it.name })
return "OK"
}
@@ -4,7 +4,7 @@ import kotlin.reflect.jvm.*
class K(private val value: String)
fun box(): String {
val p = javaClass<K>().kotlin.properties.single() as KProperty1<K, String>
val p = javaClass<K>().kotlin.memberProperties.single() as KProperty1<K, String>
try {
return p.get(K("Fail: private property should not be accessible by default"))
@@ -7,10 +7,10 @@ open class Super(val r: String)
class Sub(r: String) : Super(r)
fun box(): String {
val props = javaClass<Sub>().kotlin.declaredProperties
val props = javaClass<Sub>().kotlin.declaredMemberProperties
if (!props.isEmpty()) return "Fail $props"
val allProps = javaClass<Sub>().kotlin.properties
val allProps = javaClass<Sub>().kotlin.memberProperties
assertEquals(listOf("r"), allProps.map { it.name })
return allProps.single().get(Sub("OK")) as String
}
@@ -5,6 +5,6 @@ class A<T> {
}
fun box(): String {
val k: KProperty1<A<*>, *> = A::class.properties.single()
val k: KProperty1<A<*>, *> = A::class.memberProperties.single()
return k.get(A<String>()) as String
}
@@ -13,7 +13,7 @@ class A {
}
fun box(): String {
val props = javaClass<A>().kotlin.extensionProperties
val props = javaClass<A>().kotlin.memberExtensionProperties
val readonly = props.single { it.name == "readonly" }
assert(readonly !is KMutableProperty2<A, *, *>) { "Fail 1: $readonly" }
val mutable = props.single { it.name == "mutable" }
@@ -6,7 +6,7 @@ class A(val readonly: String) {
}
fun box(): String {
val props = javaClass<A>().kotlin.properties
val props = javaClass<A>().kotlin.memberProperties
val readonly = props.single { it.name == "readonly" }
assert(readonly !is KMutableProperty1<A, *>) { "Fail 1: $readonly" }
val mutable = props.single { it.name == "mutable" }
@@ -8,13 +8,13 @@ class A {
fun box(): String {
run {
val foo: KProperty1<A, *> = javaClass<A>().kotlin.properties.single()
val foo: KProperty1<A, *> = javaClass<A>().kotlin.memberProperties.single()
assert(foo.name == "foo") { "Fail name: $foo (${foo.name})" }
assert(foo.get(A()) == "member") { "Fail value: ${foo[A()]}" }
}
run {
val foo: KProperty2<A, *, *> = javaClass<A>().kotlin.extensionProperties.single()
val foo: KProperty2<A, *, *> = javaClass<A>().kotlin.memberExtensionProperties.single()
assert(foo.name == "foo") { "Fail name: $foo (${foo.name})" }
foo as KProperty2<A, Unit, *>
assert(foo.get(A(), Unit) == "extension") { "Fail value: ${foo[A(), Unit]}" }
@@ -4,7 +4,7 @@ import kotlin.reflect.jvm.accessible
class Result {
private val value = "OK"
fun ref() = Result::class.properties.single() as KProperty1<Result, String>
fun ref() = Result::class.memberProperties.single() as KProperty1<Result, String>
}
fun box(): String {
@@ -4,7 +4,7 @@ import kotlin.reflect.jvm.accessible
class A {
private var value = 0
fun ref() = A::class.properties.single() as KMutableProperty1<A, Int>
fun ref() = A::class.memberProperties.single() as KMutableProperty1<A, Int>
}
fun box(): String {
@@ -4,5 +4,5 @@ open class A(private val p: Int)
class B : A(42)
fun box() =
if (B::class.properties.isEmpty()) "OK"
else "Fail: invisible fake overrides should not appear in KClass.properties"
if (B::class.memberProperties.isEmpty()) "OK"
else "Fail: invisible fake overrides should not appear in KClass.memberProperties"
@@ -4,7 +4,7 @@ import kotlin.reflect.jvm.accessible
class A(param: String) {
protected var v: String = param
fun ref() = A::class.properties.single() as KMutableProperty1<A, String>
fun ref() = A::class.memberProperties.single() as KMutableProperty1<A, String>
}
fun box(): String {
@@ -14,7 +14,7 @@ class A(param: String) {
fun box(): String {
val klass = javaClass<A>().kotlin
val props = klass.properties
val props = klass.memberProperties
val names = props.map { it.name }.toSortedList()
assert(names == listOf("anyVar", "int", "string")) { "Fail names: $props" }