Support @JvmField on interface properties
#KT-15807 Fixed
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +JvmFieldInInterface
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
interface Foo {
|
||||
companion object {
|
||||
@JvmField
|
||||
val value = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val field = Foo.Companion::value.javaField!!
|
||||
return field.get(null) as String
|
||||
}
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !LANGUAGE: +JvmFieldInInterface +NestedClassesInAnnotations
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.full.declaredMemberProperties
|
||||
|
||||
annotation class Ann(val value: String)
|
||||
|
||||
public class Bar(public val value: String)
|
||||
|
||||
annotation class Foo {
|
||||
companion object {
|
||||
@JvmField @Ann("O")
|
||||
val FOO = Bar("K")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val field = Foo.Companion::class.declaredMemberProperties.single()
|
||||
return (field.annotations.single() as Ann).value + (field.get(Foo.Companion) as Bar).value
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: +JvmFieldInInterface
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// WITH_REFLECT
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.full.memberProperties
|
||||
import kotlin.reflect.full.companionObject
|
||||
|
||||
class Bar(val value: String)
|
||||
|
||||
interface Foo {
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val z = Bar("OK")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val field = Foo::class.companionObject!!.memberProperties.single() as KProperty1<Foo.Companion, Bar>
|
||||
return field.get(Foo.Companion).value
|
||||
}
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !LANGUAGE: +JvmFieldInInterface
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.full.declaredMemberProperties
|
||||
|
||||
annotation class Ann(val value: String)
|
||||
|
||||
public class Bar(public val value: String)
|
||||
|
||||
interface Foo {
|
||||
companion object {
|
||||
@JvmField @Ann("O")
|
||||
val FOO = Bar("K")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val field = Foo.Companion::class.declaredMemberProperties.single()
|
||||
return (field.annotations.single() as Ann).value + (field.get(Foo.Companion) as Bar).value
|
||||
}
|
||||
Reference in New Issue
Block a user