33import com .google .common .collect .ArrayListMultimap ;
44import com .google .common .collect .Multimap ;
55import com .google .common .collect .Multimaps ;
6+ import me .coley .recaf .util .CollectionUtil ;
67
7- import java .util .AbstractMap ;
8- import java .util .Collection ;
9- import java .util .HashMap ;
10- import java .util .Map ;
11- import java .util .Objects ;
8+ import java .util .*;
129import java .util .stream .Collectors ;
1310
1411/**
@@ -86,10 +83,21 @@ public static void applyMappingToExisting(Map<String, String> existing, Map<Stri
8683 + key + " gave more than 1 result: " + String .join (", " + classPreimages ));
8784 }
8885 // if we have a preimage for the class, apply the mapping to that preimage class name
89- if (classPreimages .size () == 1 ) {
90- String classPreimage = classPreimages .iterator ().next ();
91- String memberName = key .substring (key .indexOf ('.' ) + 1 );
92- key = classPreimage + "." + memberName ;
86+ // otherwise use given name
87+ String targetClassName = classPreimages .isEmpty () ? className : classPreimages .iterator ().next ();
88+ String memberInfo = key .substring (key .indexOf ('.' ) + 1 );
89+ if (memberInfo .contains (" " )) {
90+ int x = memberInfo .indexOf (" " );
91+ String fieldName = memberInfo .substring (0 , x );
92+ String fieldDesc = memberInfo .substring (x + 1 );
93+ key = targetClassName + "." + fieldName + " " + mapDesc (existing , fieldDesc );
94+ } else if (memberInfo .contains ("(" )) {
95+ int x = memberInfo .indexOf ("(" );
96+ String methodName = memberInfo .substring (0 , x );
97+ String methodDesc = memberInfo .substring (x );
98+ key = targetClassName + "." + methodName + mapDesc (existing , methodDesc );
99+ } else {
100+ key = targetClassName + "." + memberInfo ;
93101 }
94102 }
95103
@@ -109,6 +117,22 @@ public static void applyMappingToExisting(Map<String, String> existing, Map<Stri
109117 existing .putAll (preimageAwareUpdates );
110118 }
111119
120+ /**
121+ * @param existing
122+ * Current aggregate mappings.
123+ * @param desc
124+ * Descriptor to map.
125+ *
126+ * @return Mapped descriptor.
127+ */
128+ private static String mapDesc (Map <String , String > existing , String desc ) {
129+ SimpleRecordingRemapper remapper = new SimpleRecordingRemapper (
130+ CollectionUtil .invert (existing ), false , false , false , null );
131+ return desc .charAt (0 ) == '(' ?
132+ remapper .mapMethodDesc (desc ) :
133+ remapper .mapDesc (desc );
134+ }
135+
112136 /**
113137 * Transforms a given mapping in ASM format (See
114138 * {@link org.objectweb.asm.commons.SimpleRemapper#SimpleRemapper(Map)}) to a mapping where the values are in the
0 commit comments