Support KClass.functions and declaredFunctions
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
import kotlin.reflect.*
|
||||
|
||||
open class A {
|
||||
fun mem() {}
|
||||
fun Int.memExt() {}
|
||||
}
|
||||
|
||||
class B : A()
|
||||
|
||||
fun box(): String {
|
||||
val all = A::class.functions.map { it.name }.toSortedList()
|
||||
assert(all == listOf("equals", "hashCode", "mem", "memExt", "toString")) { "Fail A functions: ${A::class.functions}" }
|
||||
|
||||
val declared = A::class.declaredFunctions.map { it.name }.toSortedList()
|
||||
assert(declared == listOf("mem", "memExt")) { "Fail A declaredFunctions: ${A::class.declaredFunctions}" }
|
||||
|
||||
val declaredSubclass = B::class.declaredFunctions.map { it.name }.toSortedList()
|
||||
assert(declaredSubclass.isEmpty()) { "Fail B declaredFunctions: ${B::class.declaredFunctions}" }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+7
@@ -5,9 +5,16 @@ class A {
|
||||
var String.id: String
|
||||
get() = this
|
||||
set(value) {}
|
||||
|
||||
fun Int.foo(): Double = toDouble()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val p = javaClass<A>().kotlin.extensionProperties.single()
|
||||
return if ("$p" == "var A.(kotlin.String.)id") "OK" else "Fail $p"
|
||||
|
||||
val q = javaClass<A>().kotlin.declaredFunctions.single()
|
||||
if ("$q" != "fun A.(kotlin.Int.)foo(): kotlin.Double") return "Fail q $q"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Vendored
+4
@@ -5,6 +5,8 @@ fun foo(bar: String): Int = bar.length()
|
||||
|
||||
class A(val c: String) {
|
||||
fun foz(baz: Int) {}
|
||||
|
||||
fun Double.mext(mez: Long) {}
|
||||
}
|
||||
|
||||
fun Int.qux(zux: String) {}
|
||||
@@ -21,6 +23,8 @@ fun box(): String {
|
||||
checkParameters(A::foz, listOf(null, "baz"))
|
||||
checkParameters(Int::qux, listOf(null, "zux"))
|
||||
|
||||
checkParameters(A::class.functions.single { it.name == "mext" }, listOf(null, null, "mez"))
|
||||
|
||||
checkParameters(::A, listOf("c"))
|
||||
|
||||
return "OK"
|
||||
|
||||
Reference in New Issue
Block a user