diff options
| author | 2023-10-09 12:29:35 +0200 | |
|---|---|---|
| committer | 2023-10-09 12:29:35 +0200 | |
| commit | 4681411ca1f9fcbe5eba5c4009175033e76c865c (patch) | |
| tree | 0c4bc2f4b469288d56b1a9452644d2b7f348b6e3 /enigma/src/main/java | |
| parent | Update to latest Mapping-IO release (diff) | |
| download | enigma-fork-4681411ca1f9fcbe5eba5c4009175033e76c865c.tar.gz enigma-fork-4681411ca1f9fcbe5eba5c4009175033e76c865c.tar.xz enigma-fork-4681411ca1f9fcbe5eba5c4009175033e76c865c.zip | |
Use `VisitableMappingTree` where possible
Diffstat (limited to 'enigma/src/main/java')
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java | 47 |
1 files changed, 27 insertions, 20 deletions
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 05d862a..a0912fa 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; |