Class StackLocatorUtil


  • public final class StackLocatorUtil
    extends Object
    Consider this class private. Provides various methods to determine the caller class.

    Background

    • Method Detail

      • getCallerClass

        public static Class<?> getCallerClass​(int depth)
      • getStackTraceElement

        public static StackTraceElement getStackTraceElement​(int depth)
      • getCallerClass

        public static Class<?> getCallerClass​(String fqcn,
                                              String pkg)
        Search for a calling class.
        Parameters:
        fqcn - Root class name whose caller to search for.
        pkg - Package name prefix that must be matched after the fqcn has been found.
        Returns:
        The caller class that was matched, or null if one could not be located.
      • getCallerClassLoader

        public static ClassLoader getCallerClassLoader​(int depth)
        Gets the ClassLoader of the class that called this method at the location up the call stack by the given stack frame depth.

        This method returns null if:

        • sun.reflect.Reflection.getCallerClass(int) is not present.
        • An exception is caught calling sun.reflect.Reflection.getCallerClass(int).
        • Some Class implementations may use null to represent the bootstrap class loader.
        Parameters:
        depth - The stack frame count to walk.
        Returns:
        A class or null.
        Throws:
        IndexOutOfBoundsException - if depth is negative.
      • getCallerClass

        public static Class<?> getCallerClass​(Class<?> sentinelClass,
                                              Predicate<Class<?>> callerPredicate)
        Search for a calling class.
        Parameters:
        sentinelClass - Sentinel class at which to begin searching
        callerPredicate - Predicate checked after the sentinelClass is found
        Returns:
        the first matching class after sentinelClass is found.
      • getCallerClass

        public static Class<?> getCallerClass​(Class<?> anchor)
      • getCurrentStackTrace

        public static Deque<Class<?>> getCurrentStackTrace()