Files
kotlin-fork/compiler/testData/codegen/boxWithStdlib/reflection/properties/simpleGetProperties.kt
T
Alexander Udalov 8d9618348d Move .java and .kotlin extension properties to kotlin.jvm
Delete the old ones in package kotlin.reflect.jvm because otherwise the code
using those functions will become red in a lot less meaningful way (overload
resolution ambiguity) than if they're deleted (unresolved import)

Based on the work originally done by @dnpetrov

 #KT-8380 Fixed
2015-08-27 08:19:50 +03:00

24 lines
608 B
Kotlin
Vendored

import kotlin.reflect.*
class A(param: String) {
val int: Int get() = 42
val string: String = param
var anyVar: Any? = null
val List<IntRange>.extensionToList: Unit get() {}
fun notAProperty() {}
}
fun box(): String {
val klass = javaClass<A>().kotlin
val props = klass.memberProperties
val names = props.map { it.name }.toSortedList()
assert(names == listOf("anyVar", "int", "string")) { "Fail names: $props" }
val stringProp = props.firstOrNull { it.name == "string" } ?: return "Fail, string not found: $props"
return stringProp.get(A("OK")) as String
}