Add 'val KClass.declaredProperties', make getProperties a property
This commit is contained in:
+1
-1
@@ -7,6 +7,6 @@ class A {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val p = javaClass<A>().kotlin.getExtensionProperties().single()
|
||||
val p = javaClass<A>().kotlin.extensionProperties.single()
|
||||
return if ("$p" == "var A.(kotlin.String.)id") "OK" else "Fail $p"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.*
|
||||
|
||||
open class Super {
|
||||
val a: Int = 1
|
||||
val String.b: String get() = this
|
||||
}
|
||||
|
||||
class Sub : Super() {
|
||||
val c: Double = 1.0
|
||||
val Char.d: Char get() = this
|
||||
}
|
||||
|
||||
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 })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ import kotlin.reflect.jvm.*
|
||||
class K(private val value: String)
|
||||
|
||||
fun box(): String {
|
||||
val p = javaClass<K>().kotlin.getProperties().single() as KMemberProperty<K, String>
|
||||
val p = javaClass<K>().kotlin.properties.single() as KMemberProperty<K, String>
|
||||
|
||||
try {
|
||||
return p.get(K("Fail: private property should not be accessible by default"))
|
||||
|
||||
+7
-3
@@ -1,4 +1,5 @@
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.*
|
||||
|
||||
open class Super(val r: String)
|
||||
@@ -6,7 +7,10 @@ open class Super(val r: String)
|
||||
class Sub(r: String) : Super(r)
|
||||
|
||||
fun box(): String {
|
||||
val props = javaClass<Sub>().kotlin.getProperties()
|
||||
assertEquals(listOf("r"), props.map { it.name })
|
||||
return props.single().get(Sub("OK")).toString()
|
||||
val props = javaClass<Sub>().kotlin.declaredProperties
|
||||
if (!props.isEmpty()) return "Fail $props"
|
||||
|
||||
val allProps = javaClass<Sub>().kotlin.properties
|
||||
assertEquals(listOf("r"), allProps.map { it.name })
|
||||
return allProps.single().get(Sub("OK")) as String
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ class A<T> {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val k = A::class.getProperties().single()
|
||||
val k = A::class.properties.single()
|
||||
k : KMemberProperty<A<*>, *>
|
||||
return k.get(A<String>()) as String
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ class A {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val props = javaClass<A>().kotlin.getExtensionProperties()
|
||||
val props = javaClass<A>().kotlin.extensionProperties
|
||||
val readonly = props.single { it.name == "readonly" }
|
||||
assert(readonly !is KMutableMemberExtensionProperty<A, *, *>) { "Fail 1: $readonly" }
|
||||
val mutable = props.single { it.name == "mutable" }
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ class A(val readonly: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val props = javaClass<A>().kotlin.getProperties()
|
||||
val props = javaClass<A>().kotlin.properties
|
||||
val readonly = props.single { it.name == "readonly" }
|
||||
assert(readonly !is KMutableMemberProperty<A, *>) { "Fail 1: $readonly" }
|
||||
val mutable = props.single { it.name == "mutable" }
|
||||
|
||||
+2
-2
@@ -9,13 +9,13 @@ class A {
|
||||
|
||||
fun box(): String {
|
||||
run {
|
||||
val foo: KMemberProperty<A, *> = javaClass<A>().kotlin.getProperties().single()
|
||||
val foo: KMemberProperty<A, *> = javaClass<A>().kotlin.properties.single()
|
||||
assert(foo.name == "foo") { "Fail name: $foo (${foo.name})" }
|
||||
assert(foo.get(A()) == "member") { "Fail value: ${foo[A()]}" }
|
||||
}
|
||||
|
||||
run {
|
||||
val foo: KMemberExtensionProperty<A, *, *> = javaClass<A>().kotlin.getExtensionProperties().single()
|
||||
val foo: KMemberExtensionProperty<A, *, *> = javaClass<A>().kotlin.extensionProperties.single()
|
||||
assert(foo.name == "foo") { "Fail name: $foo (${foo.name})" }
|
||||
foo as KMemberExtensionProperty<A, Unit, *>
|
||||
assert(foo.get(A(), Unit) == "extension") { "Fail value: ${foo[A(), Unit]}" }
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ class A(param: String) {
|
||||
fun box(): String {
|
||||
val klass = javaClass<A>().kotlin
|
||||
|
||||
val props = klass.getProperties()
|
||||
val props = klass.properties
|
||||
|
||||
val names = props.map { it.name }.toSortedList()
|
||||
assert(names == listOf("anyVar", "int", "string")) { "Fail names: $props" }
|
||||
|
||||
Reference in New Issue
Block a user