Class Reflection
- java.lang.Object
-
- hudson.plugins.project_inheritance.util.Reflection
-
public class Reflection extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Reflection.AssignabilityChecker
protected static class
Reflection.CachedClassResolver
This is a cache for loading classes by their name.
-
Field Summary
Fields Modifier and Type Field Description protected static Reflection.AssignabilityChecker
assigner
protected static int
MAX_STACK_DEPTH
protected static Reflection.CachedClassResolver
resolver
A short-term (30s) cache to speed up resolving classes
-
Constructor Summary
Constructors Constructor Description Reflection()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
calledFromClass(int maxDepth, Class<?>... classes)
This method determines whether or not it was called by an object derived from theInheritanceBuild
class.static boolean
calledFromClass(Class<?>... classes)
Wrapper forcalledFromClass(int, Class...)
, with the maxDepth set to 30.static boolean
calledFromClassNames(int maxDepth, String... classes)
static boolean
calledFromClassNames(String... classes)
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.static boolean
calledFromMethod(Class<?> clazz, String... methodNames)
Wrapper forcalledFromMethod(Class, int, String...)
, with the maxDepth set to 30.static Object
invokeIfPossible(Object self, String methodName, Object... args)
-
-
-
Field Detail
-
MAX_STACK_DEPTH
protected static final int MAX_STACK_DEPTH
- See Also:
- Constant Field Values
-
resolver
protected static final Reflection.CachedClassResolver resolver
A short-term (30s) cache to speed up resolving classes
-
assigner
protected static final Reflection.AssignabilityChecker assigner
-
-
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 forcalledFromClass(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 theInheritanceBuild
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 formaxDepth
- 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 forcalledFromMethod(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.
-
-