@@ -389,65 +389,110 @@ private Method[] groupMethodsByName(Method[] methods)
389389
390390 return result .values ().toArray (new Method [result .size ()]);
391391 }
392+
393+ private String getMethodSignature (Method m )
394+ {
395+ String sig = m .toGenericString ();
396+
397+ int nameIdx = sig .indexOf ("(" );
398+ int endSigIdx = sig .indexOf (")" ) + 1 ;
399+
400+ return m .getName () + sig .substring (nameIdx , endSigIdx );
401+ }
392402
393403 private Method [] getSupportedMethods (Class <?> clazz , HashSet <String > methodOverrides )
394404 {
395405 ArrayList <Method > result = new ArrayList <Method >();
396- HashMap <String , Method > finalMethods = new HashMap <String , Method >();
397- ArrayList <Class <?>> implementedInterfaces = new ArrayList <Class <?>>();
398- while (clazz != null )
406+
407+ if (clazz .isInterface ())
399408 {
400- Method [] methods = clazz .getDeclaredMethods ();
401-
402- ArrayList <Method > methodz = new ArrayList <Method >();
403-
404- for (int i = 0 ; i < methods .length ; i ++)
409+ Set <String > objectMethods = new HashSet <String >();
410+ for (Method objMethod : java .lang .Object .class .getDeclaredMethods ())
405411 {
406- Method candidateMethod = methods [i ];
407- if (methodOverrides != null && !methodOverrides .contains (candidateMethod .getName ()))
412+ if (!Modifier .isStatic (objMethod .getModifiers ()))
408413 {
409- continue ;
414+ String sig = getMethodSignature (objMethod );
415+ objectMethods .add (sig );
410416 }
411-
412- methodz .add (methods [i ]);
413417 }
414-
415-
416- Class <?>[] interfaces = clazz .getInterfaces ();
417- for (int i = 0 ; i < interfaces .length ; i ++)
418+ Set <Method > notImplementedObjectMethods = new HashSet <Method >();
419+ Method [] ifaceMethods = clazz .getDeclaredMethods ();
420+ for (Method ifaceMethod : ifaceMethods )
418421 {
419- implementedInterfaces .add (interfaces [i ]);
422+ if (!Modifier .isStatic (ifaceMethod .getModifiers ()))
423+ {
424+ String sig = getMethodSignature (ifaceMethod );
425+ if (objectMethods .contains (sig ) && !methodOverrides .contains (ifaceMethod .getName ()))
426+ {
427+ notImplementedObjectMethods .add (ifaceMethod );
428+ }
429+ }
420430 }
421-
422- for (int i = 0 ; i < methodz .size (); i ++)
431+ for (Method ifaceMethod : ifaceMethods )
423432 {
424- Method method = methodz .get (i );
425-
426- if (isMethodSupported (method , finalMethods ))
433+ if (!notImplementedObjectMethods .contains (ifaceMethod ))
427434 {
428- result .add (method );
435+ result .add (ifaceMethod );
429436 }
430437 }
431-
432- clazz = clazz .getSuperclass ();
433438 }
434-
435- for (int i = 0 ; i < implementedInterfaces .size (); i ++)
439+ else
436440 {
437- Class <?> implementedInterface = implementedInterfaces . get ( i );
438- Method [] interfaceMethods = implementedInterface . getMethods ();
439- for ( int j = 0 ; j < interfaceMethods . length ; j ++ )
441+ HashMap < String , Method > finalMethods = new HashMap < String , Method >( );
442+ ArrayList < Class <?>> implementedInterfaces = new ArrayList < Class <?>> ();
443+ while ( clazz != null )
440444 {
441- Method method = interfaceMethods [j ];
445+ Method [] methods = clazz .getDeclaredMethods ();
446+
447+ ArrayList <Method > methodz = new ArrayList <Method >();
448+
449+ for (int i = 0 ; i < methods .length ; i ++)
450+ {
451+ Method candidateMethod = methods [i ];
452+ if (methodOverrides != null && !methodOverrides .contains (candidateMethod .getName ()))
453+ {
454+ continue ;
455+ }
456+
457+ methodz .add (methods [i ]);
458+ }
459+
460+ Class <?>[] interfaces = clazz .getInterfaces ();
461+ for (int i = 0 ; i < interfaces .length ; i ++)
462+ {
463+ implementedInterfaces .add (interfaces [i ]);
464+ }
442465
443- if ( methodOverrides != null && ! methodOverrides . contains ( method . getName ()) )
466+ for ( int i = 0 ; i < methodz . size (); i ++ )
444467 {
445- continue ;
468+ Method method = methodz .get (i );
469+
470+ if (isMethodSupported (method , finalMethods ))
471+ {
472+ result .add (method );
473+ }
446474 }
447475
448- if (!isMethodMarkedAsFinalInClassHierarchy (method , finalMethods ))
476+ clazz = clazz .getSuperclass ();
477+ }
478+
479+ for (int i = 0 ; i < implementedInterfaces .size (); i ++)
480+ {
481+ Class <?> implementedInterface = implementedInterfaces .get (i );
482+ Method [] interfaceMethods = implementedInterface .getMethods ();
483+ for (int j = 0 ; j < interfaceMethods .length ; j ++)
449484 {
450- result .add (method );
485+ Method method = interfaceMethods [j ];
486+
487+ if (methodOverrides != null && !methodOverrides .contains (method .getName ()))
488+ {
489+ continue ;
490+ }
491+
492+ if (!isMethodMarkedAsFinalInClassHierarchy (method , finalMethods ))
493+ {
494+ result .add (method );
495+ }
451496 }
452497 }
453498 }
@@ -1158,4 +1203,4 @@ private int getDexModifiers(int modifiers)
11581203
11591204 return org .ow2 .asmdex .Opcodes .ACC_PROTECTED ;
11601205 }
1161- }
1206+ }
0 commit comments