diff options
Diffstat (limited to 'enigma/src/main/java/cuchaz')
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java | 8 | ||||
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java | 50 |
2 files changed, 50 insertions, 8 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 bbbf369..530aff4 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 | |||
| @@ -15,6 +15,7 @@ import net.fabricmc.mappingio.tree.VisitOrder; | |||
| 15 | import net.fabricmc.mappingio.tree.VisitableMappingTree; | 15 | import net.fabricmc.mappingio.tree.VisitableMappingTree; |
| 16 | 16 | ||
| 17 | import cuchaz.enigma.ProgressListener; | 17 | import cuchaz.enigma.ProgressListener; |
| 18 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 18 | import cuchaz.enigma.translation.mapping.EntryMapping; | 19 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 19 | import cuchaz.enigma.translation.mapping.MappingDelta; | 20 | import cuchaz.enigma.translation.mapping.MappingDelta; |
| 20 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader; | 21 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader; |
| @@ -82,7 +83,12 @@ public enum MappingFormat { | |||
| 82 | } | 83 | } |
| 83 | } | 84 | } |
| 84 | 85 | ||
| 86 | @Deprecated | ||
| 85 | public EntryTree<EntryMapping> read(Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) throws IOException, MappingParseException { | 87 | public EntryTree<EntryMapping> read(Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) throws IOException, MappingParseException { |
| 88 | return read(path, progressListener, saveParameters, null); | ||
| 89 | } | ||
| 90 | |||
| 91 | public EntryTree<EntryMapping> read(Path path, ProgressListener progressListener, MappingSaveParameters saveParameters, JarIndex index) throws IOException, MappingParseException { | ||
| 86 | if (!useMappingIo()) { | 92 | if (!useMappingIo()) { |
| 87 | if (reader == null) { | 93 | if (reader == null) { |
| 88 | throw new IllegalStateException(name() + " does not support reading"); | 94 | throw new IllegalStateException(name() + " does not support reading"); |
| @@ -103,7 +109,7 @@ public enum MappingFormat { | |||
| 103 | 109 | ||
| 104 | VisitableMappingTree mappingTree = new MemoryMappingTree(); | 110 | VisitableMappingTree mappingTree = new MemoryMappingTree(); |
| 105 | MappingReader.read(path, mappingIoCounterpart, mappingTree); | 111 | MappingReader.read(path, mappingIoCounterpart, mappingTree); |
| 106 | return MappingIoConverter.fromMappingIo(mappingTree, progressListener); | 112 | return MappingIoConverter.fromMappingIo(mappingTree, progressListener, index); |
| 107 | } | 113 | } |
| 108 | 114 | ||
| 109 | @Nullable | 115 | @Nullable |
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 4372585..3843d8e 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 | |||
| @@ -7,6 +7,9 @@ import java.util.LinkedList; | |||
| 7 | import java.util.List; | 7 | import java.util.List; |
| 8 | import java.util.stream.StreamSupport; | 8 | import java.util.stream.StreamSupport; |
| 9 | 9 | ||
| 10 | import javax.annotation.Nullable; | ||
| 11 | |||
| 12 | import org.jetbrains.annotations.ApiStatus; | ||
| 10 | import net.fabricmc.mappingio.MappedElementKind; | 13 | import net.fabricmc.mappingio.MappedElementKind; |
| 11 | import net.fabricmc.mappingio.tree.MemoryMappingTree; | 14 | import net.fabricmc.mappingio.tree.MemoryMappingTree; |
| 12 | import net.fabricmc.mappingio.tree.VisitableMappingTree; | 15 | import net.fabricmc.mappingio.tree.VisitableMappingTree; |
| @@ -17,6 +20,7 @@ import net.fabricmc.mappingio.tree.MappingTree.MethodMapping; | |||
| 17 | import net.fabricmc.mappingio.tree.MappingTree.MethodVarMapping; | 20 | import net.fabricmc.mappingio.tree.MappingTree.MethodVarMapping; |
| 18 | 21 | ||
| 19 | import cuchaz.enigma.ProgressListener; | 22 | import cuchaz.enigma.ProgressListener; |
| 23 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 20 | import cuchaz.enigma.translation.mapping.EntryMap; | 24 | import cuchaz.enigma.translation.mapping.EntryMap; |
| 21 | import cuchaz.enigma.translation.mapping.EntryMapping; | 25 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 22 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 26 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| @@ -31,6 +35,7 @@ import cuchaz.enigma.translation.representation.entry.LocalVariableEntry; | |||
| 31 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 35 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 32 | import cuchaz.enigma.utils.I18n; | 36 | import cuchaz.enigma.utils.I18n; |
| 33 | 37 | ||
| 38 | @ApiStatus.Internal | ||
| 34 | public class MappingIoConverter { | 39 | public class MappingIoConverter { |
| 35 | public static VisitableMappingTree toMappingIo(EntryTree<EntryMapping> mappings, ProgressListener progress) { | 40 | public static VisitableMappingTree toMappingIo(EntryTree<EntryMapping> mappings, ProgressListener progress) { |
| 36 | return toMappingIo(mappings, progress, "intermediary", "named"); | 41 | return toMappingIo(mappings, progress, "intermediary", "named"); |
| @@ -174,20 +179,20 @@ public class MappingIoConverter { | |||
| 174 | mappingTree.visitComment(MappedElementKind.METHOD_VAR, varMapping.javadoc()); | 179 | mappingTree.visitComment(MappedElementKind.METHOD_VAR, varMapping.javadoc()); |
| 175 | } | 180 | } |
| 176 | 181 | ||
| 177 | public static EntryTree<EntryMapping> fromMappingIo(VisitableMappingTree mappingTree, ProgressListener progress) { | 182 | public static EntryTree<EntryMapping> fromMappingIo(VisitableMappingTree mappingTree, ProgressListener progress, @Nullable JarIndex index) { |
| 178 | EntryTree<EntryMapping> dstMappingTree = new HashEntryTree<>(); | 183 | EntryTree<EntryMapping> dstMappingTree = new HashEntryTree<>(); |
| 179 | progress.init(mappingTree.getClasses().size(), I18n.translate("progress.mappings.converting.from_mappingio")); | 184 | progress.init(mappingTree.getClasses().size(), I18n.translate("progress.mappings.converting.from_mappingio")); |
| 180 | int steps = 0; | 185 | int steps = 0; |
| 181 | 186 | ||
| 182 | for (ClassMapping classMapping : mappingTree.getClasses()) { | 187 | for (ClassMapping classMapping : mappingTree.getClasses()) { |
| 183 | progress.step(steps++, classMapping.getDstName(0) != null ? classMapping.getDstName(0) : classMapping.getSrcName()); | 188 | progress.step(steps++, classMapping.getDstName(0) != null ? classMapping.getDstName(0) : classMapping.getSrcName()); |
| 184 | readClass(classMapping, dstMappingTree); | 189 | readClass(classMapping, dstMappingTree, index); |
| 185 | } | 190 | } |
| 186 | 191 | ||
| 187 | return dstMappingTree; | 192 | return dstMappingTree; |
| 188 | } | 193 | } |
| 189 | 194 | ||
| 190 | private static void readClass(ClassMapping classMapping, EntryTree<EntryMapping> mappingTree) { | 195 | private static void readClass(ClassMapping classMapping, EntryTree<EntryMapping> mappingTree, JarIndex index) { |
| 191 | ClassEntry currentClass = new ClassEntry(classMapping.getSrcName()); | 196 | ClassEntry currentClass = new ClassEntry(classMapping.getSrcName()); |
| 192 | String dstName = classMapping.getDstName(0); | 197 | String dstName = classMapping.getDstName(0); |
| 193 | 198 | ||
| @@ -198,7 +203,7 @@ public class MappingIoConverter { | |||
| 198 | mappingTree.insert(currentClass, new EntryMapping(dstName, classMapping.getComment())); | 203 | mappingTree.insert(currentClass, new EntryMapping(dstName, classMapping.getComment())); |
| 199 | 204 | ||
| 200 | for (FieldMapping fieldMapping : classMapping.getFields()) { | 205 | for (FieldMapping fieldMapping : classMapping.getFields()) { |
| 201 | readField(fieldMapping, currentClass, mappingTree); | 206 | readField(fieldMapping, currentClass, mappingTree, index); |
| 202 | } | 207 | } |
| 203 | 208 | ||
| 204 | for (MethodMapping methodMapping : classMapping.getMethods()) { | 209 | for (MethodMapping methodMapping : classMapping.getMethods()) { |
| @@ -206,9 +211,40 @@ public class MappingIoConverter { | |||
| 206 | } | 211 | } |
| 207 | } | 212 | } |
| 208 | 213 | ||
| 209 | private static void readField(FieldMapping fieldMapping, ClassEntry parent, EntryTree<EntryMapping> mappingTree) { | 214 | private static void readField(FieldMapping fieldMapping, ClassEntry parent, EntryTree<EntryMapping> mappingTree, JarIndex index) { |
| 210 | mappingTree.insert(new FieldEntry(parent, fieldMapping.getSrcName(), new TypeDescriptor(fieldMapping.getSrcDesc())), | 215 | String srcDesc = fieldMapping.getSrcDesc(); |
| 211 | new EntryMapping(fieldMapping.getDstName(0), fieldMapping.getComment())); | 216 | FieldEntry[] fieldEntries; |
| 217 | |||
| 218 | if (srcDesc != null) { | ||
| 219 | fieldEntries = new FieldEntry[] { new FieldEntry(parent, fieldMapping.getSrcName(), new TypeDescriptor(fieldMapping.getSrcDesc())) }; | ||
| 220 | } else { | ||
| 221 | if (index == null) return; // Enigma requires source descriptors, and without an index we can't look them up | ||
| 222 | |||
| 223 | fieldEntries = index.getChildrenByClass().get(parent).stream() | ||
| 224 | .filter(entry -> entry instanceof FieldEntry) | ||
| 225 | .filter(entry -> entry.getName().equals(fieldMapping.getSrcName())) | ||
| 226 | .toArray(FieldEntry[]::new); | ||
| 227 | |||
| 228 | if (fieldEntries.length == 0) { // slow path for synthetics | ||
| 229 | fieldEntries = index.getEntryIndex().getFields().stream() | ||
| 230 | .filter(entry -> entry.getParent().getFullName().equals(parent.getFullName())) | ||
| 231 | .filter(entry -> { | ||
| 232 | if (entry.getName().equals(fieldMapping.getSrcName())) { | ||
| 233 | return true; | ||
| 234 | } else { | ||
| 235 | System.out.println("Entry name: " + entry.getName() + ", mapping name: " + fieldMapping.getSrcName()); | ||
| 236 | return false; | ||
| 237 | } | ||
| 238 | }) | ||
| 239 | .toArray(FieldEntry[]::new); | ||
| 240 | } | ||
| 241 | |||
| 242 | if (fieldEntries.length == 0) return; // No target found, invalid mapping | ||
| 243 | } | ||
| 244 | |||
| 245 | for (FieldEntry fieldEntry : fieldEntries) { | ||
| 246 | mappingTree.insert(fieldEntry, new EntryMapping(fieldMapping.getDstName(0), fieldMapping.getComment())); | ||
| 247 | } | ||
| 212 | } | 248 | } |
| 213 | 249 | ||
| 214 | private static void readMethod(MethodMapping methodMapping, ClassEntry parent, EntryTree<EntryMapping> mappingTree) { | 250 | private static void readMethod(MethodMapping methodMapping, ClassEntry parent, EntryTree<EntryMapping> mappingTree) { |