Change synthetic accessor method names to "access$..."

As per discussion in https://youtrack.jetbrains.com/issue/KT-6870
This commit is contained in:
Alexander Udalov
2015-02-27 16:18:03 +03:00
parent ac9e6cd9ca
commit 2c0830b017
11 changed files with 124 additions and 35 deletions
@@ -0,0 +1,48 @@
// This test checks that synthetic accessors generated by Kotlin compiler have names starting with "access$"
// This is crucial for some JVM frameworks like Quasar which rely on the bytecode being similar to the one generated by javac
// See https://youtrack.jetbrains.com/issue/KT-6870
class PrivateConstructor private() {
class Nested { val a = PrivateConstructor() }
}
class PrivatePropertyGet {
private val x = 42
inner class Inner { val a = x }
}
class PrivatePropertySet {
private var x = "a"
inner class Inner { { x = "b" } }
}
class PrivateMethod {
private fun foo() = ""
inner class Inner { val a = foo() }
}
fun check(klass: Class<*>) {
for (method in klass.getDeclaredMethods()) {
if (method.isSynthetic() && method.getName().startsWith("access$")) return
}
throw AssertionError("No synthetic methods starting with 'access$' found in class $klass")
}
fun box(): String {
check(javaClass<PrivateConstructor>())
check(javaClass<PrivatePropertyGet>())
check(javaClass<PrivatePropertySet>())
check(javaClass<PrivateMethod>())
// Also check that synthetic accessors really work
PrivateConstructor.Nested()
PrivatePropertyGet().Inner()
PrivatePropertySet().Inner()
PrivateMethod().Inner()
return "OK"
}