001package cn.sticki.validator.spel; 002 003import java.lang.reflect.Method; 004import java.security.PrivilegedAction; 005 006/** 007 * copy from {@link org.hibernate.validator.internal.util.privilegedactions.GetMethod} 008 * 009 * @author 阿杆 010 * @version 1.0 011 * @since 2024/4/30 012 */ 013public class GetMethod implements PrivilegedAction<Method> { 014 015 private final Class<?> clazz; 016 017 private final String methodName; 018 019 public static GetMethod action(Class<?> clazz, String methodName) { 020 return new GetMethod(clazz, methodName); 021 } 022 023 private GetMethod(Class<?> clazz, String methodName) { 024 this.clazz = clazz; 025 this.methodName = methodName; 026 } 027 028 @Override 029 public Method run() { 030 try { 031 return this.clazz.getMethod(this.methodName); 032 } catch (NoSuchMethodException var2) { 033 return null; 034 } 035 } 036 037}