From 971ee3e3186f1515e382985ab23a8d32899c5a07 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Wed, 10 Nov 2021 19:29:29 +0100 Subject: Remap mixin injector target arguments even when method is not mapped E.g. there are no mapping entries for constructors cause their name is always `` but we nevertheless want to remap their argument types. We cannot determine whether the name is ambiguous in the mapped environment (because that check is based on the mappings), so we always keep the arguments when it previously had ones. --- .../kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 13 ++++---- src/test/java/a/pkg/A.java | 12 +++++++ src/test/java/b/pkg/B.java | 12 +++++++ .../gradle/remap/mapper/TestMixinInjections.kt | 38 ++++++++++++++++++++++ 4 files changed, 69 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt index a2be57a..3adc4f1 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -339,14 +339,15 @@ internal class PsiMapper( }}") } targetMethods.firstOrNull() - } ?: continue - val mappedName = findMapping(targetMethod)?.deobfuscatedName ?: continue + } + val mappedName = targetMethod?.let(::findMapping)?.deobfuscatedName ?: targetName val ambiguousName = mapping.methodMappings.count { it.deobfuscatedName == mappedName } > 1 - val mapped = mappedName + if (ambiguousName) { - remapMethodDesc(ClassUtil.getAsmMethodSignature(targetMethod)) - } else { - "" + val mapped = mappedName + when { + ambiguousName && targetMethod != null -> + remapMethodDesc(ClassUtil.getAsmMethodSignature(targetMethod)) + targetDesc != null -> remapMethodDesc(targetDesc) + else -> "" } if (mapped != literalValue) { diff --git a/src/test/java/a/pkg/A.java b/src/test/java/a/pkg/A.java index d91a6e5..3143407 100644 --- a/src/test/java/a/pkg/A.java +++ b/src/test/java/a/pkg/A.java @@ -3,6 +3,12 @@ package a.pkg; public class A extends AParent implements AInterface { private int aField; + public A() { + } + + public A(A arg) { + } + public void aMethod() { } @@ -21,6 +27,12 @@ public class A extends AParent implements AInterface { public void commonOverloaded(A arg) { } + public void unmappedOverloaded(Object arg) { + } + + public void unmappedOverloaded(A arg) { + } + @Override public void aInterfaceMethod() { } diff --git a/src/test/java/b/pkg/B.java b/src/test/java/b/pkg/B.java index 48abdac..030ffa2 100644 --- a/src/test/java/b/pkg/B.java +++ b/src/test/java/b/pkg/B.java @@ -3,6 +3,12 @@ package b.pkg; public class B extends BParent implements BInterface { private int bField; + public B() { + } + + public B(B arg) { + } + public void bMethod() { } @@ -21,6 +27,12 @@ public class B extends BParent implements BInterface { public void commonOverloaded(B arg) { } + public void unmappedOverloaded(Object arg) { + } + + public void unmappedOverloaded(B arg) { + } + @Override public void bInterfaceMethod() { } 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 7b9750e..3f8d55f 100644 --- a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt @@ -99,4 +99,42 @@ class TestMixinInjections { } """.trimIndent() } + + @Test + fun `remaps qualified method argument without mappings for target`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "unmappedOverloaded(La/pkg/A;)V") + private void test() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "unmappedOverloaded(Lb/pkg/B;)V") + private void test() {} + } + """.trimIndent() + } + + @Test + fun `remaps constructor target`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "()V") + private void test() {} + @org.spongepowered.asm.mixin.injection.Inject(method = "(La/pkg/A;)V") + private void testArg() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "()V") + private void test() {} + @org.spongepowered.asm.mixin.injection.Inject(method = "(Lb/pkg/B;)V") + private void testArg() {} + } + """.trimIndent() + } } \ No newline at end of file -- cgit