mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
fix: 修复ClassUtil.doGetMethods最后一个参数为true时,不会提前结束遍历接口
This commit is contained in:
parent
86f4358ebf
commit
9cca7e69cc
@ -288,43 +288,42 @@ public class ClassUtil {
|
|||||||
|
|
||||||
|
|
||||||
private static void doGetMethods(Class<?> clazz, List<Method> methods, Predicate<Method> predicate, boolean firstOnly) {
|
private static void doGetMethods(Class<?> clazz, List<Method> methods, Predicate<Method> predicate, boolean firstOnly) {
|
||||||
if (clazz == null || clazz == Object.class) {
|
applyAllClass(clazz, currentClass -> {
|
||||||
return;
|
Method[] declaredMethods = clazz.getDeclaredMethods();
|
||||||
}
|
if (clazz.isInterface()) {
|
||||||
|
for (Method method : declaredMethods) {
|
||||||
Method[] declaredMethods = clazz.getDeclaredMethods();
|
// 接口类只需要获取 default 方法
|
||||||
if (clazz.isInterface()) {
|
if (method.isDefault() && (predicate == null || predicate.test(method))) {
|
||||||
for (Method method : declaredMethods) {
|
methods.add(method);
|
||||||
// 接口类只需要获取 default 方法
|
if (firstOnly) {
|
||||||
if (method.isDefault() && (predicate == null || predicate.test(method))) {
|
break;
|
||||||
methods.add(method);
|
}
|
||||||
if (firstOnly) {
|
}
|
||||||
break;
|
}
|
||||||
|
} else {
|
||||||
|
for (Method method : declaredMethods) {
|
||||||
|
if (predicate == null || predicate.test(method)) {
|
||||||
|
methods.add(method);
|
||||||
|
if (firstOnly) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
// 只获取第一个并且集合不为空就结束遍历
|
||||||
for (Method method : declaredMethods) {
|
if (firstOnly && !methods.isEmpty()) {
|
||||||
if (predicate == null || predicate.test(method)) {
|
return false;
|
||||||
methods.add(method);
|
}
|
||||||
if (firstOnly) {
|
Class<?>[] interfaces = clazz.getInterfaces();
|
||||||
break;
|
for (Class<?> anInterface : interfaces) {
|
||||||
}
|
doGetMethods(anInterface, methods, predicate, firstOnly);
|
||||||
|
// 只获取第一个并且集合不为空就结束遍历
|
||||||
|
if (firstOnly && !methods.isEmpty()){
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
if (firstOnly && !methods.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?>[] interfaces = clazz.getInterfaces();
|
|
||||||
for (Class<?> anInterface : interfaces) {
|
|
||||||
doGetMethods(anInterface, methods, predicate, firstOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
doGetMethods(clazz.getSuperclass(), methods, predicate, firstOnly);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> Class<T> getJdkProxySuperClass(Class<T> clazz) {
|
private static <T> Class<T> getJdkProxySuperClass(Class<T> clazz) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user