提交 f4d63158 编写于 作者: D Dmitry Petrov

Take into account JvmName annotation when generating accessors

 #KT-17444 Fixed Target versions 1.1.5
上级 efb6756c
......@@ -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)
}
......
// 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");
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册