From 117d1cf035edc83017e344a6142c40cd72420642 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Thu, 11 Nov 2021 21:22:12 +0100 Subject: Fix @At target in constant being duplicated if remapped twice --- .../kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 2 +- .../gradle/remap/mapper/TestMixinInjections.kt | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt index c620c4c..bcade7e 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -473,7 +473,7 @@ internal class PsiMapper( if ("target" != attribute.name) continue val (value, signature) = attribute.resolvedLiteralValue ?: continue val newSignature = remapMixinTarget(signature) - if (newSignature != signature) { + if (newSignature != signature && valid(value)) { replace(value, "\"$newSignature\"") } } diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt index f01a832..fd4c1cb 100644 --- a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt @@ -179,4 +179,31 @@ class TestMixinInjections { } """.trimIndent() } + + @Test + fun `remaps @At target in constant`() { + TestData.remap(""" + import org.spongepowered.asm.mixin.injection.At; + import org.spongepowered.asm.mixin.injection.Inject; + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + private static final String TARGET = "La/pkg/A;aInterfaceMethod()V"; + @Inject(method = "aMethod", at = @At(target = TARGET)) + private void test1() {} + @Inject(method = "aMethod", at = @At(target = TARGET)) + private void test2() {} + } + """.trimIndent()) shouldBe """ + import org.spongepowered.asm.mixin.injection.At; + import org.spongepowered.asm.mixin.injection.Inject; + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + private static final String TARGET = "Lb/pkg/B;bInterfaceMethod()V"; + @Inject(method = "bMethod", at = @At(target = TARGET)) + private void test1() {} + @Inject(method = "bMethod", at = @At(target = TARGET)) + private void test2() {} + } + """.trimIndent() + } } \ No newline at end of file -- cgit