Rename and implement KProperty.accessible -> KCallable.isAccessible
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
enum class E
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
val c = E::class.constructors.single()
|
||||
c.isAccessible = true
|
||||
c.call()
|
||||
return "Fail: constructing an enum class should not be allowed"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ fun box(): String {
|
||||
val a = A("abc")
|
||||
|
||||
val p = A::class.declaredMemberProperties.single() as KMutableProperty1<A, String>
|
||||
p.accessible = true
|
||||
p.isAccessible = true
|
||||
assertEquals("abc", p.call(a))
|
||||
assertEquals(Unit, p.setter.call(a, "def"))
|
||||
assertEquals("def", p.getter.call(a))
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ fun box(): String {
|
||||
// OK
|
||||
}
|
||||
|
||||
p.accessible = true
|
||||
p.isAccessible = true
|
||||
|
||||
return p.get(K("OK"))
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.accessible
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
class Result {
|
||||
private val value = "OK"
|
||||
@@ -14,11 +14,11 @@ fun box(): String {
|
||||
return "Fail: private property is accessible by default"
|
||||
} catch(e: IllegalPropertyAccessException) { }
|
||||
|
||||
p.accessible = true
|
||||
p.isAccessible = true
|
||||
|
||||
val r = p.get(Result())
|
||||
|
||||
p.accessible = false
|
||||
p.isAccessible = false
|
||||
try {
|
||||
p.get(Result())
|
||||
return "Fail: setAccessible(false) had no effect"
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.accessible
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
class A {
|
||||
private var value = 0
|
||||
@@ -15,12 +15,12 @@ fun box(): String {
|
||||
return "Fail: private property is accessible by default"
|
||||
} catch(e: IllegalPropertyAccessException) { }
|
||||
|
||||
p.accessible = true
|
||||
p.isAccessible = true
|
||||
|
||||
p.set(a, 2)
|
||||
p.get(a)
|
||||
|
||||
p.accessible = false
|
||||
p.isAccessible = false
|
||||
try {
|
||||
p.set(a, 3)
|
||||
return "Fail: setAccessible(false) had no effect"
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ class K<in T : String> {
|
||||
|
||||
fun run(): String {
|
||||
val p = ::t
|
||||
p.accessible = true
|
||||
p.isAccessible = true
|
||||
p.set(this, "" as T)
|
||||
return p.get(this)
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.accessible
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
class A(param: String) {
|
||||
protected var v: String = param
|
||||
@@ -21,7 +21,7 @@ fun box(): String {
|
||||
return "Fail: protected property setter is accessible by default"
|
||||
} catch (e: IllegalPropertyAccessException) { }
|
||||
|
||||
f.accessible = true
|
||||
f.isAccessible = true
|
||||
|
||||
f.set(a, ":)")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user