Class Reflection


  • public class Reflection
    extends Object
    • Constructor Detail

      • Reflection

        public Reflection()
    • Method Detail

      • calledFromClassNames

        public static boolean calledFromClassNames​(String... classes)
      • calledFromClassNames

        public static boolean calledFromClassNames​(int maxDepth,
                                                   String... classes)
      • calledFromClass

        public static boolean calledFromClass​(Class<?>... classes)
        Wrapper for calledFromClass(int, Class...), with the maxDepth set to 30.
        Parameters:
        classes - the classes to search for.
        Returns:
        true, if the method was called from the given class.
      • calledFromClass

        public static boolean calledFromClass​(int maxDepth,
                                              Class<?>... classes)
        This method determines whether or not it was called by an object derived from the InheritanceBuild class.

        It does so by examining the call stack and checking whether one of the last 20 calls has a classname set, that can be resolved down to the InheritanceBuild class.

        Parameters:
        classes - the class to search for
        maxDepth - the maximum depth to search in the call stack. If 0 or negative, explore the full stack.
        Returns:
        true, if the method was called from the given class.
      • calledFromMethod

        public static boolean calledFromMethod​(Class<?> clazz,
                                               String... methodNames)
        Wrapper for calledFromMethod(Class, int, String...), with the maxDepth set to 30.
        Parameters:
        clazz - the class to search for. This must be an exact match.
        methodNames - the method names inside the class.
        Returns:
        true, if the method was called from the given class.
      • calledFromMethod

        public static boolean calledFromMethod​(Class<?> clazz,
                                               int maxDepth,
                                               String... methodNames)
        Determines whether or not at least one of the given methods from the given class are present in the call stack. Both class name and method name must be exact matches.
        Parameters:
        maxDepth - the maximum stack depth to search in.
        clazz - the class to search for. This must be an exact match.
        methodNames - the method names inside the class to search for.
        Returns:
        true, if at least one of the methods was called from the given class.