diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/javac/KaptTreeMaker.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/javac/KaptTreeMaker.kt index 5ff19a547be..70e1eda92cc 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/javac/KaptTreeMaker.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/javac/KaptTreeMaker.kt @@ -113,17 +113,20 @@ class KaptTreeMaker(context: Context, private val kaptContext: KaptContext<*>) : } private inline fun String.iterateDollars(variantHandler: (outerName: String, innerName: String) -> Unit) { - var dollarIndex = this.indexOf('$') - if (dollarIndex < 0) { - variantHandler(this, "") - return - } + var dollarIndex = this.indexOf('$', startIndex = 1) - while (dollarIndex > 0 && dollarIndex < this.lastIndex) { - val outerName = this.take(dollarIndex) - val innerName = this.drop(dollarIndex + 1) + while (dollarIndex > 0) { + val previousSymbol = this[dollarIndex - 1] + val nextSymbol = this.getOrNull(dollarIndex + 1) - variantHandler(outerName, innerName) + if (previousSymbol != '.' && nextSymbol != '.') { + val outerName = this.take(dollarIndex) + val innerName = this.drop(dollarIndex + 1) + + if (outerName.isNotEmpty() && innerName.isNotEmpty()) { + variantHandler(outerName, innerName) + } + } dollarIndex = this.indexOf('$', startIndex = dollarIndex + 1) } diff --git a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java index 4906471bc1a..1792ed70f80 100644 --- a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java +++ b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java @@ -235,6 +235,18 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi doTest(fileName); } + @TestMetadata("leadingDollars.kt") + public void testLeadingDollars() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars.kt"); + doTest(fileName); + } + + @TestMetadata("leadingDollars2.kt") + public void testLeadingDollars2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars2.kt"); + doTest(fileName); + } + @TestMetadata("mapEntry.kt") public void testMapEntry() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/kapt3-compiler/testData/converter/mapEntry.kt"); diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars.kt b/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars.kt new file mode 100644 index 00000000000..46b3e8278c0 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars.kt @@ -0,0 +1,19 @@ +// CORRECT_ERROR_TYPES + +// FILE: $Test.java +public class $Test { + public static class $Inner {} +} + +// FILE: Test$.java +public class Test$ { + public static class Inner$ {} +} + +// FILE: test.kt + +package test + +fun test(a: `$Test`.`$Inner`) {} + +fun test(a: `Test$`.`Inner$`) {} \ No newline at end of file diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars.txt b/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars.txt new file mode 100644 index 00000000000..32cfaa38437 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars.txt @@ -0,0 +1,52 @@ +public class $Test { + + public $Test() { + super(); + } + + public static class $Inner { + + public $Inner() { + super(); + } + } +} + +//////////////////// + + +public class Test$ { + + public Test$() { + super(); + } + + public static class Inner$ { + + public Inner$() { + super(); + } + } +} + +//////////////////// + +package test; + +import java.lang.System; + +@kotlin.Metadata() +public final class TestKt { + + public TestKt() { + super(); + } + + public static final void test(@org.jetbrains.annotations.NotNull() + $Test.$Inner a) { + } + + public static final void test(@org.jetbrains.annotations.NotNull() + Test$.Inner$ a) { + } +} diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars2.kt b/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars2.kt new file mode 100644 index 00000000000..3d8ac610100 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars2.kt @@ -0,0 +1,16 @@ +// CORRECT_ERROR_TYPES + +// FILE: te/st/a/JavaClass +package te.st.a; + +public class JavaClass {} + +// FILE: test.kt +@file:Suppress("UNRESOLVED_REFERENCE") +package te.st.a + +import te.st.a.`$Test`.Inner as MyInner +import te.st.a.`Test$`.Inner as MyInner2 +import te.st.a.`Test$`.`Inner$` as MyInner3 + +fun a(a: MyInner) {} \ No newline at end of file diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars2.txt b/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars2.txt new file mode 100644 index 00000000000..1639e37c1b7 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars2.txt @@ -0,0 +1,17 @@ +package te.st.a; + +import te.st.a.$Test.Inner; +import te.st.a.Test$.Inner$; + +@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"}) +@kotlin.Metadata() +public final class TestKt { + + public TestKt() { + super(); + } + + public static final void a(@org.jetbrains.annotations.NotNull() + te.st.a.$Test.Inner a) { + } +}