1717import net .fabricmc .mappingio .MappingVisitor ;
1818import net .fabricmc .mappingio .adapter .MappingDstNsReorder ;
1919import net .fabricmc .mappingio .adapter .MappingSourceNsSwitch ;
20- import net .fabricmc .mappingio .tree .MappingTree .ClassMapping ;
21- import net .fabricmc .mappingio .tree .MappingTree .FieldMapping ;
22- import net .fabricmc .mappingio .tree .MappingTree .MethodMapping ;
20+ import net .fabricmc .mappingio .tree .MappingTree .ElementMapping ;
2321import net .fabricmc .mappingio .tree .MappingTreeView ;
2422import net .fabricmc .mappingio .tree .MemoryMappingTree ;
2523
@@ -61,6 +59,9 @@ private McpReader(McpFiles files) {
6159 private MappingTreeView read () throws IOException {
6260 mappings = new MemoryMappingTree ();
6361
62+ try (InputStreamReader input = new InputStreamReader (files .readIntermediary ())) {
63+ MappingReader .read (input , mappings );
64+ }
6465 try (InputStreamReader input = new InputStreamReader (files .readSrg ())) {
6566 readSrg (input );
6667 }
@@ -73,9 +74,6 @@ private MappingTreeView read() throws IOException {
7374 try (InputStreamReader input = new InputStreamReader (files .readParams ())) {
7475 readParams (input );
7576 }
76- try (InputStreamReader input = new InputStreamReader (files .readIntermediary ())) {
77- MappingReader .read (input , mappings );
78- }
7977
8078 return mappings ;
8179 }
@@ -109,22 +107,23 @@ private void readSrg(BufferedReader r) throws IOException {
109107 }
110108
111109 String src = args [1 ];
112- String dst = args [2 ];
110+ String srg = args [2 ];
113111
114112 if (src == null || src .isEmpty ()) {
115113 throw new IOException ("invalid src name for class mapping on line " + lineNumber );
116114 }
117- if (dst == null || dst .isEmpty ()) {
118- throw new IOException ("invalid dst name for class mapping on line " + lineNumber );
115+ if (srg == null || srg .isEmpty ()) {
116+ throw new IOException ("invalid srg name for class mapping on line " + lineNumber );
119117 }
120118
121119 if (!src .equals (cls )) {
122120 cls = src ;
123121 visitCls = mappings .visitClass (src );
124122
125123 if (visitCls ) {
126- mappings .visitDstName (MappedElementKind .CLASS , 0 , dst );
127- mappings .visitDstName (MappedElementKind .CLASS , 1 , dst );
124+ // for classes, srg == named
125+ mappings .visitDstName (MappedElementKind .CLASS , 0 , srg );
126+ mappings .visitDstName (MappedElementKind .CLASS , 1 , srg );
128127 visitCls = mappings .visitElementContent (MappedElementKind .CLASS );
129128 }
130129 }
@@ -142,17 +141,17 @@ private void readSrg(BufferedReader r) throws IOException {
142141 }
143142
144143 String srcCls = null ;
145- String dstCls = null ;
144+ String srgCls = null ;
146145 String src = null ;
147- String dst = null ;
146+ String srg = null ;
148147 String srcDesc = null ;
149148
150149 if (field ) {
151150 src = args [1 ];
152- dst = args [2 ];
151+ srg = args [2 ];
153152 } else {
154153 src = args [1 ];
155- dst = args [3 ];
154+ srg = args [3 ];
156155 srcDesc = args [2 ];
157156
158157 if (srcDesc == null || srcDesc .isEmpty ()) {
@@ -161,49 +160,54 @@ private void readSrg(BufferedReader r) throws IOException {
161160 }
162161
163162 int srcSep = src .lastIndexOf ('/' );
164- int dstSep = dst .lastIndexOf ('/' );
163+ int dstSep = srg .lastIndexOf ('/' );
165164
166165 if (src == null || src .isEmpty () || srcSep <= 0 ) {
167166 throw new IOException ("invalid src name for " + (field ? "field" : "method" ) + " mapping on line " + lineNumber );
168167 }
169- if (dst == null || dst .isEmpty () || dstSep <= 0 ) {
170- throw new IOException ("invalid dst name for " + (field ? "field" : "method" ) + " mapping on line " + lineNumber );
168+ if (srg == null || srg .isEmpty () || dstSep <= 0 ) {
169+ throw new IOException ("invalid srg name for " + (field ? "field" : "method" ) + " mapping on line " + lineNumber );
171170 }
172171
173172 srcCls = src .substring (0 , srcSep );
174- dstCls = dst .substring (0 , dstSep );
173+ srgCls = srg .substring (0 , dstSep );
175174 src = src .substring (srcSep + 1 );
176- dst = dst .substring (dstSep + 1 );
175+ srg = srg .substring (dstSep + 1 );
177176
178177 if (!srcCls .equals (cls )) {
179178 cls = srcCls ;
180179 visitCls = mappings .visitClass (srcCls );
181180
182181 if (visitCls ) {
183- mappings .visitDstName (MappedElementKind .CLASS , 0 , dstCls );
184- mappings .visitDstName (MappedElementKind .CLASS , 1 , dstCls );
182+ // for classes, srg == named
183+ mappings .visitDstName (MappedElementKind .CLASS , 0 , srgCls );
184+ mappings .visitDstName (MappedElementKind .CLASS , 1 , srgCls );
185185 visitCls = mappings .visitElementContent (MappedElementKind .CLASS );
186186 }
187187 }
188188
189189 if (visitCls ) {
190- if (field ? mappings .visitField (src , null ) : mappings .visitMethod (src , srcDesc )) {
190+ ElementMapping mapping = field
191+ ? mappings .getField (srcCls , src , null )
192+ : mappings .getMethod (srcCls , src , srcDesc );
193+
194+ if (mapping != null && field ? mappings .visitField (src , null ) : mappings .visitMethod (src , srcDesc )) {
191195 MappedElementKind kind = field ? MappedElementKind .FIELD : MappedElementKind .METHOD ;
192- boolean obf = field ? dst .startsWith ("field_" ) : dst .startsWith ("func_" );
196+ boolean obf = field ? srg .startsWith ("field_" ) : srg .startsWith ("func_" );
193197
194- mappings .visitDstName (kind , 0 , dst );
198+ mappings .visitDstName (kind , 0 , srg );
195199 if (!obf ) {
196- mappings .visitDstName (kind , 1 , dst );
200+ mappings .visitDstName (kind , 1 , srg );
197201 }
198202 mappings .visitElementContent (kind );
199203
200204 if (field ) {
201- fieldClasses .computeIfAbsent (dst , key -> new HashSet <>()).add (cls );
205+ fieldClasses .computeIfAbsent (srg , key -> new HashSet <>()).add (srgCls );
202206 } else {
203- methodClasses .computeIfAbsent (dst , key -> new HashSet <>()).add (cls );
207+ methodClasses .computeIfAbsent (srg , key -> new HashSet <>()).add (srgCls );
204208
205- if (dst .indexOf ('_' ) > 0 ) {
206- methods .put (dst .split ("[_]" )[1 ], dst );
209+ if (srg .indexOf ('_' ) > 0 ) {
210+ methods .put (srg .split ("[_]" )[1 ], srg );
207211 } else {
208212 // not obfuscated probably
209213 }
@@ -260,27 +264,18 @@ private void readFields(BufferedReader r) throws IOException {
260264 throw new IOException ("invalid dst name for field mapping on line " + lineNumber );
261265 }
262266
263- Collection <String > clss = fieldClasses .get (srg );
267+ Collection <String > srgClss = fieldClasses .get (srg );
264268
265- if (clss .isEmpty ()) {
269+ if (srgClss .isEmpty ()) {
266270 throw new IOException ("unknown field mapping on line " + lineNumber );
267271 }
268272
269- for (String clsName : clss ) {
270- ClassMapping cm = mappings .getClass (clsName );
271- String clsSrg = cm .getName (SRG_NAMESPACE );
272-
273- if (mappings .visitClass (clsSrg ) && mappings .visitElementContent (MappedElementKind .CLASS )) {
274- FieldMapping fm = cm .getField (srg , null , 0 );
275-
276- if (fm == null ) {
277- throw new IOException ("field " + srg + " went missing!" );
278- } else {
279- mappings .visitField (srg , null );
280- mappings .visitDstName (MappedElementKind .FIELD , 0 , dst );
281- if (jav != null && !jav .isEmpty ()) {
282- mappings .visitComment (MappedElementKind .FIELD , jav );
283- }
273+ for (String srgCls : srgClss ) {
274+ if (mappings .visitClass (srgCls ) && mappings .visitElementContent (MappedElementKind .CLASS )) {
275+ mappings .visitField (srg , null );
276+ mappings .visitDstName (MappedElementKind .FIELD , 0 , dst );
277+ if (jav != null && !jav .isEmpty ()) {
278+ mappings .visitComment (MappedElementKind .FIELD , jav );
284279 }
285280 }
286281 }
@@ -331,27 +326,18 @@ private void readMethods(BufferedReader r) throws IOException {
331326 throw new IOException ("invalid dst name for method mapping on line " + lineNumber );
332327 }
333328
334- Collection <String > clss = methodClasses .get (srg );
329+ Collection <String > srgClss = methodClasses .get (srg );
335330
336- if (clss .isEmpty ()) {
331+ if (srgClss .isEmpty ()) {
337332 throw new IOException ("unknown method mapping on line " + lineNumber );
338333 }
339334
340- for (String clsName : clss ) {
341- ClassMapping cm = mappings .getClass (clsName );
342- String clsSrg = cm .getName (SRG_NAMESPACE );
343-
344- if (mappings .visitClass (clsSrg ) && mappings .visitElementContent (MappedElementKind .CLASS )) {
345- MethodMapping mm = cm .getMethod (srg , null , 0 );
346-
347- if (mm == null ) {
348- throw new IOException ("method " + srg + " went missing!" );
349- } else {
350- mappings .visitMethod (srg , null );
351- mappings .visitDstName (MappedElementKind .METHOD , 0 , dst );
352- if (jav != null && !jav .isEmpty ()) {
353- mappings .visitComment (MappedElementKind .METHOD , jav );
354- }
335+ for (String srgCls : srgClss ) {
336+ if (mappings .visitClass (srgCls ) && mappings .visitElementContent (MappedElementKind .CLASS )) {
337+ mappings .visitMethod (srg , null );
338+ mappings .visitDstName (MappedElementKind .METHOD , 0 , dst );
339+ if (jav != null && !jav .isEmpty ()) {
340+ mappings .visitComment (MappedElementKind .METHOD , jav );
355341 }
356342 }
357343 }
@@ -416,27 +402,18 @@ private void readParams(BufferedReader r) throws IOException {
416402 continue ;
417403 }
418404
419- String mtdName = methods .get (methodId );
420- Collection <String > clss = methodClasses .get (mtdName );
405+ String srgMtd = methods .get (methodId );
406+ Collection <String > srgClss = methodClasses .get (srgMtd );
421407
422- if (clss .isEmpty ()) {
408+ if (srgClss .isEmpty ()) {
423409 throw new IOException ("unknown parameter mapping on line " + lineNumber );
424410 }
425411
426- for (String clsName : clss ) {
427- ClassMapping cm = mappings .getClass (clsName );
428- String clsSrg = cm .getName (SRG_NAMESPACE );
429-
430- if (mappings .visitClass (clsSrg ) && mappings .visitElementContent (MappedElementKind .CLASS )) {
431- MethodMapping mm = cm .getMethod (mtdName , null , 0 );
432-
433- if (mm == null ) {
434- throw new IOException ("method " + srg + " went missing!" );
435- } else {
436- if (mappings .visitMethod (mtdName , null ) && mappings .visitElementContent (MappedElementKind .METHOD )) {
437- mappings .visitMethodArg (-1 , idx , null );
438- mappings .visitDstName (MappedElementKind .METHOD_ARG , 0 , dst );
439- }
412+ for (String srgCls : srgClss ) {
413+ if (mappings .visitClass (srgCls ) && mappings .visitElementContent (MappedElementKind .CLASS )) {
414+ if (mappings .visitMethod (srgMtd , null ) && mappings .visitElementContent (MappedElementKind .METHOD )) {
415+ mappings .visitMethodArg (-1 , idx , null );
416+ mappings .visitDstName (MappedElementKind .METHOD_ARG , 0 , dst );
440417 }
441418 }
442419 }
0 commit comments