diff options
author | Jonas Herzig <jonas@spark-squared.com> | 2021-11-11 16:52:27 +0100 |
---|---|---|
committer | Jonas Herzig <jonas@spark-squared.com> | 2021-11-11 21:38:47 +0100 |
commit | 982982c63027e416bd78ca40708c7238e7eed26b (patch) | |
tree | 509517275b8664157f0cfc58e20675527fcc9ce8 /src/test | |
parent | b4462eb6030f8e5a072ad4b6508d7a93d574522f (diff) | |
download | Remap-982982c63027e416bd78ca40708c7238e7eed26b.tar.gz Remap-982982c63027e416bd78ca40708c7238e7eed26b.tar.bz2 Remap-982982c63027e416bd78ca40708c7238e7eed26b.zip |
Fix remapping of qualified inner class reference in Kotlin code
When we used to remap `a.pkg.A.Inner` we would apply both mappings (the one for
the inner class and the one for the outer class) at the same time, resulting in
`b.pkg.B.Inner.Inner`.
The direct cause being that we only checked conflicts for the range of the
respective expression (which is just `A` and `Inner` for Kotlin, and therefore
not conflicting) instead of the parent as we should have.
With that fixed, it now also becomes apparent that we need to apply mappings for
dot qualified expressions back to front (otherwise the outer class takes
priority), so that is the second thing this commit change.
Diffstat (limited to 'src/test')
7 files changed, 148 insertions, 0 deletions
diff --git a/src/test/java/a/pkg/A.java b/src/test/java/a/pkg/A.java index ff779b2..94e8a77 100644 --- a/src/test/java/a/pkg/A.java +++ b/src/test/java/a/pkg/A.java @@ -42,4 +42,9 @@ public class A extends AParent implements AInterface { public class Inner { private int aField; } + + public class InnerA { + } + + public class GenericA<T> {} } diff --git a/src/test/java/b/pkg/B.java b/src/test/java/b/pkg/B.java index 6ed26c1..9524513 100644 --- a/src/test/java/b/pkg/B.java +++ b/src/test/java/b/pkg/B.java @@ -42,4 +42,9 @@ public class B extends BParent implements BInterface { public class Inner { private int bField; } + + public class InnerB { + } + + public class GenericB<T> {} } diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinGenerics.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinGenerics.kt new file mode 100644 index 0000000..19a3574 --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinGenerics.kt @@ -0,0 +1,49 @@ +package com.replaymod.gradle.remap.mapper.kotlin + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.collections.shouldHaveSize +import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldContain +import org.junit.jupiter.api.Test + +class TestKotlinGenerics { + @Test + fun `remaps generic type argument`() { + TestData.remapKt(""" + val test: List<a.pkg.A> = TODO() + """.trimIndent()) shouldBe """ + val test: List<b.pkg.B> = TODO() + """.trimIndent() + } + + @Test + fun `remaps generic type argument with import`() { + TestData.remapKt(""" + import a.pkg.A + val test: List<A> = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B + val test: List<B> = TODO() + """.trimIndent() + } + + @Test + fun `remaps generic type`() { + TestData.remapKt(""" + val test: a.pkg.A.GenericA<Int> = TODO() + """.trimIndent()) shouldBe """ + val test: b.pkg.B.GenericB<Int> = TODO() + """.trimIndent() + } + + @Test + fun `remaps generic type with import`() { + TestData.remapKt(""" + import a.pkg.A.GenericA + val test: GenericA<Int> = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B.GenericB + val test: GenericB<Int> = TODO() + """.trimIndent() + } +}
\ No newline at end of file diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinImports.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinImports.kt new file mode 100644 index 0000000..3193c2f --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinImports.kt @@ -0,0 +1,42 @@ +package com.replaymod.gradle.remap.mapper.kotlin + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.collections.shouldHaveSize +import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldContain +import org.junit.jupiter.api.Test + +class TestKotlinImports { + @Test + fun `remaps simple import`() { + TestData.remapKt(""" + import a.pkg.A + val test: A = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B + val test: B = TODO() + """.trimIndent() + } + + @Test + fun `remaps outer class of inner class import`() { + TestData.remapKt(""" + import a.pkg.A.Inner + val test: Inner = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B.Inner + val test: Inner = TODO() + """.trimIndent() + } + + @Test + fun `remaps inner class import`() { + TestData.remapKt(""" + import a.pkg.A.InnerA + val test: InnerA = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B.InnerB + val test: InnerB = TODO() + """.trimIndent() + } +}
\ No newline at end of file diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinTypeAliases.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinTypeAliases.kt new file mode 100644 index 0000000..0d69341 --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinTypeAliases.kt @@ -0,0 +1,42 @@ +package com.replaymod.gradle.remap.mapper.kotlin + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.collections.shouldHaveSize +import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldContain +import org.junit.jupiter.api.Test + +class TestKotlinTypeAliases { + @Test + fun `remaps simple alias`() { + TestData.remapKt(""" + typealias A = a.pkg.A + val test: A = TODO() + """.trimIndent()) shouldBe """ + typealias A = b.pkg.B + val test: A = TODO() + """.trimIndent() + } + + @Test + fun `remaps outer class of inner class alias`() { + TestData.remapKt(""" + typealias Inner = a.pkg.A.Inner + val test: Inner = TODO() + """.trimIndent()) shouldBe """ + typealias Inner = b.pkg.B.Inner + val test: Inner = TODO() + """.trimIndent() + } + + @Test + fun `remaps inner class alias`() { + TestData.remapKt(""" + typealias InnerA = a.pkg.A.InnerA + val test: InnerA = TODO() + """.trimIndent()) shouldBe """ + typealias InnerA = b.pkg.B.InnerB + val test: InnerA = TODO() + """.trimIndent() + } +}
\ No newline at end of file diff --git a/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt b/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt index cb0ad44..0f83373 100644 --- a/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt +++ b/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt @@ -45,4 +45,7 @@ object TestData { fun remap(content: String): String = transformer.remap(mapOf("test.java" to content))["test.java"]!!.first fun remapWithErrors(content: String) = transformer.remap(mapOf("test.java" to content))["test.java"]!! + + fun remapKt(content: String): String = transformer.remap(mapOf("test.kt" to content))["test.kt"]!!.first + fun remapKtWithErrors(content: String) = transformer.remap(mapOf("test.kt" to content))["test.kt"]!! }
\ No newline at end of file diff --git a/src/test/resources/mappings.srg b/src/test/resources/mappings.srg index 4213107..91f6822 100644 --- a/src/test/resources/mappings.srg +++ b/src/test/resources/mappings.srg @@ -9,6 +9,8 @@ MD: a/pkg/A/commonOverloaded (La/pkg/A;)V b/pkg/B/commonOverloaded (La/pkg/B;)V CL: a/pkg/A$1 b/pkg/B$1 CL: a/pkg/A$Inner b/pkg/B$Inner FD: a/pkg/A$Inner/aField b/pkg/B$Inner/bField +CL: a/pkg/A$InnerA b/pkg/B$InnerB +CL: a/pkg/A$GenericA b/pkg/B$GenericB CL: a/pkg/AParent b/pkg/BParent CL: a/pkg/AInterface b/pkg/BInterface MD: a/pkg/AInterface/aInterfaceMethod ()V b/pkg/BInterface/bInterfaceMethod ()V |