From 5134612493d43da328a2567e8425981094d67c50 Mon Sep 17 00:00:00 2001 From: Sychic <47618543+Sychic@users.noreply.github.com> Date: Mon, 6 May 2024 10:13:52 -0400 Subject: Override `createInnerClassMapping` for `LegacyMappingSetModelFactory` (#22) Co-authored-by: DJtheRedstoner <52044242+DJtheRedstoner@users.noreply.github.com> --- .../remap/legacy/LegacyMappingSetModelFactory.kt | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/kotlin/com/replaymod/gradle/remap/legacy/LegacyMappingSetModelFactory.kt b/src/main/kotlin/com/replaymod/gradle/remap/legacy/LegacyMappingSetModelFactory.kt index ec21546..6d463f0 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/legacy/LegacyMappingSetModelFactory.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/legacy/LegacyMappingSetModelFactory.kt @@ -3,7 +3,10 @@ package com.replaymod.gradle.remap.legacy import org.cadixdev.bombe.type.signature.MethodSignature import org.cadixdev.lorenz.MappingSet import org.cadixdev.lorenz.impl.MappingSetModelFactoryImpl +import org.cadixdev.lorenz.impl.model.InnerClassMappingImpl import org.cadixdev.lorenz.impl.model.TopLevelClassMappingImpl +import org.cadixdev.lorenz.model.ClassMapping +import org.cadixdev.lorenz.model.InnerClassMapping import org.cadixdev.lorenz.model.MethodMapping import org.cadixdev.lorenz.model.TopLevelClassMapping import java.util.* @@ -29,4 +32,29 @@ class LegacyMappingSetModelFactory : MappingSetModelFactoryImpl() { } } } + + override fun createInnerClassMapping( + parent: ClassMapping, *>?, + obfuscatedName: String?, + deobfuscatedName: String? + ): InnerClassMapping { + return object : InnerClassMappingImpl(parent, obfuscatedName, deobfuscatedName) { + private fun stripDesc(signature: MethodSignature): MethodSignature { + // actual descriptor isn't included in legacy format + return MethodSignature.of(signature.name, "()V") + } + + override fun hasMethodMapping(signature: MethodSignature): Boolean { + return super.hasMethodMapping(signature) || super.hasMethodMapping(stripDesc(signature)) + } + + override fun getMethodMapping(signature: MethodSignature): Optional { + var maybeMapping = super.getMethodMapping(signature) + if (!maybeMapping.isPresent || maybeMapping.get().let { it.signature == it.deobfuscatedSignature }) { + maybeMapping = super.getMethodMapping(stripDesc(signature)) + } + return maybeMapping + } + } + } } -- cgit