diff options
author | Linnea Gräf <nea@nea.moe> | 2024-03-06 01:33:51 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-03-06 01:33:51 +0100 |
commit | 3c5d9d3c161c1516e2a695e21b9c69e816e88036 (patch) | |
tree | 5f3363b0fb940690b4ec8e244240d344b0f5e1f1 /src/main/java/moe/nea/zwirn/RenameTask.java | |
parent | 24553fcf7129e94559627a2edbf02777dc987f64 (diff) | |
download | zwirn-3c5d9d3c161c1516e2a695e21b9c69e816e88036.tar.gz zwirn-3c5d9d3c161c1516e2a695e21b9c69e816e88036.tar.bz2 zwirn-3c5d9d3c161c1516e2a695e21b9c69e816e88036.zip |
Renaming and fixing method descriptors sometimes
Diffstat (limited to 'src/main/java/moe/nea/zwirn/RenameTask.java')
-rw-r--r-- | src/main/java/moe/nea/zwirn/RenameTask.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/main/java/moe/nea/zwirn/RenameTask.java b/src/main/java/moe/nea/zwirn/RenameTask.java index 89c15c4..a9a2153 100644 --- a/src/main/java/moe/nea/zwirn/RenameTask.java +++ b/src/main/java/moe/nea/zwirn/RenameTask.java @@ -4,6 +4,8 @@ import net.fabricmc.stitch.commands.tinyv2.*; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; @@ -11,6 +13,7 @@ public class RenameTask { private final TinyFile tinyFile; private final List<Zwirn.RenameCommand> newNamespaceOrder; private final int[] namespaceRemapOrder; + private final SimpleRemapper remapper; public RenameTask(@NotNull TinyFile tinyFile, @NotNull List<Zwirn.RenameCommand> newNamespaceOrder) { this.tinyFile = tinyFile; @@ -18,8 +21,26 @@ public class RenameTask { namespaceRemapOrder = newNamespaceOrder.stream().mapToInt( it -> tinyFile.getHeader().getNamespaces().indexOf(it.oldNamespaceName()) ).toArray(); + this.remapper = new SimpleRemapper( + classOnlyRename(), "__old", "__new" + ); } + public TinyFile classOnlyRename() { + List<String> namespaces = new ArrayList<>(); + namespaces.add("__old"); + namespaces.add("__new"); + return new TinyFile( + new TinyHeader(namespaces, 2, 0, new HashMap<>()), + tinyFile.getClassEntries().stream().map( + it -> new TinyClass( + Arrays.asList( + it.getClassNames().get(0), + it.getClassNames().get(namespaceRemapOrder[0])) + ) + ).collect(Collectors.toList()) + ); + } private List<String> rename(List<String> strings) { List<String> newNames = new ArrayList<>(namespaceRemapOrder.length); @@ -48,7 +69,7 @@ public class RenameTask { private TinyField renameField(TinyField tinyField) { var names = rename(tinyField.getFieldNames()); return new TinyField( - names.get(0), + remapper.remapFieldDescriptor(tinyField.getFieldDescriptorInFirstNamespace()), names, tinyField.getComments() ); @@ -57,7 +78,7 @@ public class RenameTask { private TinyMethod renameMethod(TinyMethod tinyMethod) { var names = rename(tinyMethod.getMethodNames()); return new TinyMethod( - names.get(0), + remapper.remapMethodDescriptor(tinyMethod.getMethodDescriptorInFirstNamespace()), names, tinyMethod.getParameters().stream().map(this::renameMethodParameter).collect(Collectors.toList()), tinyMethod.getLocalVariables().stream().map(this::renameVariable).collect(Collectors.toList()), |