Files
kotlin-fork/compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt
T
Juan Chen 9dd8eda1c9 [FIR]: fix library methods in packages
Library methods such as 'listOf' are resolved
to have the package fragments as their parents,
but JVM expects their containing file classes as parents.
This fix generates those file classes and
uses them as parent replacements for such library methods.
2020-02-20 14:24:02 +03:00

61 lines
1.7 KiB
Kotlin
Vendored

// !LANGUAGE: +UseGetterNameForPropertyAnnotationsMethodOnJvm
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FULL_JDK
// JVM_TARGET: 1.8
package test
import java.lang.reflect.Modifier
import kotlin.test.*
class WithCompanionJvmStatic {
companion object {
@JvmStatic
val property: Int
get() = 42
}
}
interface InterfaceWithCompanionJvmStatic {
fun defaultImplsTrigger() = 123
companion object {
@JvmStatic
val property: Int
get() = 42
}
}
fun check(clazz: Class<*>, expected: Boolean = true) {
for (method in clazz.getDeclaredMethods()) {
if (method.getName() == "getProperty\$annotations") {
if (!expected) {
fail("Synthetic method for annotated property found, but not expected: $method")
}
assertTrue(method.isSynthetic())
assertTrue(Modifier.isStatic(method.modifiers))
assertTrue(Modifier.isPublic(method.modifiers))
val str = method.declaredAnnotations.single().toString()
assertTrue("@kotlin.jvm.JvmStatic\\(\\)".toRegex().matches(str), str)
return
}
}
if (expected) {
fail("Synthetic method for annotated property expected, but not found")
}
}
fun box(): String {
check(Class.forName("test.WithCompanionJvmStatic"), expected = false)
check(Class.forName("test.WithCompanionJvmStatic\$Companion"))
check(Class.forName("test.InterfaceWithCompanionJvmStatic"), expected = false)
check(Class.forName("test.InterfaceWithCompanionJvmStatic\$DefaultImpls"), expected = false)
check(Class.forName("test.InterfaceWithCompanionJvmStatic\$Companion"))
return "OK"
}