Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -382,7 +383,9 @@ public static Method getMatchingMethod(final Class<?> cls, final String methodNa
.filter(method -> method.getName().equals(methodName))
.collect(Collectors.toList());

getAllSuperclassesAndInterfaces(cls).stream()
final List<Class<?>> allSuperclassesAndInterfaces = getAllSuperclassesAndInterfaces(cls);
Collections.reverse(allSuperclassesAndInterfaces);
allSuperclassesAndInterfaces.stream()
.map(Class::getDeclaredMethods)
.flatMap(Stream::of)
.filter(method -> method.getName().equals(methodName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class MethodUtilsTest extends AbstractLangTest {
protected abstract static class AbstractGetMatchingMethod implements InterfaceGetMatchingMethod {
public abstract void testMethod5(Exception exception);
}
protected abstract static class AbstractGetMatchingMethod2 implements InterfaceGetMatchingMethod {
@Override
public void testMethod6() { }
}

interface ChildInterface {
}
Expand Down Expand Up @@ -112,6 +116,12 @@ public void testMethod5(final Exception exception) {
}
}

private static final class ConcreteGetMatchingMethod2 extends AbstractGetMatchingMethod2 { }
private static final class ConcreteGetMatchingMethod22 extends AbstractGetMatchingMethod2 {
@Override
public void testMethod6() { }
}

public static class GrandParentObject {
}
public static class InheritanceBean {
Expand Down Expand Up @@ -670,6 +680,17 @@ void testGetMatchingMethod() throws NoSuchMethodException {

assertNullPointerException(
() -> MethodUtils.getMatchingMethod(null, "testMethod5", RuntimeException.class));

{
final Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod2.class, "testMethod6");
assertNotNull(testMethod6);
assertEquals(AbstractGetMatchingMethod2.class, testMethod6.getDeclaringClass());
}
{
final Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod22.class, "testMethod6");
assertNotNull(testMethod6);
assertEquals(ConcreteGetMatchingMethod22.class, testMethod6.getDeclaringClass());
}
}

@Test
Expand Down