diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMatcher.java b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMatcher.java index 54e3b09d2..be9057eeb 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMatcher.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMatcher.java @@ -17,24 +17,15 @@ import java.util.function.Predicate; @FunctionalInterface public interface MethodMatcher extends MethodMetadataLookup, Predicate { - /** - * 检查方法是否匹配 - * - * @param method 方法 - * @return 结果 - */ - boolean test(Method method); - /** * 返回一个组合的条件,当且仅当所有条件都符合时,才返回{@code true}, - * 等同于{@link Predicate#and(Predicate)}. * * @param other 其他条件 * @return 条件 * @throws NullPointerException 当other为null时抛出 */ @Override - default MethodMatcher and(Predicate other) { + default MethodMatcher and(final Predicate other) { Objects.requireNonNull(other); return t -> test(t) && other.test(t); } @@ -57,7 +48,7 @@ public interface MethodMatcher extends MethodMetadataLookup, Predicate< * @throws NullPointerException 当other为null时抛出 */ @Override - default MethodMatcher or(Predicate other) { + default MethodMatcher or(final Predicate other) { Objects.requireNonNull(other); return t -> test(t) || other.test(t); } @@ -69,7 +60,7 @@ public interface MethodMatcher extends MethodMetadataLookup, Predicate< * @return 结果 */ @Override - default Boolean inspect(Method method) { + default Boolean inspect(final Method method) { return test(method) ? Boolean.TRUE : null; } } diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMatcherUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMatcherUtil.java index 555163ed3..1542d8963 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMatcherUtil.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMatcherUtil.java @@ -318,7 +318,7 @@ public class MethodMatcherUtil { * @return 方法匹配器 */ public static MethodMatcher forNameIgnoreCaseAndStrictParameterTypes( - final String methodName, Class... parameterTypes) { + final String methodName, final Class... parameterTypes) { Objects.requireNonNull(methodName); Objects.requireNonNull(parameterTypes); return allMatch(forNameIgnoreCase(methodName), forStrictParameterTypes(parameterTypes)); @@ -352,8 +352,8 @@ public class MethodMatcherUtil { *
  • 参数类型是否匹配,允许参数类型为方法参数类型的子类,若参数类型为{@code null}则表示匹配无参数的方法;
  • * * - * @param methodName 方法名 - * @param returnType 返回值类型,若为{@code null}则表示匹配无返回值的方法 + * @param methodName 方法名 + * @param returnType 返回值类型,若为{@code null}则表示匹配无返回值的方法 * @param parameterTypes 参数类型,若为{@code null}则表示匹配无参数的方法 * @return 方法匹配器 */ @@ -375,8 +375,8 @@ public class MethodMatcherUtil { *
  • 参数类型是否匹配,要求参数类型与方法参数类型完全一致,若参数类型为{@code null}则表示匹配无参数的方法;
  • * * - * @param methodName 方法名 - * @param returnType 返回值类型,若为{@code null}则表示匹配无返回值的方法 + * @param methodName 方法名 + * @param returnType 返回值类型,若为{@code null}则表示匹配无返回值的方法 * @param parameterTypes 参数类型,若为{@code null}则表示匹配无参数的方法 * @return 方法匹配器 */ @@ -474,7 +474,7 @@ public class MethodMatcherUtil { * @param count 参数个数 * @return 方法匹配器 */ - public static MethodMatcher forParameterCount(int count) { + public static MethodMatcher forParameterCount(final int count) { return method -> method.getParameterCount() == count; } @@ -568,7 +568,7 @@ public class MethodMatcherUtil { @NotNull private static MethodMatcher mostSpecificStrictParameterTypesMatcher( - Class[] parameterTypes, BiPredicate, Class> typeMatcher) { + final Class[] parameterTypes, final BiPredicate, Class> typeMatcher) { Objects.requireNonNull(parameterTypes); // 若参数为空,则表示匹配无参数方法 if (parameterTypes.length == 0) { diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMetadataLookup.java b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMetadataLookup.java index 21c7b1d10..fc536e3a7 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMetadataLookup.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodMetadataLookup.java @@ -5,6 +5,7 @@ import java.lang.reflect.Method; /** * 方法的元数据查找器,参照 spring 的 {@code MethodIntrospector.MetadataLookup},用于从方法上获得特定的元数据。 * + * @param 返回类型 * @author huangchengxing * @see MethodMatcher * @see MethodMatcherUtil diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodScanner.java b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodScanner.java index 8c35c8d0c..f46b662f8 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodScanner.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodScanner.java @@ -63,8 +63,8 @@ import java.util.function.Predicate; * @since 6.0.0 */ public class MethodScanner { - /** - * TODO 替换{@link MethodUtil}中的部分方法实现 + /* + TODO 替换{@link MethodUtil}中的部分方法实现 */ /** @@ -90,7 +90,7 @@ public class MethodScanner { * @param type 类 * @return 当前类及父类的所有公共方法 */ - public static Method[] getMethods(Class type) { + public static Method[] getMethods(final Class type) { if (Objects.isNull(type)) { return EMPTY_METHODS; } @@ -103,7 +103,7 @@ public class MethodScanner { * @param type 类 * @return 当前类及父类的所有公共方法 */ - public static Method[] getDeclaredMethods(Class type) { + public static Method[] getDeclaredMethods(final Class type) { if (Objects.isNull(type)) { return EMPTY_METHODS; } @@ -124,11 +124,11 @@ public class MethodScanner { * @return 当前类及父类的所有公共方法 * @see ClassUtil#traverseTypeHierarchyWhile(Class, Predicate) */ - public static Method[] getAllMethods(Class type) { + public static Method[] getAllMethods(final Class type) { if (Objects.isNull(type)) { return EMPTY_METHODS; } - List methods = new ArrayList<>(); + final List methods = new ArrayList<>(); ClassUtil.traverseTypeHierarchyWhile(type, t -> { methods.addAll(Arrays.asList(getDeclaredMethods(t))); return true; @@ -154,14 +154,15 @@ public class MethodScanner { * @param methods 方法列表 * @param lookup 查找器 * @return 方法与对应的元数据集合 + * @param 结果类型 */ - public static Map findWithMetadataFromSpecificMethods(Method[] methods, MethodMetadataLookup lookup) { + public static Map findWithMetadataFromSpecificMethods(final Method[] methods, final MethodMetadataLookup lookup) { if (ArrayUtil.isEmpty(methods)) { return Collections.emptyMap(); } - Map results = new LinkedHashMap<>(); - for (Method method : methods) { - T result = lookup.inspect(method); + final Map results = new LinkedHashMap<>(); + for (final Method method : methods) { + final T result = lookup.inspect(method); if (Objects.nonNull(result)) { results.put(method, result); } @@ -176,7 +177,7 @@ public class MethodScanner { * @param lookup 查找器 * @return 方法集合 */ - public static Set findFromSpecificMethods(Method[] methods, MethodMetadataLookup lookup) { + public static Set findFromSpecificMethods(final Method[] methods, final MethodMetadataLookup lookup) { return findWithMetadataFromSpecificMethods(methods, lookup).keySet(); } @@ -186,10 +187,11 @@ public class MethodScanner { * @param methods 方法列表 * @param lookup 查找器 * @return 方法与对应的元数据 + * @param 值类型 */ - public static Map.Entry getWithMetadataFromSpecificMethods(Method[] methods, MethodMetadataLookup lookup) { - for (Method method : methods) { - T result = lookup.inspect(method); + public static Map.Entry getWithMetadataFromSpecificMethods(final Method[] methods, final MethodMetadataLookup lookup) { + for (final Method method : methods) { + final T result = lookup.inspect(method); if (Objects.nonNull(result)) { return MapUtil.entry(method, result); } @@ -204,8 +206,8 @@ public class MethodScanner { * @param lookup 查找器 * @return 方法 */ - public static Method getFromSpecificMethods(Method[] methods, MethodMetadataLookup lookup) { - Map.Entry result = getWithMetadataFromSpecificMethods(methods, lookup); + public static Method getFromSpecificMethods(final Method[] methods, final MethodMetadataLookup lookup) { + final Map.Entry result = getWithMetadataFromSpecificMethods(methods, lookup); return Objects.isNull(result) ? null : result.getKey(); } @@ -219,8 +221,9 @@ public class MethodScanner { * @param type 类型 * @param lookup 查找器 * @return 方法与对应的元数据集合 + * @param 值类型 */ - public static Map findWithMetadataFromMethods(Class type, MethodMetadataLookup lookup) { + public static Map findWithMetadataFromMethods(final Class type, final MethodMetadataLookup lookup) { return findWithMetadataFromSpecificMethods(getMethods(type), lookup); } @@ -231,7 +234,7 @@ public class MethodScanner { * @param lookup 查找器 * @return 方法集合 */ - public static Set findFromMethods(Class type, MethodMetadataLookup lookup) { + public static Set findFromMethods(final Class type, final MethodMetadataLookup lookup) { return findFromSpecificMethods(getMethods(type), lookup); } @@ -241,8 +244,9 @@ public class MethodScanner { * @param type 类型 * @param lookup 查找器 * @return 方法及元数据,若无任何匹配的结果则返回{@code null} + * @param 值类型 */ - public static Map.Entry getWithMetadataFromMethods(Class type, MethodMetadataLookup lookup) { + public static Map.Entry getWithMetadataFromMethods(final Class type, final MethodMetadataLookup lookup) { return getWithMetadataFromSpecificMethods(getMethods(type), lookup); } @@ -253,7 +257,7 @@ public class MethodScanner { * @param lookup 查找器 * @return 方法,若无任何匹配的结果则返回{@code null} */ - public static Method getFromMethods(Class type, MethodMetadataLookup lookup) { + public static Method getFromMethods(final Class type, final MethodMetadataLookup lookup) { return getFromSpecificMethods(getMethods(type), lookup); } @@ -267,8 +271,9 @@ public class MethodScanner { * @param type 类型 * @param lookup 查找器 * @return 方法与对应的元数据集合 + * @param 值类型 */ - public static Map findWithMetadataFromDeclaredMethods(Class type, MethodMetadataLookup lookup) { + public static Map findWithMetadataFromDeclaredMethods(final Class type, final MethodMetadataLookup lookup) { return findWithMetadataFromSpecificMethods(getDeclaredMethods(type), lookup); } @@ -279,7 +284,7 @@ public class MethodScanner { * @param lookup 查找器 * @return 方法集合 */ - public static Set findFromDeclaredMethods(Class type, MethodMetadataLookup lookup) { + public static Set findFromDeclaredMethods(final Class type, final MethodMetadataLookup lookup) { return findFromSpecificMethods(getDeclaredMethods(type), lookup); } @@ -289,8 +294,9 @@ public class MethodScanner { * @param type 类型 * @param lookup 查找器 * @return 方法及元数据,若无任何匹配的结果则返回{@code null} + * @param 值类型 */ - public static Map.Entry getWithMetadataFromDeclaredMethods(Class type, MethodMetadataLookup lookup) { + public static Map.Entry getWithMetadataFromDeclaredMethods(final Class type, final MethodMetadataLookup lookup) { return getWithMetadataFromSpecificMethods(getDeclaredMethods(type), lookup); } @@ -301,7 +307,7 @@ public class MethodScanner { * @param lookup 查找器 * @return 方法,若无任何匹配的结果则返回{@code null} */ - public static Method getFromDeclaredMethods(Class type, MethodMetadataLookup lookup) { + public static Method getFromDeclaredMethods(final Class type, final MethodMetadataLookup lookup) { return getFromSpecificMethods(getDeclaredMethods(type), lookup); } @@ -316,8 +322,9 @@ public class MethodScanner { * @param type 类型 * @param lookup 查找器 * @return 方法与对应的元数据集合 + * @param 值类型 */ - public static Map findWithMetadataFromAllMethods(Class type, MethodMetadataLookup lookup) { + public static Map findWithMetadataFromAllMethods(final Class type, final MethodMetadataLookup lookup) { return findWithMetadataFromSpecificMethods(getAllMethods(type), lookup); } @@ -328,7 +335,7 @@ public class MethodScanner { * @param lookup 查找器 * @return 方法集合 */ - public static Set findFromAllMethods(Class type, MethodMetadataLookup lookup) { + public static Set findFromAllMethods(final Class type, final MethodMetadataLookup lookup) { return findFromSpecificMethods(getAllMethods(type), lookup); } @@ -338,14 +345,15 @@ public class MethodScanner { * @param type 类型 * @param lookup 查找器 * @return 方法及元数据,若无任何匹配的结果则返回{@code null} + * @param 值类型 */ - public static Map.Entry getWithMetadataFromAllMethods(Class type, MethodMetadataLookup lookup) { + public static Map.Entry getWithMetadataFromAllMethods(final Class type, final MethodMetadataLookup lookup) { if (Objects.isNull(type)) { return null; } - Mutable> result = new MutableObj<>(); + final Mutable> result = new MutableObj<>(); ClassUtil.traverseTypeHierarchyWhile(type, t -> { - Map.Entry target = getWithMetadataFromDeclaredMethods(t, lookup); + final Map.Entry target = getWithMetadataFromDeclaredMethods(t, lookup); if (Objects.nonNull(target)) { result.set(target); return false; @@ -362,8 +370,8 @@ public class MethodScanner { * @param lookup 查找器 * @return 方法,若无任何匹配的结果则返回{@code null} */ - public static Method getFromAllMethods(Class type, MethodMetadataLookup lookup) { - Map.Entry target = getWithMetadataFromAllMethods(type, lookup); + public static Method getFromAllMethods(final Class type, final MethodMetadataLookup lookup) { + final Map.Entry target = getWithMetadataFromAllMethods(type, lookup); return Objects.isNull(target) ? null : target.getKey(); }