张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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());
    }
}