package com.thhy.general.config.mysql.tos; import org.springframework.lang.Nullable; public class MoreReflection { private static final StackTraceProvider STACK_TRACE_PROVIDER=new StackTraceProviderJdk8(); /** * 获取当前方法的调用者,通过获取当前的调用栈向上查找获得 * * @return StackTraceElement */ @Nullable public static StackTraceElement getCallerPlace() { return getCallerPlace(MoreReflection.class); } /** * 获取当前方法的调用者,从指定的类位置向上查找 * * @param locationAwareClass 指定类的类型 * @return StackTraceElement */ @Nullable public static StackTraceElement getCallerPlace(Class locationAwareClass) { String name = locationAwareClass.getName(); return STACK_TRACE_PROVIDER.getCallerPlace(name::equals, Predicates.alwaysFalse()); } }