2020import java .util .ArrayList ;
2121import java .util .Arrays ;
2222import java .util .LinkedHashMap ;
23- import java .util .LinkedHashSet ;
2423import java .util .List ;
2524import java .util .Map ;
26- import java .util .Set ;
2725import java .util .concurrent .atomic .AtomicBoolean ;
2826import java .util .concurrent .atomic .AtomicReference ;
2927import java .util .stream .Collectors ;
@@ -73,7 +71,6 @@ public static MappingInheritance read(Path path) throws IOException {
7371 Map <String , MethodInheritance > methodsHolder = new LinkedHashMap <>();
7472 Map <String , FieldInheritance > fieldsHolder = new LinkedHashMap <>();
7573 AtomicBoolean enabled = new AtomicBoolean (true );
76- Set <String > bridges = new LinkedHashSet <>();
7774 var reader = new ClassReader (zis );
7875 var visitor = new ClassVisitor (Opcodes .ASM9 ) {
7976 @ Override
@@ -100,28 +97,15 @@ public FieldVisitor visitField(int access, String name, String descriptor, Strin
10097 @ Override
10198 public MethodVisitor visitMethod (int access , String name , String descriptor , String signature , String [] exceptions ) {
10299 if (enabled .getPlain ()) {
103- boolean isBridge = (access & Opcodes .ACC_BRIDGE ) != 0 ;
104- if (isBridge ) {
105- bridges .add (name +descriptor );
106- }
100+ // We don't check for bridge methods here -- no reliable way to detect them without parsing the code
107101 var heritable = !Modifier .isPrivate (access ) && !Modifier .isStatic (access );
108- methodsHolder .put (name +descriptor , new MethodInheritance (name , descriptor , null , null , heritable ));
102+ methodsHolder .put (name +descriptor , new MethodInheritance (name , descriptor , null , heritable ));
109103 }
110104 return super .visitMethod (access , name , descriptor , signature , exceptions );
111105 }
112106 };
113107 reader .accept (visitor , ClassReader .SKIP_DEBUG | ClassReader .SKIP_CODE | ClassReader .SKIP_FRAMES );
114108 if (enabled .getPlain ()) {
115- // Is this the _best_ heuristic? Eh. But it works, in theory
116- for (var bridge : bridges ) {
117- var bridgeMethod = methodsHolder .get (bridge );
118- var name = bridgeMethod .name ;
119- var eligible = methodsHolder .values ().stream ().filter (m -> !bridges .contains (m .name + m .descriptor ) && m .name .equals (name )).toList ();
120- if (eligible .size () == 1 ) {
121- var method = eligible .getFirst ();
122- methodsHolder .put (bridge , new MethodInheritance (bridgeMethod .name , bridgeMethod .descriptor , null , method .descriptor , method .heritable ));
123- }
124- }
125109 map .put (nameHolder .getPlain (), new ClassInheritance (nameHolder .getPlain (), parentHolder .getPlain (), interfacesHolder , methodsHolder , fieldsHolder ));
126110 }
127111 }
@@ -191,15 +175,15 @@ private FieldInheritance remap(MappingTree tree, int namespace, ClassInheritance
191175 }
192176
193177 private record MethodInheritance (String name , String descriptor , @ Nullable String from ,
194- @ Nullable String bridgeDescriptor , boolean heritable ) {
178+ boolean heritable ) {
195179
196180 private MethodInheritance withParents (ClassInheritance classInheritance , MappingInheritance mappingInheritance ) {
197181 if (from != null || !heritable ) {
198182 return this ;
199183 }
200184 String found = findMethod (mappingInheritance , classInheritance .name , name , descriptor );
201185 if (found != null && !found .equals (classInheritance .name )) {
202- return new MethodInheritance (name , descriptor , found , bridgeDescriptor , true );
186+ return new MethodInheritance (name , descriptor , found , true );
203187 }
204188 return this ;
205189 }
@@ -231,23 +215,13 @@ private MethodInheritance remap(MappingTree tree, int namespace, ClassInheritanc
231215 if (newFrom != null ) {
232216 newFrom = tree .mapClassName (from , namespace );
233217 }
234- String newBridgeDescriptor = bridgeDescriptor ;
235- if (newBridgeDescriptor != null ) {
236- newBridgeDescriptor = tree .mapDesc (bridgeDescriptor , namespace );
237- }
238218 String newName = null ;
239219 var classMapping = tree .getClass (clazz .name );
240220 if (classMapping != null ) {
241221 var methodMapping = classMapping .getMethod (name , descriptor );
242222 if (methodMapping != null ) {
243223 newName = methodMapping .getDstName (namespace );
244224 }
245- if (newName == null && bridgeDescriptor != null ) {
246- methodMapping = classMapping .getMethod (name , bridgeDescriptor );
247- if (methodMapping != null ) {
248- newName = methodMapping .getDstName (namespace );
249- }
250- }
251225 }
252226 if (newName == null ) {
253227 var sourceClassMapping = tree .getClass (from );
@@ -261,11 +235,11 @@ private MethodInheritance remap(MappingTree tree, int namespace, ClassInheritanc
261235 if (newName == null ) {
262236 newName = name ;
263237 }
264- return new MethodInheritance (newName , newDescriptor , newFrom , newBridgeDescriptor , heritable );
238+ return new MethodInheritance (newName , newDescriptor , newFrom , heritable );
265239 }
266240
267241 public void fill (ClassInheritance classInheritance , MappingTreeView input , FlatMappingVisitor output ) throws IOException {
268- if (from == null && bridgeDescriptor == null ) {
242+ if (from == null ) {
269243 return ;
270244 }
271245 var thisClass = input .getClass (classInheritance .name );
@@ -280,27 +254,15 @@ public void fill(ClassInheritance classInheritance, MappingTreeView input, FlatM
280254 }
281255 }
282256 }
283- if (from != null ) {
284- var fromClass = input .getClass (from );
285- if (fromClass != null ) {
286- var fromMethod = fromClass .getMethod (name , descriptor );
287- if (fromMethod != null && IntStream .range (0 , input .getMaxNamespaceId ()).anyMatch (i -> fromMethod .getDstName (i ) != null )) {
288- output .visitMethod (classInheritance .name (), name , descriptor , dstNames (input , fromMethod ));
289- if (inheritArgs ) {
290- for (var arg : fromMethod .getArgs ()) {
291- output .visitMethodArg (classInheritance .name (), name , descriptor , arg .getArgPosition (), arg .getLvIndex (), arg .getSrcName (), dstNames (input , arg ));
292- }
257+ var fromClass = input .getClass (from );
258+ if (fromClass != null ) {
259+ var fromMethod = fromClass .getMethod (name , descriptor );
260+ if (fromMethod != null && IntStream .range (0 , input .getMaxNamespaceId ()).anyMatch (i -> fromMethod .getDstName (i ) != null )) {
261+ output .visitMethod (classInheritance .name (), name , descriptor , dstNames (input , fromMethod ));
262+ if (inheritArgs ) {
263+ for (var arg : fromMethod .getArgs ()) {
264+ output .visitMethodArg (classInheritance .name (), name , descriptor , arg .getArgPosition (), arg .getLvIndex (), arg .getSrcName (), dstNames (input , arg ));
293265 }
294- return ;
295- }
296- }
297- }
298- // May not be necessary with intermediary -- but hey, let's be safe if we can be.
299- if (thisClass != null ) {
300- if (bridgeDescriptor != null ) {
301- var bridgeMethod = thisClass .getMethod (name , bridgeDescriptor );
302- if (bridgeMethod != null && IntStream .range (0 , input .getMaxNamespaceId ()).anyMatch (i -> bridgeMethod .getDstName (i ) != null )) {
303- output .visitMethod (classInheritance .name (), name , descriptor , dstNames (input , bridgeMethod ));
304266 }
305267 }
306268 }
0 commit comments