Kapt: Fix compilation errors when the referenced class has '$' in the beginning of its name (KT-22493)

This commit is contained in:
Yan Zhulanow
2018-01-26 20:49:15 +03:00
parent 5fc9c5671c
commit 1f81c0cdfe
6 changed files with 128 additions and 9 deletions
@@ -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)
}
@@ -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");
@@ -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$`) {}
@@ -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) {
}
}
@@ -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) {}
@@ -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) {
}
}