| 程序包 | 说明 |
|---|---|
| org.dromara.hutool.core.reflect.method |
提供方法相关封装
|
| 限定符和类型 | 方法和说明 |
|---|---|
static MethodMatcher |
MethodMatcherUtil.allMatch(MethodMatcher... matchers)
用于组合多个方法匹配器的方法匹配器,当所有方法匹配器均匹配成功时才认为方法匹配。
|
static MethodMatcher |
MethodMatcherUtil.alwaysMatch()
创建一个匹配任何方法的方法匹配器
|
default MethodMatcher |
MethodMatcher.and(Predicate<? super Method> other)
返回一个组合的条件,当且仅当所有条件都符合时,才返回
true, |
static MethodMatcher |
MethodMatcherUtil.anyMatch(MethodMatcher... matchers)
用于组合多个方法匹配器的方法匹配器,当任意方法匹配器匹配成功时即认为方法匹配。
|
static MethodMatcher |
MethodMatcherUtil.forGetterMethod(Field field)
用于获得指定属性的getter方法的匹配器
查找方法名为
get + 首字母大写的属性名的无参数方法;
查找方法名为属性名的无参数方法;
若fieldType为boolean或Boolean,则同时查找方法名为is + 首字母大写的属性的无参数方法;
|
static MethodMatcher |
MethodMatcherUtil.forGetterMethod(String fieldName,
Class<?> fieldType)
用于获得指定属性的getter方法的匹配器
查找方法名为
get + 首字母大写的属性名的无参数方法;
查找方法名为属性名的无参数方法;
若fieldType为boolean或Boolean,则同时查找方法名为is + 首字母大写的属性的无参数方法;
|
static MethodMatcher |
MethodMatcherUtil.forMethodSignature(Method method)
用于匹配方法签名的方法匹配器,检查的内容包括:
方法名是否完全一致;
返回值类型是否匹配,允许返回值类型为方法返回值类型的子类;
参数类型是否匹配,允许参数类型为方法参数类型的子类;
|
static MethodMatcher |
MethodMatcherUtil.forMethodSignature(String methodName,
Class<?> returnType,
Class<?>... parameterTypes)
用于匹配方法签名的方法匹配器,检查的内容包括:
方法名是否完全一致;
返回值类型是否匹配,允许返回值类型为方法返回值类型的子类,若返回值类型为
null则表示匹配无返回值的方法;
参数类型是否匹配,允许参数类型为方法参数类型的子类,若参数类型为null则表示匹配无参数的方法;
|
static MethodMatcher |
MethodMatcherUtil.forModifiers(int... modifiers)
用于具有指定修饰符的方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.forMostSpecificParameterTypes(Class<?>... parameterTypes)
用于匹配指定参数类型的方法的方法匹配器,与
MethodMatcherUtil.forParameterTypes(java.lang.Class<?>...)不同的是,该方法仅用于尽量可能最匹配的方法
若参数为空,则表示匹配无参数方法;
若参数不为空:
仅匹配parameterTypes中不为null的参数类型,若参数类型为null则表示匹配任意类型的参数;
若N为parameterTypes长度,则仅要求parameterTypes不为null的类型与方法前N个参数类型匹配即可;
若parameterTypes长度大于参数列表长度,则直接返回false;
比如:若存在三参数方法 method(String, Integer, Object),支持以下匹配:
forMostSpecificParameterTypes(CharSequence.class, Number.class, Object.class)
forMostSpecificParameterTypes(String.class, Integer.class, Object.class)
forMostSpecificParameterTypes(String.class, Integer.class, null)
forMostSpecificParameterTypes(String.class, null, null)
forMostSpecificParameterTypes(null, null, null)
forMostSpecificParameterTypes(String.class, Integer.class)
forMostSpecificParameterTypes(String.class)
|
static MethodMatcher |
MethodMatcherUtil.forMostSpecificStrictParameterTypes(Class<?>... parameterTypes)
用于匹配指定参数类型的方法的方法匹配器,与
MethodMatcherUtil.forParameterTypes(java.lang.Class<?>...)不同的是,该方法仅用于尽量可能最匹配的方法
若参数为空,则表示匹配无参数方法;
若参数不为空:
仅匹配parameterTypes中不为null的参数类型,若参数类型为null则表示匹配任意类型的参数;
若N为parameterTypes长度,则仅要求parameterTypes不为null的类型与方法前N个参数类型匹配即可;
若parameterTypes长度大于参数列表长度,则直接返回false;
比如:若存在三参数方法 method(String, Integer, Object),支持以下匹配:
forMostSpecificParameterTypes(String.class, Integer.class, Object.class)
forMostSpecificParameterTypes(String.class, Integer.class, null)
forMostSpecificParameterTypes(String.class, null, null)
forMostSpecificParameterTypes(null, null, null)
forMostSpecificParameterTypes(String.class, Integer.class)
forMostSpecificParameterTypes(String.class)
|
static MethodMatcher |
MethodMatcherUtil.forName(String methodName)
用于根据方法名匹配方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.forNameAndParameterTypes(String methodName,
Class<?>... parameterTypes)
用于同时匹配方法名和参数类型的方法匹配器,其中,参数类型匹配时允许参数类型为方法参数类型的子类。
|
static MethodMatcher |
MethodMatcherUtil.forNameAndStrictParameterTypes(String methodName,
Class<?>... parameterTypes)
用于同时匹配方法名和参数类型的方法匹配器,其中,参数类型匹配时要求参数类型与方法参数类型完全一致。
|
static MethodMatcher |
MethodMatcherUtil.forNameIgnoreCase(String methodName)
用于根据方法名匹配方法的方法匹配器,忽略方法名大小写。
|
static MethodMatcher |
MethodMatcherUtil.forNameIgnoreCaseAndParameterTypes(String methodName,
Class<?>... parameterTypes)
用于同时匹配方法名和参数类型的方法匹配器,其中,参数类型匹配时允许参数类型为方法参数类型的子类,且方法名忽略大小写。
|
static MethodMatcher |
MethodMatcherUtil.forNameIgnoreCaseAndStrictParameterTypes(String methodName,
Class<?>... parameterTypes)
用于同时匹配方法名和参数类型的方法匹配器,其中,参数类型匹配时要求参数类型与方法参数类型完全一致,且方法名忽略大小写。
|
static MethodMatcher |
MethodMatcherUtil.forNoneParameter()
用于匹配无参数方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.forNoneReturnType()
用于匹配无返回值的方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.forParameterCount(int count)
用于匹配指定参数个数的方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.forParameterTypes(Class<?>... parameterTypes)
用于匹配指定参数类型的方法的方法匹配器,只要参数类型可以赋值给方法参数类型即认为匹配成功。
|
static MethodMatcher |
MethodMatcherUtil.forReturnType(Class<?> returnType)
用于匹配指定参数类型的方法的方法匹配器,只要参数类型可以赋值给方法参数类型。
|
static MethodMatcher |
MethodMatcherUtil.forSetterMethod(Field field)
用于获得指定属性的setter方法的匹配器,默认查找方法名为
set + 首字母大写的属性的单参数方法。 |
static MethodMatcher |
MethodMatcherUtil.forSetterMethod(String fieldName,
Class<?> fieldType)
用于获得指定属性的setter方法的匹配器,默认查找方法名为
set + 首字母大写的属性的单参数方法。 |
static MethodMatcher |
MethodMatcherUtil.forStrictMethodSignature(Method method)
用于匹配方法签名的方法匹配器,检查的内容包括:
方法名是否完全一致;
返回值类型是否匹配,要求返回值类型与方法返回值类型完全一致;
参数类型是否匹配,要求参数类型与方法参数类型完全一致;
|
static MethodMatcher |
MethodMatcherUtil.forStrictMethodSignature(String methodName,
Class<?> returnType,
Class<?>... parameterTypes)
用于匹配方法签名的方法匹配器,检查的内容包括:
方法名是否完全一致;
返回值类型是否匹配,要求返回值类型与方法返回值类型完全一致,若返回值类型为
null则表示匹配无返回值的方法;
参数类型是否匹配,要求参数类型与方法参数类型完全一致,若参数类型为null则表示匹配无参数的方法;
|
static MethodMatcher |
MethodMatcherUtil.forStrictParameterTypes(Class<?>... parameterTypes)
用于匹配指定参数类型的方法的方法匹配器,只有参数类型完全匹配才认为匹配成功。
|
static MethodMatcher |
MethodMatcherUtil.forStrictReturnType(Class<?> returnType)
用于匹配指定返回值类型的方法的方法匹配器,要求返回值类型与指定类型完全一致。
|
static MethodMatcher |
MethodMatcherUtil.hasAnnotation(Class<? extends Annotation> annotationType)
用于匹配被指定注解标注、或注解层级结构中存在指定注解的方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.hasAnnotationOnDeclaringClass(Class<? extends Annotation> annotationType)
用于匹配声明方法的类的层级接口中,存在任意类被指定注解标注、或注解层级结构中存在指定注解的方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.hasAnnotationOnMethodOrDeclaringClass(Class<? extends Annotation> annotationType)
用于匹配方法本身或声明方法的类上,直接被指定注解标注、或注解层级结构中存在指定注解的方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.hasDeclaredAnnotation(Class<? extends Annotation> annotationType)
用于匹配被指定注解标注、或注解层级结构中存在指定注解的方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.isPublic()
用于匹配共有方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.isPublicStatic()
用于匹配公共静态方法的方法匹配器。
|
static MethodMatcher |
MethodMatcherUtil.isStatic()
用于匹配静态方法的方法匹配器。
|
default MethodMatcher |
MethodMatcher.negate()
返回一个与此条件相反的条件
|
static MethodMatcher |
MethodMatcherUtil.noneMatch(MethodMatcher... matchers)
用于组合多个方法匹配器的方法匹配器,仅当所有方法匹配器均匹配失败时才认为方法匹配。
|
static MethodMatcher |
MethodMatcherUtil.of(Predicate<Method> predicate)
创建一个方法匹配器
|
default MethodMatcher |
MethodMatcher.or(Predicate<? super Method> other)
返回一个组合的条件,当且仅当任一条件符合时,才返回
true, |
| 限定符和类型 | 方法和说明 |
|---|---|
static MethodMatcher |
MethodMatcherUtil.allMatch(MethodMatcher... matchers)
用于组合多个方法匹配器的方法匹配器,当所有方法匹配器均匹配成功时才认为方法匹配。
|
static MethodMatcher |
MethodMatcherUtil.anyMatch(MethodMatcher... matchers)
用于组合多个方法匹配器的方法匹配器,当任意方法匹配器匹配成功时即认为方法匹配。
|
static MethodMatcher |
MethodMatcherUtil.noneMatch(MethodMatcher... matchers)
用于组合多个方法匹配器的方法匹配器,仅当所有方法匹配器均匹配失败时才认为方法匹配。
|
Copyright © 2023. All rights reserved.