Class StackLocatorUtil


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

    Background

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private StackLocatorUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.StackTraceElement calcLocation​(java.lang.String fqcnOfLogger)  
      static java.lang.Class<?> getCallerClass​(int depth)  
      static java.lang.Class<?> getCallerClass​(java.lang.Class<?> anchor)  
      static java.lang.Class<?> getCallerClass​(java.lang.Class<?> sentinelClass, java.util.function.Predicate<java.lang.Class<?>> callerPredicate)
      Search for a calling class.
      static java.lang.Class<?> getCallerClass​(java.lang.String fqcn)
      Equivalent to getCallerClass(String, String) with an empty pkg.
      static java.lang.Class<?> getCallerClass​(java.lang.String fqcn, java.lang.String pkg)
      Search for a calling class.
      static java.util.Stack<java.lang.Class<?>> getCurrentStackTrace()  
      static java.lang.StackTraceElement getStackTraceElement​(int depth)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • errorLogged

        private static volatile boolean errorLogged
    • Constructor Detail

      • StackLocatorUtil

        private StackLocatorUtil()
    • Method Detail

      • getCallerClass

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

        public static java.lang.StackTraceElement getStackTraceElement​(int depth)
      • getCallerClass

        public static java.lang.Class<?> getCallerClass​(java.lang.String fqcn)
        Equivalent to getCallerClass(String, String) with an empty pkg.
      • getCallerClass

        public static java.lang.Class<?> getCallerClass​(java.lang.String fqcn,
                                                        java.lang.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.
      • getCallerClass

        public static java.lang.Class<?> getCallerClass​(java.lang.Class<?> sentinelClass,
                                                        java.util.function.Predicate<java.lang.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 java.lang.Class<?> getCallerClass​(java.lang.Class<?> anchor)
      • getCurrentStackTrace

        public static java.util.Stack<java.lang.Class<?>> getCurrentStackTrace()
      • calcLocation

        public static java.lang.StackTraceElement calcLocation​(java.lang.String fqcnOfLogger)