diff options
-rw-r--r-- | src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 6 | ||||
-rw-r--r-- | src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinSyntheticProperties.kt | 13 | ||||
-rw-r--r-- | src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt | 2 | ||||
-rw-r--r-- | src/testA/kotlin/aMarker.kt | 3 | ||||
-rw-r--r-- | src/testA/kotlin/pkg/Kt.kt | 12 | ||||
-rw-r--r-- | src/testB/kotlin/bMarker.kt | 3 | ||||
-rw-r--r-- | src/testB/kotlin/pkg/Kt.kt | 12 |
7 files changed, 50 insertions, 1 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt index 13bcc14..0ad498b 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeAsSequence import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor.Companion.propertyNameByGetMethodName import java.util.* @@ -150,7 +151,10 @@ internal class PsiMapper( } private fun map(expr: PsiElement, property: SyntheticJavaPropertyDescriptor) { - val getter = property.getMethod.findPsi() as? PsiMethod ?: return + val getter = property.getMethod + .overriddenTreeAsSequence(false) + .firstNotNullOfOrNull { it.findPsi() } + as? PsiMethod ?: return val mapping = findMapping(getter) val mappedGetter = mapping?.deobfuscatedName ?: return if (mappedGetter != getter.name) { diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinSyntheticProperties.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinSyntheticProperties.kt index b77978a..20b65b9 100644 --- a/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinSyntheticProperties.kt +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinSyntheticProperties.kt @@ -141,4 +141,17 @@ class TestKotlinSyntheticProperties { val v = B().b """.trimIndent() } + + @Test + fun `remaps synthetic property even when overwritten in kotlin subclass`() { + TestData.remapKt(""" + import pkg.Kt + val v = Kt().syntheticA + fun test() { Kt().syntheticA = Kt() } + """.trimIndent()) shouldBe """ + import pkg.Kt + val v = Kt().syntheticB + fun test() { Kt().syntheticB = Kt() } + """.trimIndent() + } } 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 c40635c..c5b8851 100644 --- a/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt +++ b/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt @@ -40,10 +40,12 @@ object TestData { classpath = arrayOf( findClasspathEntry("org.spongepowered.asm.mixin.Mixin"), findClasspathEntry("a.pkg.A"), + findClasspathEntry("AMarkerKt"), ) remappedClasspath = arrayOf( findClasspathEntry("org.spongepowered.asm.mixin.Mixin"), findClasspathEntry("b.pkg.B"), + findClasspathEntry("BMarkerKt"), ) patternAnnotation = "remap.Pattern" } diff --git a/src/testA/kotlin/aMarker.kt b/src/testA/kotlin/aMarker.kt new file mode 100644 index 0000000..86d0391 --- /dev/null +++ b/src/testA/kotlin/aMarker.kt @@ -0,0 +1,3 @@ +@file:Suppress("unused") // Exists only so we can find the testA/kotlin classes on the classpath + +private const val dummy = 1 diff --git a/src/testA/kotlin/pkg/Kt.kt b/src/testA/kotlin/pkg/Kt.kt new file mode 100644 index 0000000..9c42707 --- /dev/null +++ b/src/testA/kotlin/pkg/Kt.kt @@ -0,0 +1,12 @@ +package pkg + +import a.pkg.A + +class Kt : A() { + override fun getSyntheticA(): A { + return this + } + + override fun setSyntheticA(arg: A) { + } +}
\ No newline at end of file diff --git a/src/testB/kotlin/bMarker.kt b/src/testB/kotlin/bMarker.kt new file mode 100644 index 0000000..b56de50 --- /dev/null +++ b/src/testB/kotlin/bMarker.kt @@ -0,0 +1,3 @@ +@file:Suppress("unused") // Exists only so we can find the testB/kotlin classes on the classpath + +private const val dummy = 1 diff --git a/src/testB/kotlin/pkg/Kt.kt b/src/testB/kotlin/pkg/Kt.kt new file mode 100644 index 0000000..7e75181 --- /dev/null +++ b/src/testB/kotlin/pkg/Kt.kt @@ -0,0 +1,12 @@ +package pkg + +import b.pkg.B + +class Kt : B() { + override fun getSyntheticB(): B { + return this + } + + override fun setSyntheticB(arg: B) { + } +}
\ No newline at end of file |