Rebuild record components from field names, improves decompile (#497)

This commit is contained in:
modmuss50
2021-09-19 08:53:13 +01:00
committed by GitHub
parent 98d8f37672
commit 256e61ce3c
5 changed files with 97 additions and 6 deletions

View File

@@ -34,7 +34,9 @@ import com.google.common.collect.ImmutableMap;
import org.gradle.api.Project;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.fabricmc.tinyremapper.IMappingProvider;
import net.fabricmc.tinyremapper.TinyRemapper;
@@ -57,14 +59,32 @@ public final class TinyRemapperHelper {
}
public static TinyRemapper getTinyRemapper(Project project, String fromM, String toM) throws IOException {
return getTinyRemapper(project, fromM, toM, false);
}
public static TinyRemapper getTinyRemapper(Project project, String fromM, String toM, boolean fixRecords) throws IOException {
LoomGradleExtension extension = LoomGradleExtension.get(project);
MemoryMappingTree mappingTree = extension.getMappingsProvider().getMappings();
if (fixRecords && !mappingTree.getSrcNamespace().equals(fromM)) {
throw new IllegalStateException("Mappings src namespace must match remap src namespace");
}
int intermediaryNsId = mappingTree.getNamespaceId(MappingsNamespace.INTERMEDIARY.toString());
return TinyRemapper.newRemapper()
.withMappings(create(extension.getMappingsProvider().getMappings(), fromM, toM, true))
.withMappings(create(mappingTree, fromM, toM, true))
.withMappings(out -> JSR_TO_JETBRAINS.forEach(out::acceptClass))
.renameInvalidLocals(true)
.rebuildSourceFilenames(true)
.invalidLvNamePattern(MC_LV_PATTERN)
.extraPreApplyVisitor((cls, next) -> {
if (fixRecords && !cls.isRecord() && "java/lang/Record".equals(cls.getSuperName())) {
return new RecordComponentFixVisitor(next, mappingTree, intermediaryNsId);
}
return next;
})
.build();
}