Support reflection calls to multifile class members

#KT-11447 Fixed
This commit is contained in:
Alexander Udalov
2016-03-22 15:21:09 +03:00
parent 9fa101b3fe
commit 6924d883eb
6 changed files with 171 additions and 4 deletions
@@ -0,0 +1,52 @@
// WITH_REFLECT
// FULL_JDK
// FILE: 1.kt
@file:kotlin.jvm.JvmName("Test")
@file:kotlin.jvm.JvmMultifileClass
package test
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
fun testX() {
val field = ::x.javaField ?: throw AssertionError("No java field for ${::x.name}")
try {
field.get(null)
throw AssertionError("Fail: field.get should fail because the field is private")
}
catch (e: IllegalAccessException) {
// OK
}
field.setAccessible(true)
assertEquals("I am x", field.get(null))
field.set(null, "OK")
}
fun testY() {
val field = ::y.javaField ?: throw AssertionError("No java field for ${::y.name}")
assertEquals("I am const y", field.get(null))
// Accessible = false should have no effect because the field is public
field.setAccessible(false)
assertEquals("I am const y", field.get(null))
}
fun box(): String {
testX()
testY()
return x
}
// FILE: 2.kt
@file:kotlin.jvm.JvmName("Test")
@file:kotlin.jvm.JvmMultifileClass
package test
var x = "I am x"
const val y = "I am const y"