Take into account JvmName annotation when generating accessors

#KT-17444 Fixed Target versions 1.1.5
This commit is contained in:
Dmitry Petrov
2017-07-10 18:02:32 +03:00
parent efb6756cbc
commit f4d63158cc
6 changed files with 51 additions and 2 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.codegen
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.resolve.DescriptorUtils
enum class FieldAccessorKind(val suffix: String) {
NORMAL("p"),
@@ -26,15 +27,18 @@ enum class FieldAccessorKind(val suffix: String) {
override fun toString() = suffix
}
private fun CallableMemberDescriptor.getJvmName() =
DescriptorUtils.getJvmName(this) ?: name.asString()
fun getAccessorNameSuffix(descriptor: CallableMemberDescriptor, superCallDescriptor: ClassDescriptor?,
accessorKind: FieldAccessorKind): String {
val suffix = when (descriptor) {
is ConstructorDescriptor ->
return "will be ignored"
is SimpleFunctionDescriptor ->
descriptor.name.asString()
descriptor.getJvmName()
is PropertyDescriptor ->
descriptor.name.asString() + "$" + accessorKind
descriptor.getJvmName() + "$" + accessorKind
else ->
throw UnsupportedOperationException("Do not know how to create accessor for descriptor " + descriptor)
}
@@ -0,0 +1,15 @@
// IGNORE_BACKEND: JS, NATIVE
// WITH_RUNTIME
@JvmName("fooA")
private fun String.foo(t: String?): String = this
private fun String.foo(t: String): String = this
fun runNoInline(fn: () -> String) = fn()
fun box() =
runNoInline { "O".foo("") } +
runNoInline { "K".foo(null) }
@@ -18029,6 +18029,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("jvmNameForAccessors.kt")
public void testJvmNameForAccessors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt");
doTest(fileName);
}
@TestMetadata("kt10047.kt")
public void testKt10047() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
@@ -18029,6 +18029,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("jvmNameForAccessors.kt")
public void testJvmNameForAccessors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt");
doTest(fileName);
}
@TestMetadata("kt10047.kt")
public void testKt10047() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
@@ -18029,6 +18029,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("jvmNameForAccessors.kt")
public void testJvmNameForAccessors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt");
doTest(fileName);
}
@TestMetadata("kt10047.kt")
public void testKt10047() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
@@ -22103,6 +22103,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
}
@TestMetadata("jvmNameForAccessors.kt")
public void testJvmNameForAccessors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt");
try {
doTest(fileName);
}
catch (Throwable ignore) {
return;
}
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
}
@TestMetadata("kt10047.kt")
public void testKt10047() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");