Package com.google.common.flogger.util
Class CallerFinder
- java.lang.Object
-
- com.google.common.flogger.util.CallerFinder
-
public final class CallerFinder extends Object
A helper class for determining callers of a specified class currently on the stack.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @Nullable StackTraceElementfindCallerOf(Class<?> target, int skip)Returns the stack trace element of the immediate caller of the specified class.static StackTraceElement[]getStackForCallerOf(Class<?> target, int maxDepth, int skip)Returns a synthetic stack trace starting at the immediate caller of the specified target.
-
-
-
Method Detail
-
findCallerOf
public static @Nullable StackTraceElement findCallerOf(Class<?> target, int skip)
Returns the stack trace element of the immediate caller of the specified class.- Parameters:
target- the target class whose callers we are looking for.skip- the minimum number of calls known to have occurred between the first call to the target class and the point at which the specified throwable was created. If in doubt, specify zero here to avoid accidentally skipping past the caller. This is particularly important for code which might be used in Android, since you cannot know whether a tool such as Proguard has merged methods or classes and reduced the number of intermediate stack frames.- Returns:
- the stack trace element representing the immediate caller of the specified class, or null if no caller was found (due to incorrect target, wrong skip count or use of JNI).
-
getStackForCallerOf
public static StackTraceElement[] getStackForCallerOf(Class<?> target, int maxDepth, int skip)
Returns a synthetic stack trace starting at the immediate caller of the specified target.- Parameters:
target- the class who caller the returned stack trace will start at.maxDepth- the maximum size of the returned stack (pass -1 for the complete stack).skip- the minimum number of stack frames to skip before looking for callers.- Returns:
- a synthetic stack trace starting at the immediate caller of the specified target, or the empty array if no caller was found (due to incorrect target, wrong skip count or use of JNI).
-
-