mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-09 03:46:18 -04:00
Update CallerFinder (#3350)
* Update CallerFinder * Revert "Fix #2687 (#2688)" This reverts commit 207b4d003384b048abe069e4888e980741d7bbf6. * update --------- Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
parent
49ea9e5da0
commit
457490276c
@ -9,13 +9,13 @@ import java.util.stream.Stream;
|
||||
* @author Glavo
|
||||
*/
|
||||
final class CallerFinder {
|
||||
private static final StackWalker WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
|
||||
private static final String PACKAGE_PREFIX = CallerFinder.class.getPackageName() + ".";
|
||||
private static final Predicate<StackWalker.StackFrame> PREDICATE = stackFrame -> !stackFrame.getClassName().startsWith(PACKAGE_PREFIX);
|
||||
private static final Function<Stream<StackWalker.StackFrame>, Optional<StackWalker.StackFrame>> FUNCTION = stream -> stream.filter(PREDICATE).findFirst();
|
||||
private static final Function<StackWalker.StackFrame, String> FRAME_MAPPING = frame -> frame.getClassName() + "." + frame.getMethodName();
|
||||
|
||||
static String getCaller() {
|
||||
return WALKER.walk(FUNCTION).map(it -> it.getClassName() + "." + it.getMethodName()).orElse(null);
|
||||
return StackWalker.getInstance().walk(FUNCTION).map(FRAME_MAPPING).orElse(null);
|
||||
}
|
||||
|
||||
private CallerFinder() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user