Support @JvmField on interface properties

#KT-15807 Fixed
This commit is contained in:
Mikhael Bogdanov
2018-03-13 15:18:01 +01:00
parent 719c1882e0
commit 1d283d243e
36 changed files with 718 additions and 34 deletions
@@ -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
}
@@ -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
}
@@ -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
}
@@ -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
}