diff options
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | 5 | ||||
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java | 47 |
2 files changed, 30 insertions, 22 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index 0eecc7ba..2c153050 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -33,6 +33,7 @@ import net.fabricmc.mappingio.MappingReader; | |||
| 33 | import net.fabricmc.mappingio.MappingWriter; | 33 | import net.fabricmc.mappingio.MappingWriter; |
| 34 | import net.fabricmc.mappingio.tree.MemoryMappingTree; | 34 | import net.fabricmc.mappingio.tree.MemoryMappingTree; |
| 35 | import net.fabricmc.mappingio.tree.VisitOrder; | 35 | import net.fabricmc.mappingio.tree.VisitOrder; |
| 36 | import net.fabricmc.mappingio.tree.VisitableMappingTree; | ||
| 36 | 37 | ||
| 37 | import cuchaz.enigma.Enigma; | 38 | import cuchaz.enigma.Enigma; |
| 38 | import cuchaz.enigma.EnigmaProfile; | 39 | import cuchaz.enigma.EnigmaProfile; |
| @@ -167,7 +168,7 @@ public class GuiController implements ClientPacketHandler { | |||
| 167 | } | 168 | } |
| 168 | 169 | ||
| 169 | progress.init(1, loadingMessage); | 170 | progress.init(1, loadingMessage); |
| 170 | MemoryMappingTree mappingTree = new MemoryMappingTree(); | 171 | VisitableMappingTree mappingTree = new MemoryMappingTree(); |
| 171 | MappingReader.read(path, format.getMappingIoCounterpart(), mappingTree); | 172 | MappingReader.read(path, format.getMappingIoCounterpart(), mappingTree); |
| 172 | mappings = MappingIoConverter.fromMappingIo(mappingTree, progress); | 173 | mappings = MappingIoConverter.fromMappingIo(mappingTree, progress); |
| 173 | } else { | 174 | } else { |
| @@ -229,7 +230,7 @@ public class GuiController implements ClientPacketHandler { | |||
| 229 | loadedMappingPath = path; | 230 | loadedMappingPath = path; |
| 230 | 231 | ||
| 231 | if (useMappingIo) { | 232 | if (useMappingIo) { |
| 232 | MemoryMappingTree mappingTree = MappingIoConverter.toMappingIo(mapper.getObfToDeobf(), progress); | 233 | VisitableMappingTree mappingTree = MappingIoConverter.toMappingIo(mapper.getObfToDeobf(), progress); |
| 233 | 234 | ||
| 234 | progress.init(1, I18n.translate("progress.mappings.writing")); | 235 | progress.init(1, I18n.translate("progress.mappings.writing")); |
| 235 | MappingWriter writer = MappingWriter.create(path, format.getMappingIoCounterpart()); | 236 | MappingWriter writer = MappingWriter.create(path, format.getMappingIoCounterpart()); |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java index 05d862a6..a0912faf 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | package cuchaz.enigma.translation.mapping.serde; | 1 | package cuchaz.enigma.translation.mapping.serde; |
| 2 | 2 | ||
| 3 | import java.io.IOException; | ||
| 4 | import java.io.UncheckedIOException; | ||
| 3 | import java.util.Deque; | 5 | import java.util.Deque; |
| 4 | import java.util.LinkedList; | 6 | import java.util.LinkedList; |
| 5 | import java.util.List; | 7 | import java.util.List; |
| @@ -7,6 +9,7 @@ import java.util.stream.StreamSupport; | |||
| 7 | 9 | ||
| 8 | import net.fabricmc.mappingio.MappedElementKind; | 10 | import net.fabricmc.mappingio.MappedElementKind; |
| 9 | import net.fabricmc.mappingio.tree.MemoryMappingTree; | 11 | import net.fabricmc.mappingio.tree.MemoryMappingTree; |
| 12 | import net.fabricmc.mappingio.tree.VisitableMappingTree; | ||
| 10 | import net.fabricmc.mappingio.tree.MappingTree.ClassMapping; | 13 | import net.fabricmc.mappingio.tree.MappingTree.ClassMapping; |
| 11 | import net.fabricmc.mappingio.tree.MappingTree.FieldMapping; | 14 | import net.fabricmc.mappingio.tree.MappingTree.FieldMapping; |
| 12 | import net.fabricmc.mappingio.tree.MappingTree.MethodArgMapping; | 15 | import net.fabricmc.mappingio.tree.MappingTree.MethodArgMapping; |
| @@ -29,27 +32,31 @@ import cuchaz.enigma.translation.representation.entry.MethodEntry; | |||
| 29 | import cuchaz.enigma.utils.I18n; | 32 | import cuchaz.enigma.utils.I18n; |
| 30 | 33 | ||
| 31 | public class MappingIoConverter { | 34 | public class MappingIoConverter { |
| 32 | public static MemoryMappingTree toMappingIo(EntryTree<EntryMapping> mappings, ProgressListener progress) { | 35 | public static VisitableMappingTree toMappingIo(EntryTree<EntryMapping> mappings, ProgressListener progress) { |
| 33 | List<EntryTreeNode<EntryMapping>> classes = StreamSupport.stream(mappings.spliterator(), false) | 36 | try { |
| 34 | .filter(node -> node.getEntry() instanceof ClassEntry) | 37 | List<EntryTreeNode<EntryMapping>> classes = StreamSupport.stream(mappings.spliterator(), false) |
| 35 | .toList(); | 38 | .filter(node -> node.getEntry() instanceof ClassEntry) |
| 39 | .toList(); | ||
| 36 | 40 | ||
| 37 | progress.init(classes.size(), I18n.translate("progress.mappings.converting.to_mappingio")); | 41 | progress.init(classes.size(), I18n.translate("progress.mappings.converting.to_mappingio")); |
| 38 | int steps = 0; | 42 | int steps = 0; |
| 39 | 43 | ||
| 40 | MemoryMappingTree mappingTree = new MemoryMappingTree(); | 44 | MemoryMappingTree mappingTree = new MemoryMappingTree(); |
| 41 | mappingTree.visitNamespaces("intermediary", List.of("named")); | 45 | mappingTree.visitNamespaces("intermediary", List.of("named")); |
| 42 | 46 | ||
| 43 | for (EntryTreeNode<EntryMapping> classNode : classes) { | 47 | for (EntryTreeNode<EntryMapping> classNode : classes) { |
| 44 | progress.step(steps++, classNode.getEntry().getFullName()); | 48 | progress.step(steps++, classNode.getEntry().getFullName()); |
| 45 | writeClass(classNode, mappings, mappingTree); | 49 | writeClass(classNode, mappings, mappingTree); |
| 46 | } | 50 | } |
| 47 | 51 | ||
| 48 | mappingTree.visitEnd(); | 52 | mappingTree.visitEnd(); |
| 49 | return mappingTree; | 53 | return mappingTree; |
| 54 | } catch (IOException e) { | ||
| 55 | throw new UncheckedIOException(e); | ||
| 56 | } | ||
| 50 | } | 57 | } |
| 51 | 58 | ||
| 52 | private static void writeClass(EntryTreeNode<EntryMapping> classNode, EntryMap<EntryMapping> oldMappingTree, MemoryMappingTree newMappingTree) { | 59 | private static void writeClass(EntryTreeNode<EntryMapping> classNode, EntryMap<EntryMapping> oldMappingTree, VisitableMappingTree newMappingTree) throws IOException { |
| 53 | ClassEntry classEntry = (ClassEntry) classNode.getEntry(); | 60 | ClassEntry classEntry = (ClassEntry) classNode.getEntry(); |
| 54 | EntryMapping mapping = oldMappingTree.get(classEntry); | 61 | EntryMapping mapping = oldMappingTree.get(classEntry); |
| 55 | Deque<String> parts = new LinkedList<>(); | 62 | Deque<String> parts = new LinkedList<>(); |
| @@ -83,7 +90,7 @@ public class MappingIoConverter { | |||
| 83 | } | 90 | } |
| 84 | } | 91 | } |
| 85 | 92 | ||
| 86 | private static void writeField(EntryTreeNode<EntryMapping> fieldNode, MemoryMappingTree mappingTree) { | 93 | private static void writeField(EntryTreeNode<EntryMapping> fieldNode, VisitableMappingTree mappingTree) throws IOException { |
| 87 | if (fieldNode.getValue() == null || fieldNode.getValue().equals(EntryMapping.DEFAULT)) { | 94 | if (fieldNode.getValue() == null || fieldNode.getValue().equals(EntryMapping.DEFAULT)) { |
| 88 | return; // Shortcut | 95 | return; // Shortcut |
| 89 | } | 96 | } |
| @@ -101,7 +108,7 @@ public class MappingIoConverter { | |||
| 101 | mappingTree.visitComment(MappedElementKind.FIELD, fieldMapping.javadoc()); | 108 | mappingTree.visitComment(MappedElementKind.FIELD, fieldMapping.javadoc()); |
| 102 | } | 109 | } |
| 103 | 110 | ||
| 104 | private static void writeMethod(EntryTreeNode<EntryMapping> methodNode, MemoryMappingTree mappingTree) { | 111 | private static void writeMethod(EntryTreeNode<EntryMapping> methodNode, VisitableMappingTree mappingTree) throws IOException { |
| 105 | MethodEntry methodEntry = ((MethodEntry) methodNode.getEntry()); | 112 | MethodEntry methodEntry = ((MethodEntry) methodNode.getEntry()); |
| 106 | mappingTree.visitMethod(methodEntry.getName(), methodEntry.getDesc().toString()); | 113 | mappingTree.visitMethod(methodEntry.getName(), methodEntry.getDesc().toString()); |
| 107 | 114 | ||
| @@ -127,7 +134,7 @@ public class MappingIoConverter { | |||
| 127 | } | 134 | } |
| 128 | } | 135 | } |
| 129 | 136 | ||
| 130 | private static void writeMethodArg(EntryTreeNode<EntryMapping> argNode, MemoryMappingTree mappingTree) { | 137 | private static void writeMethodArg(EntryTreeNode<EntryMapping> argNode, VisitableMappingTree mappingTree) throws IOException { |
| 131 | if (argNode.getValue() == null || argNode.getValue().equals(EntryMapping.DEFAULT)) { | 138 | if (argNode.getValue() == null || argNode.getValue().equals(EntryMapping.DEFAULT)) { |
| 132 | return; // Shortcut | 139 | return; // Shortcut |
| 133 | } | 140 | } |
| @@ -145,7 +152,7 @@ public class MappingIoConverter { | |||
| 145 | mappingTree.visitComment(MappedElementKind.METHOD_ARG, argMapping.javadoc()); | 152 | mappingTree.visitComment(MappedElementKind.METHOD_ARG, argMapping.javadoc()); |
| 146 | } | 153 | } |
| 147 | 154 | ||
| 148 | private static void writeMethodVar(EntryTreeNode<EntryMapping> varNode, MemoryMappingTree mappingTree) { | 155 | private static void writeMethodVar(EntryTreeNode<EntryMapping> varNode, VisitableMappingTree mappingTree) throws IOException { |
| 149 | if (varNode.getValue() == null || varNode.getValue().equals(EntryMapping.DEFAULT)) { | 156 | if (varNode.getValue() == null || varNode.getValue().equals(EntryMapping.DEFAULT)) { |
| 150 | return; // Shortcut | 157 | return; // Shortcut |
| 151 | } | 158 | } |
| @@ -163,7 +170,7 @@ public class MappingIoConverter { | |||
| 163 | mappingTree.visitComment(MappedElementKind.METHOD_VAR, varMapping.javadoc()); | 170 | mappingTree.visitComment(MappedElementKind.METHOD_VAR, varMapping.javadoc()); |
| 164 | } | 171 | } |
| 165 | 172 | ||
| 166 | public static EntryTree<EntryMapping> fromMappingIo(MemoryMappingTree mappingTree, ProgressListener progress) { | 173 | public static EntryTree<EntryMapping> fromMappingIo(VisitableMappingTree mappingTree, ProgressListener progress) { |
| 167 | EntryTree<EntryMapping> dstMappingTree = new HashEntryTree<>(); | 174 | EntryTree<EntryMapping> dstMappingTree = new HashEntryTree<>(); |
| 168 | progress.init(mappingTree.getClasses().size(), I18n.translate("progress.mappings.converting.from_mappingio")); | 175 | progress.init(mappingTree.getClasses().size(), I18n.translate("progress.mappings.converting.from_mappingio")); |
| 169 | int steps = 0; | 176 | int steps = 0; |