Generate separate anonymous class for each property reference
Each property reference obtained by the '::' operator now causes back-end to generate an anonymous subclass of the corresponding KProperty class, with the customized behavior. This fixes a number of issues: - get/set/name of property references now works without kotlin-reflect.jar in the classpath - get/set/name methods are now overridden with statically-generated property access instead of the default KPropertyImpl's behavior of using Java reflection, which should be a lot faster - references to private/protected properties now work without the need to set 'accessible' flag, because corresponding synthetic accessors are generated at compile-time near the target property #KT-6870 Fixed #KT-6873 Fixed #KT-7033 Fixed
This commit is contained in:
@@ -10,8 +10,8 @@ fun box(): String {
|
||||
val s = J::s
|
||||
|
||||
// Check that correct reflection objects are created
|
||||
assert(i.javaClass.getSimpleName() == "KProperty1Impl", "Fail i class")
|
||||
assert(s.javaClass.getSimpleName() == "KMutableProperty1Impl", "Fail s class")
|
||||
assert(i !is KMutableProperty<*>, "Fail i class: ${i.javaClass}")
|
||||
assert(s is KMutableProperty<*>, "Fail s class: ${s.javaClass}")
|
||||
|
||||
// Check that no Method objects are created for such properties
|
||||
assert(i.javaGetter == null, "Fail i getter")
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
class Test {
|
||||
private var iv = 1
|
||||
|
||||
public fun exec() {
|
||||
val t = object : Thread() {
|
||||
override fun run() {
|
||||
::iv.get(this@Test)
|
||||
::iv.set(this@Test, 2)
|
||||
}
|
||||
}
|
||||
t.start()
|
||||
t.join(1000)
|
||||
}
|
||||
|
||||
fun result() = if (iv == 2) "OK" else "Fail $iv"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t = Test()
|
||||
t.exec()
|
||||
return t.result()
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ import kotlin.reflect.jvm.accessible
|
||||
class Result {
|
||||
private val value = "OK"
|
||||
|
||||
fun ref(): KProperty1<Result, String> = ::value
|
||||
fun ref() = Result::class.properties.single() as KProperty1<Result, String>
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
+1
-1
@@ -5,7 +5,7 @@ import kotlin.reflect.jvm.accessible
|
||||
class A {
|
||||
private var value = 0
|
||||
|
||||
fun ref(): KMutableProperty1<A, Int> = ::value
|
||||
fun ref() = A::class.properties.single() as KMutableProperty1<A, Int>
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
import kotlin.reflect.IllegalPropertyAccessException
|
||||
import kotlin.reflect.jvm.accessible
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
|
||||
class A(param: String) {
|
||||
protected var v: String = param
|
||||
|
||||
fun ref() = ::v
|
||||
fun ref() = A::class.properties.single() as KMutableProperty1<A, String>
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Reference in New Issue
Block a user