Class StackInspector


  • public final class StackInspector
    extends Object
    A utility class which is useful for inspecting the call stack.
    Author:
    David M. Lloyd
    • Constructor Detail

      • StackInspector

        private StackInspector()
    • Method Detail

      • getCallerClass

        public Class<?> getCallerClass​(int skipFrames)
        Get the caller class. The skipFrames argument specifies how many spots to go back on the call stack; 0 indicates the immediate caller.
        Parameters:
        skipFrames - the number of frames to skip over before the immediate caller
        Returns:
        the caller class
      • getCallStack

        public Class<?>[] getCallStack​(int skipFrames,
                                       int numFrames)
        Get all or a portion of the call stack. The numFrames argument specifies how many frames should be returned.
        Parameters:
        skipFrames - the number of frames to skip; 0 will include the immediate caller at index 0
        numFrames - the maximum number of frames to return
        Returns:
        the partial call stack
      • getCallStack

        public Class<?>[] getCallStack​(int skipFrames)
        Get all or a portion of the call stack. The numFrames argument specifies how many frames should be returned.
        Parameters:
        skipFrames - the number of frames to skip; 0 will include the immediate caller at index 0
        Returns:
        the partial call stack
      • getCallStack

        public Class<?>[] getCallStack()
        Get the call stack.
        Returns:
        the call stack
      • callStackContains

        public boolean callStackContains​(Class<?> clazz)
        Determine whether the call stack contains a given class. Useful for assertions.
        Parameters:
        clazz - the class to test
        Returns:
        true if the call stack contains the class