Support 'accessible' for reflected properties on JVM

Calls Java reflection's isAccessible/setAccessible
This commit is contained in:
Alexander Udalov
2014-06-05 19:15:09 +04:00
parent 1275c84f92
commit e7f19c531a
7 changed files with 150 additions and 4 deletions
@@ -0,0 +1,28 @@
import kotlin.reflect.jvm.accessible
class A(param: String) {
protected var v: String = param
fun ref() = ::v
}
fun box(): String {
val a = A(":(")
val f = a.ref()
try {
f.get(a)
return "Fail: protected property getter is accessible by default"
} catch (e: IllegalAccessException) { }
try {
f.set(a, ":D")
return "Fail: protected property setter is accessible by default"
} catch (e: IllegalAccessException) { }
f.accessible = true
f.set(a, ":)")
return if (f[a] != ":)") "Fail: ${f[a]}" else "OK"
}