From 06c82ab212214a2de1417718e28926272c12aa1f Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Sat, 8 Aug 2020 17:12:03 +0800 Subject: [PATCH] Remap correctly on covariant return and synthetic methods. --- build.gradle | 2 +- .../gradle/tasks/ProcessMappingTask.groovy | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index e3932b3..74afb1c 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'io.izzel.arclight' -version '1.7' +version '1.8' repositories { mavenCentral() diff --git a/src/main/groovy/io/izzel/arclight/gradle/tasks/ProcessMappingTask.groovy b/src/main/groovy/io/izzel/arclight/gradle/tasks/ProcessMappingTask.groovy index 287d3a6..82dd1a5 100644 --- a/src/main/groovy/io/izzel/arclight/gradle/tasks/ProcessMappingTask.groovy +++ b/src/main/groovy/io/izzel/arclight/gradle/tasks/ProcessMappingTask.groovy @@ -1,5 +1,7 @@ package io.izzel.arclight.gradle.tasks +import com.google.common.collect.MultimapBuilder +import com.google.common.collect.SetMultimap import io.izzel.arclight.gradle.Utils import net.md_5.specialsource.InheritanceMap import net.md_5.specialsource.Jar @@ -10,11 +12,7 @@ import net.md_5.specialsource.provider.JarProvider import net.md_5.specialsource.provider.JointProvider import net.md_5.specialsource.transformer.MappingTransformer import org.gradle.api.DefaultTask -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.* import org.objectweb.asm.Type import org.objectweb.asm.commons.Remapper @@ -73,6 +71,16 @@ class ProcessMappingTask extends DefaultTask { !it.startsWith('#') && !it.trim().empty }.collect { it.toString() } processors.forEach { it.call(csrg, ats, srg) } + def srgMethodAlias = MultimapBuilder.hashKeys().hashSetValues().build() as SetMultimap + srg.methods.entrySet().forEach { + def spl = it.key.split(' ') + def srgMethod = it.value + if (srgMethod.startsWith('func_')) { + def i = spl[0].lastIndexOf('/') + def notch = spl[0].substring(i + 1) + srgMethodAlias.put(srgMethod, notch) + } + } def srgRev = srg.classes.collectEntries { [(it.value): it.key] } def csrgRev = csrg.classes.collectEntries { [(it.value): it.key] } def im = new InheritanceMap() @@ -195,6 +203,18 @@ class ProcessMappingTask extends DefaultTask { def csrgCl = notchToCsrgMapper.map(owner) def csrgDesc = notchToCsrgMapper.mapMethodDesc(desc) def csrgMethod = ProcessMappingTask.findCsrg(prov, csrgCl, notch, csrgDesc, csrg.methods) + if (csrgMethod == null) { + for (def alias : srgMethodAlias.get(srgMethod)) { + if (alias != notch) { + def find = ProcessMappingTask.findCsrg(prov, csrgCl, alias, csrgDesc, csrg.methods) + if (find != null) { + csrgMethod = find + break + } + } + } + } + if (csrgMethod == null) csrgMethod = notch writer.println("MD: $csrgCl/$csrgMethod $csrgDesc ${srg.classes.get(owner)}/$srgMethod ${notchToSrgMapper.mapMethodDesc(desc)}") } } @@ -209,7 +229,7 @@ class ProcessMappingTask extends DefaultTask { if (csrg) return csrg } } - return notch + return null } private static List allRet(InheritanceProvider prov, String desc) {