33import org .jspecify .annotations .NonNull ;
44import org .jspecify .annotations .Nullable ;
55import org .quiltmc .enigma .api .Enigma ;
6+ import org .quiltmc .enigma .api .EnigmaProject ;
67import org .quiltmc .enigma .api .analysis .index .jar .InheritanceIndex ;
78import org .quiltmc .enigma .api .analysis .index .jar .JarIndex ;
89import org .quiltmc .enigma .api .analysis .index .mapping .MappingsIndex ;
3031import java .util .Set ;
3132import java .util .stream .Stream ;
3233
33- public class EntryRemapper {
34+ public final class EntryRemapper {
3435 private final EntryTree <EntryMapping > deobfMappings ;
3536 private final EntryTree <EntryMapping > jarProposedMappings ;
3637 private final EntryTree <EntryMapping > proposedMappings ;
@@ -45,7 +46,12 @@ public class EntryRemapper {
4546 private final MappingValidator validator ;
4647 private final List <NameProposalService > proposalServices ;
4748
48- private EntryRemapper (Enigma enigma , JarIndex jarIndex , MappingsIndex mappingsIndex , EntryTree <EntryMapping > jarProposedMappings , EntryTree <EntryMapping > deobfMappings , List <NameProposalService > proposalServices ) {
49+ private EntryRemapper (
50+ Enigma enigma , JarIndex jarIndex , JarIndex combinedIndex ,
51+ MappingsIndex mappingsIndex ,
52+ EntryTree <EntryMapping > jarProposedMappings , EntryTree <EntryMapping > deobfMappings ,
53+ List <NameProposalService > proposalServices
54+ ) {
4955 this .deobfMappings = deobfMappings ;
5056 this .jarProposedMappings = jarProposedMappings ;
5157 this .proposedMappings = new HashEntryTree <>(jarProposedMappings );
@@ -58,16 +64,67 @@ private EntryRemapper(Enigma enigma, JarIndex jarIndex, MappingsIndex mappingsIn
5864 this .jarIndex = jarIndex ;
5965 this .mappingsIndex = mappingsIndex ;
6066
61- this .validator = new MappingValidator (this .obfResolver , this .deobfuscator , jarIndex , mappingsIndex );
67+ // use combined index for validator so it can find conflicts with lib method names
68+ final EntryResolver combinedResolver = combinedIndex .getEntryResolver ();
69+ this .validator = new MappingValidator (combinedResolver , new MappingTranslator (this .mappings , combinedResolver ), combinedIndex , mappingsIndex );
6270 this .proposalServices = proposalServices ;
6371 }
6472
65- public static EntryRemapper mapped (Enigma enigma , JarIndex jarIndex , MappingsIndex mappingsIndex , EntryTree <EntryMapping > proposedMappings , EntryTree <EntryMapping > deobfMappings , List <NameProposalService > proposalServices ) {
66- return new EntryRemapper (enigma , jarIndex , mappingsIndex , proposedMappings , deobfMappings , proposalServices );
73+ public static EntryRemapper mapped (
74+ Enigma project , JarIndex jarIndex , JarIndex combinedIndex ,
75+ MappingsIndex mappingsIndex ,
76+ EntryTree <EntryMapping > proposedMappings , EntryTree <EntryMapping > deobfMappings ,
77+ List <NameProposalService > proposalServices
78+ ) {
79+ return new EntryRemapper (
80+ project , jarIndex , combinedIndex ,
81+ mappingsIndex ,
82+ proposedMappings , deobfMappings ,
83+ proposalServices
84+ );
6785 }
6886
69- public static EntryRemapper empty (Enigma enigma , JarIndex index , List <NameProposalService > proposalServices ) {
70- return new EntryRemapper (enigma , index , MappingsIndex .empty (), new HashEntryTree <>(), new HashEntryTree <>(), proposalServices );
87+ /**
88+ * Creates a remapper with the passed {@code project}'s {@linkplain EnigmaProject#getEnigma() enigma} instance,
89+ * {@linkplain EnigmaProject#getJarIndex() jar index}, {@linkplain EnigmaProject#getCombinedIndex() combined index},
90+ * {@linkplain EnigmaProject#getMappingsIndex() mappings index},
91+ * and its enigma instance's {@linkplain Enigma#getNameProposalServices() name proposal services}.
92+ */
93+ public static EntryRemapper mapped (
94+ EnigmaProject project , EntryTree <EntryMapping > proposedMappings , EntryTree <EntryMapping > deobfMappings
95+ ) {
96+ return mapped (
97+ project .getEnigma (), project .getJarIndex (), project .getCombinedIndex (),
98+ project .getMappingsIndex (),
99+ proposedMappings , deobfMappings ,
100+ project .getEnigma ().getNameProposalServices ()
101+ );
102+ }
103+
104+ public static EntryRemapper empty (
105+ Enigma enigma ,
106+ JarIndex jarIndex , JarIndex combinedIndex ,
107+ List <NameProposalService > proposalServices
108+ ) {
109+ return new EntryRemapper (
110+ enigma , jarIndex , combinedIndex ,
111+ MappingsIndex .empty (), new HashEntryTree <>(), new HashEntryTree <>(),
112+ proposalServices
113+ );
114+ }
115+
116+ /**
117+ * Creates an empty remapper with the passed {@code project}'s
118+ * {@linkplain EnigmaProject#getEnigma() enigma} instance,
119+ * {@linkplain EnigmaProject#getJarIndex() jar index}, {@linkplain EnigmaProject#getCombinedIndex() combined index},
120+ * and its enigma instance's {@linkplain Enigma#getNameProposalServices() name proposal services}.
121+ */
122+ public static EntryRemapper empty (EnigmaProject project ) {
123+ return empty (
124+ project .getEnigma (),
125+ project .getJarIndex (), project .getCombinedIndex (),
126+ project .getEnigma ().getNameProposalServices ()
127+ );
71128 }
72129
73130 public void validatePutMapping (ValidationContext vc , Entry <?> obfuscatedEntry , @ NonNull EntryMapping deobfMapping ) {
@@ -82,7 +139,9 @@ private void doPutMapping(ValidationContext vc, Entry<?> obfuscatedEntry, @NonNu
82139 EntryMapping oldMapping = this .getMapping (obfuscatedEntry );
83140 boolean renaming = !Objects .equals (oldMapping .targetName (), deobfMapping .targetName ());
84141
85- Collection <Entry <?>> resolvedEntries = renaming ? this .resolveAllRoots (obfuscatedEntry ) : this .obfResolver .resolveEntry (obfuscatedEntry , ResolutionStrategy .RESOLVE_CLOSEST );
142+ Collection <Entry <?>> resolvedEntries = renaming
143+ ? this .resolveAllRoots (obfuscatedEntry )
144+ : this .obfResolver .resolveEntry (obfuscatedEntry , ResolutionStrategy .RESOLVE_CLOSEST );
86145
87146 if (renaming && deobfMapping .targetName () != null ) {
88147 for (Entry <?> resolvedEntry : resolvedEntries ) {
0 commit comments