diff options
| author | 2022-10-06 20:03:14 +0200 | |
|---|---|---|
| committer | 2023-10-09 11:54:30 +0200 | |
| commit | 6c7738ca744e55e8e2ea03518a5b93000fe9a864 (patch) | |
| tree | 6a7a3b15f5c56de1992cf7851655f88e6f45c93a /enigma/src | |
| parent | Add initial Mapping-IO export support (diff) | |
| download | enigma-fork-6c7738ca744e55e8e2ea03518a5b93000fe9a864.tar.gz enigma-fork-6c7738ca744e55e8e2ea03518a5b93000fe9a864.tar.xz enigma-fork-6c7738ca744e55e8e2ea03518a5b93000fe9a864.zip | |
Add Mapping-IO import support; small cleanup
Diffstat (limited to 'enigma/src')
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java | 2 | ||||
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java | 58 |
2 files changed, 60 insertions, 0 deletions
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java index 4790fee..5bad929 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java | |||
| @@ -27,6 +27,8 @@ public enum MappingFormat { | |||
| 27 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), net.fabricmc.mappingio.format.MappingFormat.TINY_2), | 27 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), net.fabricmc.mappingio.format.MappingFormat.TINY_2), |
| 28 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.TINY), | 28 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.TINY), |
| 29 | SRG_FILE(SrgMappingsWriter.INSTANCE, null, net.fabricmc.mappingio.format.MappingFormat.SRG), | 29 | SRG_FILE(SrgMappingsWriter.INSTANCE, null, net.fabricmc.mappingio.format.MappingFormat.SRG), |
| 30 | TSRG_FILE(null, null, net.fabricmc.mappingio.format.MappingFormat.TSRG), | ||
| 31 | TSRG_2_FILE(null, null, net.fabricmc.mappingio.format.MappingFormat.TSRG2), | ||
| 30 | PROGUARD(null, ProguardMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.PROGUARD), | 32 | PROGUARD(null, ProguardMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.PROGUARD), |
| 31 | RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, null); | 33 | RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, null); |
| 32 | 34 | ||
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 3a86476..d3fd341 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 | |||
| @@ -6,11 +6,18 @@ import java.util.List; | |||
| 6 | 6 | ||
| 7 | import net.fabricmc.mappingio.MappedElementKind; | 7 | import net.fabricmc.mappingio.MappedElementKind; |
| 8 | import net.fabricmc.mappingio.tree.MemoryMappingTree; | 8 | import net.fabricmc.mappingio.tree.MemoryMappingTree; |
| 9 | import net.fabricmc.mappingio.tree.MappingTree.ClassMapping; | ||
| 10 | import net.fabricmc.mappingio.tree.MappingTree.FieldMapping; | ||
| 11 | import net.fabricmc.mappingio.tree.MappingTree.MethodArgMapping; | ||
| 12 | import net.fabricmc.mappingio.tree.MappingTree.MethodMapping; | ||
| 9 | 13 | ||
| 10 | import cuchaz.enigma.translation.mapping.EntryMap; | 14 | import cuchaz.enigma.translation.mapping.EntryMap; |
| 11 | import cuchaz.enigma.translation.mapping.EntryMapping; | 15 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 12 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 16 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 13 | import cuchaz.enigma.translation.mapping.tree.EntryTreeNode; | 17 | import cuchaz.enigma.translation.mapping.tree.EntryTreeNode; |
| 18 | import cuchaz.enigma.translation.mapping.tree.HashEntryTree; | ||
| 19 | import cuchaz.enigma.translation.representation.MethodDescriptor; | ||
| 20 | import cuchaz.enigma.translation.representation.TypeDescriptor; | ||
| 14 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 21 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 15 | import cuchaz.enigma.translation.representation.entry.Entry; | 22 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 16 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | 23 | import cuchaz.enigma.translation.representation.entry.FieldEntry; |
| @@ -123,4 +130,55 @@ public class MappingIoConverter { | |||
| 123 | mappingTree.visitDstName(MappedElementKind.METHOD_ARG, 0, methodArgMapping.targetName()); | 130 | mappingTree.visitDstName(MappedElementKind.METHOD_ARG, 0, methodArgMapping.targetName()); |
| 124 | mappingTree.visitComment(MappedElementKind.METHOD_ARG, methodArgMapping.javadoc()); | 131 | mappingTree.visitComment(MappedElementKind.METHOD_ARG, methodArgMapping.javadoc()); |
| 125 | } | 132 | } |
| 133 | |||
| 134 | public static EntryTree<EntryMapping> fromMappingIo(MemoryMappingTree mappingTree) { | ||
| 135 | EntryTree<EntryMapping> dstMappingTree = new HashEntryTree<>(); | ||
| 136 | |||
| 137 | for (ClassMapping classMapping : mappingTree.getClasses()) { | ||
| 138 | readClass(classMapping, dstMappingTree); | ||
| 139 | } | ||
| 140 | |||
| 141 | return dstMappingTree; | ||
| 142 | } | ||
| 143 | |||
| 144 | private static void readClass(ClassMapping classMapping, EntryTree<EntryMapping> mappingTree) { | ||
| 145 | ClassEntry currentClass = new ClassEntry(classMapping.getSrcName()); | ||
| 146 | String dstName = classMapping.getDstName(0); | ||
| 147 | |||
| 148 | if (dstName != null) { | ||
| 149 | dstName = dstName.substring(dstName.lastIndexOf('$') + 1); | ||
| 150 | } | ||
| 151 | |||
| 152 | mappingTree.insert(currentClass, new EntryMapping(dstName)); | ||
| 153 | |||
| 154 | for (FieldMapping fieldMapping : classMapping.getFields()) { | ||
| 155 | readField(fieldMapping, currentClass, mappingTree); | ||
| 156 | } | ||
| 157 | |||
| 158 | for (MethodMapping methodMapping : classMapping.getMethods()) { | ||
| 159 | readMethod(methodMapping, currentClass, mappingTree); | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | private static void readField(FieldMapping fieldMapping, ClassEntry parent, EntryTree<EntryMapping> mappingTree) { | ||
| 164 | mappingTree.insert(new FieldEntry(parent, fieldMapping.getSrcName(), new TypeDescriptor(fieldMapping.getSrcDesc())), | ||
| 165 | new EntryMapping(fieldMapping.getDstName(0))); | ||
| 166 | } | ||
| 167 | |||
| 168 | private static void readMethod(MethodMapping methodMapping, ClassEntry parent, EntryTree<EntryMapping> mappingTree) { | ||
| 169 | MethodEntry currentMethod; | ||
| 170 | mappingTree.insert(currentMethod = new MethodEntry(parent, methodMapping.getSrcName(), new MethodDescriptor(methodMapping.getSrcDesc())), | ||
| 171 | new EntryMapping(methodMapping.getDstName(0))); | ||
| 172 | |||
| 173 | for (MethodArgMapping methodArgMapping : methodMapping.getArgs()) { | ||
| 174 | readMethodArg(methodArgMapping, currentMethod, mappingTree); | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | private static void readMethodArg(MethodArgMapping methodArgMapping, MethodEntry parent, EntryTree<EntryMapping> mappingTree) { | ||
| 179 | String methodArgSrcName = methodArgMapping.getSrcName() != null ? methodArgMapping.getSrcName() : ""; | ||
| 180 | |||
| 181 | mappingTree.insert(new LocalVariableEntry(parent, methodArgMapping.getLvIndex(), methodArgSrcName, true, null), | ||
| 182 | new EntryMapping(methodArgMapping.getDstName(0))); | ||
| 183 | } | ||
| 126 | } | 184 | } |