package com.qianwen.core.tool.utils;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.SynthesizingMethodParameter;
import org.springframework.util.ClassUtils;
import org.springframework.web.method.HandlerMethod;
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/utils/ClassUtil.class */
public class ClassUtil extends ClassUtils {
private static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER = new DefaultParameterNameDiscoverer();
public static MethodParameter getMethodParameter(Constructor> constructor, int parameterIndex) {
SynthesizingMethodParameter synthesizingMethodParameter = new SynthesizingMethodParameter(constructor, parameterIndex);
synthesizingMethodParameter.initParameterNameDiscovery(PARAMETER_NAME_DISCOVERER);
return synthesizingMethodParameter;
}
public static MethodParameter getMethodParameter(Method method, int parameterIndex) {
SynthesizingMethodParameter synthesizingMethodParameter = new SynthesizingMethodParameter(method, parameterIndex);
synthesizingMethodParameter.initParameterNameDiscovery(PARAMETER_NAME_DISCOVERER);
return synthesizingMethodParameter;
}
public static A getAnnotation(Method method, Class annotationType) {
Class> targetClass = method.getDeclaringClass();
Method specificMethod = BridgeMethodResolver.findBridgedMethod(getMostSpecificMethod(method, targetClass));
A annotation = (A) AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType);
if (null != annotation) {
return annotation;
}
return (A) AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType);
}
public static A getAnnotation(HandlerMethod handlerMethod, Class annotationType) {
A annotation = (A) handlerMethod.getMethodAnnotation(annotationType);
if (null != annotation) {
return annotation;
}
Class> beanType = handlerMethod.getBeanType();
return (A) AnnotatedElementUtils.findMergedAnnotation(beanType, annotationType);
}
public static boolean isAnnotated(Method method, Class annotationType) {
boolean isMethodAnnotated = AnnotatedElementUtils.isAnnotated(method, annotationType);
if (isMethodAnnotated) {
return true;
}
Class> targetClass = method.getDeclaringClass();
return AnnotatedElementUtils.isAnnotated(targetClass, annotationType);
}
}