From 9a048424d3273152b02aafff690b8a420eae17e4 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Fri, 12 Nov 2021 11:05:14 +0100 Subject: Fix inject method in constant being duplicated if remapped twice --- .../kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 2 +- .../gradle/remap/mapper/TestMixinInjections.kt | 23 ++++++++++++++++++++++ 2 files changed, 24 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 bcade7e..edb867c 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -359,7 +359,7 @@ internal class PsiMapper( else -> "" } - if (mapped != literalValue) { + if (mapped != literalValue && valid(literalExpr)) { replace(literalExpr, '"'.toString() + mapped + '"'.toString()) } } 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 fd4c1cb..b473dbe 100644 --- a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt @@ -138,6 +138,29 @@ class TestMixinInjections { """.trimIndent() } + @Test + fun `remaps method in constant`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + private static final String TARGET = "aMethod"; + @org.spongepowered.asm.mixin.injection.Inject(method = TARGET) + private void test1() {} + @org.spongepowered.asm.mixin.injection.Inject(method = TARGET) + private void test2() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + private static final String TARGET = "bMethod"; + @org.spongepowered.asm.mixin.injection.Inject(method = TARGET) + private void test1() {} + @org.spongepowered.asm.mixin.injection.Inject(method = TARGET) + private void test2() {} + } + """.trimIndent() + } + @Test fun `remaps @At target`() { TestData.remap(""" -- cgit