|
6 | 6 | import java.util.Comparator; |
7 | 7 | import java.util.HashSet; |
8 | 8 | import java.util.List; |
| 9 | +import java.util.Objects; |
9 | 10 | import java.util.Set; |
10 | 11 |
|
11 | 12 | import org.slf4j.Logger; |
|
19 | 20 | import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch; |
20 | 21 | import net.fabricmc.mappingio.adapter.RegularAsFlatMappingVisitor; |
21 | 22 | import net.fabricmc.mappingio.format.MappingFormat; |
| 23 | +import net.fabricmc.mappingio.tree.MappingTree; |
| 24 | +import net.fabricmc.mappingio.tree.MemoryMappingTree; |
| 25 | +import net.fabricmc.mappingio.tree.VisitOrder; |
22 | 26 |
|
23 | 27 | import matcher.model.NameType; |
24 | 28 | import matcher.model.Util; |
@@ -508,7 +512,8 @@ public static boolean save(Path file, MappingFormat format, LocalClassEnv env, |
508 | 512 | List<MethodVarInstance> vars = new ArrayList<>(); |
509 | 513 | Set<Set<MethodInstance>> exportedHierarchies = verbosity == MappingsExportVerbosity.MINIMAL ? Util.newIdentityHashSet() : null; |
510 | 514 |
|
511 | | - FlatMappingVisitor writer = new RegularAsFlatMappingVisitor(MappingWriter.create(file, format)); |
| 515 | + MemoryMappingTree tree = new MemoryMappingTree(); |
| 516 | + FlatMappingVisitor writer = new RegularAsFlatMappingVisitor(tree); |
512 | 517 | writer.visitNamespaces(nsNames.get(0), nsNames.subList(1, nsNames.size())); |
513 | 518 |
|
514 | 519 | for (ClassInstance cls : classes) { |
@@ -563,6 +568,41 @@ public static boolean save(Path file, MappingFormat format, LocalClassEnv env, |
563 | 568 | } |
564 | 569 |
|
565 | 570 | writer.visitEnd(); |
| 571 | + |
| 572 | + for (MappingTree.ClassMapping classMapping : tree.getClasses()) { |
| 573 | + String srcName = classMapping.getSrcName(); |
| 574 | + int anonClassIndex; |
| 575 | + |
| 576 | + try { |
| 577 | + anonClassIndex = Integer.parseInt(srcName.substring(srcName.lastIndexOf('$') + 1)); |
| 578 | + } catch (NumberFormatException e) { |
| 579 | + continue; |
| 580 | + } |
| 581 | + |
| 582 | + for (int dstIdx = 0; dstIdx < tree.getMaxNamespaceId(); dstIdx++) { |
| 583 | + String dstName = classMapping.getDstName(dstIdx); |
| 584 | + |
| 585 | + if (dstName == null) { |
| 586 | + continue; |
| 587 | + } |
| 588 | + |
| 589 | + int dstAnonClassIndex; |
| 590 | + |
| 591 | + try { |
| 592 | + dstAnonClassIndex = Integer.parseInt(dstName.substring(dstName.lastIndexOf('$') + 1)); |
| 593 | + } catch (NumberFormatException e) { |
| 594 | + logger.warn("Unable to parse dst anon class index for {} -> {}", srcName, dstName); |
| 595 | + continue; |
| 596 | + } |
| 597 | + |
| 598 | + if (dstAnonClassIndex != anonClassIndex) { |
| 599 | + classMapping.setDstName(dstName.substring(0, dstName.lastIndexOf('$') + 1) + anonClassIndex, dstIdx); |
| 600 | + } |
| 601 | + } |
| 602 | + } |
| 603 | + |
| 604 | + tree.accept(Objects.requireNonNull(MappingWriter.create(file, format), "writer"), VisitOrder.createByName()); |
| 605 | + |
566 | 606 | return true; |
567 | 607 | } |
568 | 608 |
|
|
0 commit comments