From a98313797839b8104e79a6a75f6f779d5ef5d315 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Wed, 28 Jun 2017 16:43:58 +0300 Subject: [PATCH] Kapt: Handle parameter with Java names clashing with Java keywords properly (KT-18377) --- .../kapt3/stubs/ClassFileToSourceStubConverter.kt | 2 +- .../ClassFileToSourceStubConverterTestGenerated.java | 6 ++++++ plugins/kapt3/testData/converter/kt18377.kt | 3 +++ plugins/kapt3/testData/converter/kt18377.txt | 12 ++++++++++++ .../kapt3/testData/converter/strangeIdentifiers.txt | 2 +- 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 plugins/kapt3/testData/converter/kt18377.kt create mode 100644 plugins/kapt3/testData/converter/kt18377.txt diff --git a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index 507c031c36e..2b80d3aa42b 100644 --- a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -437,7 +437,7 @@ class ClassFileToSourceStubConverter( info.visibleAnnotations, info.invisibleAnnotations) - val name = treeMaker.name(getValidIdentifierName(info.name) ?: "p${index}_" + info.name.hashCode()) + val name = treeMaker.name(getValidIdentifierName(info.name) ?: "p${index}_" + info.name.hashCode().ushr(1)) val type = treeMaker.Type(info.type) treeMaker.VarDef(modifiers, name, type, null) } diff --git a/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java b/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java index 386a247b925..17dcbe48616 100644 --- a/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java +++ b/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java @@ -180,6 +180,12 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi doTest(fileName); } + @TestMetadata("kt18377.kt") + public void testKt18377() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/kt18377.kt"); + doTest(fileName); + } + @TestMetadata("mapEntry.kt") public void testMapEntry() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/mapEntry.kt"); diff --git a/plugins/kapt3/testData/converter/kt18377.kt b/plugins/kapt3/testData/converter/kt18377.kt new file mode 100644 index 00000000000..9bb238632c3 --- /dev/null +++ b/plugins/kapt3/testData/converter/kt18377.kt @@ -0,0 +1,3 @@ +import java.util.Date + +fun Date(double: Double): Date = Date(double.times(1000).toLong()) \ No newline at end of file diff --git a/plugins/kapt3/testData/converter/kt18377.txt b/plugins/kapt3/testData/converter/kt18377.txt new file mode 100644 index 00000000000..34284ec82db --- /dev/null +++ b/plugins/kapt3/testData/converter/kt18377.txt @@ -0,0 +1,12 @@ +@kotlin.Metadata() +public final class Kt18377Kt { + + public Kt18377Kt() { + super(); + } + + @org.jetbrains.annotations.NotNull() + public static final java.util.Date Date(double p0_1484504552) { + return null; + } +} diff --git a/plugins/kapt3/testData/converter/strangeIdentifiers.txt b/plugins/kapt3/testData/converter/strangeIdentifiers.txt index 2b45a859d35..a2e662094bc 100644 --- a/plugins/kapt3/testData/converter/strangeIdentifiers.txt +++ b/plugins/kapt3/testData/converter/strangeIdentifiers.txt @@ -50,7 +50,7 @@ public final class Test { public final void strangeFun4(@org.jetbrains.annotations.NotNull() java.lang.String a, @org.jetbrains.annotations.NotNull() - java.lang.String p1_1899121793) { + java.lang.String p1_949560896) { } public Test() {