aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/zwirn/RenameTask.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/moe/nea/zwirn/RenameTask.java')
-rw-r--r--src/main/java/moe/nea/zwirn/RenameTask.java25
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()),