Files
kotlin/compiler/testData/codegen/box/jvmField/topLevelFieldReflection.kt
Alexander Udalov c357967c2c JVM IR: generate Kotlin metadata
Introduce MetadataSource as a way to store the original descriptor for
any element (before any lowerings) and maintain it until the end of the
codegen where it's used in generating the metadata. Note that JVM
signatures written to the metadata are formed from the _resulting_
generated elements, not by mapping the original descriptors.

Some corner cases are not supported yet, namely properties declared in
companion objects, synthetic methods for property annotations,
JvmPackageName, etc.

 #KT-29119 Fixed
2019-02-19 16:37:47 +01:00

32 lines
945 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_REFLECT
package test
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.jvm.kotlinProperty
import kotlin.test.assertEquals
public var publicField = "1"
internal var internalField = "2"
fun testAccessors() {
val packageClass = Class.forName("test.TopLevelFieldReflectionKt")
packageClass.getDeclaredField("publicField").kotlinProperty
checkAccessor(packageClass.getDeclaredField("publicField").kotlinProperty as KMutableProperty0<String>, "1", "3")
checkAccessor(packageClass.getDeclaredField("internalField").kotlinProperty as KMutableProperty0<String>, "2", "4")
}
fun box(): String {
testAccessors()
return "OK"
}
public fun < R> checkAccessor(prop: KMutableProperty0<R>, value: R, newValue: R) {
assertEquals(prop.get(), value, "Property ${prop} has wrong value")
prop.set(newValue)
assertEquals(prop.get(), newValue, "Property ${prop} has wrong value")
}