@@ -432,7 +432,7 @@ public static void doWithMethods(Class<?> clazz, MethodCallback mc) throws Illeg
432
432
433
433
/**
434
434
* Perform the given callback operation on all matching methods of the given
435
- * class and superclasses.
435
+ * class and superclasses (or given interface and super-interfaces) .
436
436
* <p>The same named method occurring on subclass and superclass will appear
437
437
* twice, unless excluded by the specified {@link MethodFilter}.
438
438
* @param clazz class to start looking at
@@ -443,24 +443,27 @@ public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter
443
443
throws IllegalArgumentException {
444
444
445
445
// Keep backing up the inheritance hierarchy.
446
- Class <?> targetClass = clazz ;
447
- do {
448
- Method [] methods = targetClass .getDeclaredMethods ();
449
- for (Method method : methods ) {
450
- if (mf != null && !mf .matches (method )) {
451
- continue ;
452
- }
453
- try {
454
- mc .doWith (method );
455
- }
456
- catch (IllegalAccessException ex ) {
457
- throw new IllegalStateException ("Shouldn't be illegal to access method '" + method .getName ()
458
- + "': " + ex );
459
- }
446
+ Method [] methods = clazz .getDeclaredMethods ();
447
+ for (Method method : methods ) {
448
+ if (mf != null && !mf .matches (method )) {
449
+ continue ;
450
+ }
451
+ try {
452
+ mc .doWith (method );
453
+ }
454
+ catch (IllegalAccessException ex ) {
455
+ throw new IllegalStateException ("Shouldn't be illegal to access method '" + method .getName ()
456
+ + "': " + ex );
457
+ }
458
+ }
459
+ if (clazz .getSuperclass () != null ) {
460
+ doWithMethods (clazz .getSuperclass (), mc , mf );
461
+ }
462
+ else if (clazz .isInterface ()) {
463
+ for (Class <?> superIfc : clazz .getInterfaces ()) {
464
+ doWithMethods (superIfc , mc , mf );
460
465
}
461
- targetClass = targetClass .getSuperclass ();
462
466
}
463
- while (targetClass != null );
464
467
}
465
468
466
469
/**
0 commit comments