Package org.codehaus.groovy.reflection
Class ReflectionUtils
java.lang.Object
org.codehaus.groovy.reflection.ReflectionUtils
public class ReflectionUtils
extends java.lang.Object
This class contains utility methods to determine which class called the
current class to multiple levels of depth. Calls used to handle the
groovy MOP are excluded from the level counting.
-
Method Summary
Modifier and Type Method Description static boolean
checkAccessible(java.lang.Class<?> callerClass, java.lang.Class<?> declaringClass, int memberModifiers, boolean allowIllegalAccess)
static boolean
checkCanSetAccessible(java.lang.reflect.AccessibleObject accessibleObject, java.lang.Class<?> caller)
static java.lang.Class
getCallingClass()
Gets the immediate calling class, ignoring MOP frames.static java.lang.Class
getCallingClass(int matchLevel)
Gets the called that is matchLevel stack frames before the call, ignoring MOP frames.static java.lang.Class
getCallingClass(int matchLevel, java.util.Collection<java.lang.String> extraIgnoredPackages)
Gets the called that is matchLevel stack frames before the call, ignoring MOP frames and desired exclude packages.static java.util.List<java.lang.reflect.Method>
getDeclaredMethods(java.lang.Class<?> type, java.lang.String name, java.lang.Class<?>... parameterTypes)
static java.util.List<java.lang.reflect.Method>
getMethods(java.lang.Class<?> type, java.lang.String name, java.lang.Class<?>... parameterTypes)
static boolean
isCallingClassReflectionAvailable()
Determines whether or not the getCallingClass methods will return any sensible results.static boolean
isSealed(java.lang.Class<?> c)
static java.util.Optional<java.lang.reflect.AccessibleObject>
makeAccessible(java.lang.reflect.AccessibleObject ao)
static java.lang.reflect.AccessibleObject[]
makeAccessible(java.lang.reflect.AccessibleObject[] aoa)
static java.util.Optional<java.lang.reflect.AccessibleObject>
makeAccessibleInPrivilegedAction(java.lang.reflect.AccessibleObject ao)
static boolean
trySetAccessible(java.lang.reflect.AccessibleObject ao)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
isCallingClassReflectionAvailable
public static boolean isCallingClassReflectionAvailable()Determines whether or not the getCallingClass methods will return any sensible results. On JVMs that are not Sun derived i.e. (gcj, Harmony) this will likely return false. When not available all getCallingClass methods will return null.- Returns:
- true if getCallingClass can return anything but null, false if it will only return null.
-
getCallingClass
public static java.lang.Class getCallingClass()Gets the immediate calling class, ignoring MOP frames.- Returns:
- The Class of the caller
-
getCallingClass
public static java.lang.Class getCallingClass(int matchLevel)Gets the called that is matchLevel stack frames before the call, ignoring MOP frames.- Parameters:
matchLevel
- how may call stacks down to look. If it is less than 1 it is treated as though it was 1.- Returns:
- The Class of the matched caller, or null if there aren't enough stackframes to satisfy matchLevel
-
getCallingClass
public static java.lang.Class getCallingClass(int matchLevel, java.util.Collection<java.lang.String> extraIgnoredPackages)Gets the called that is matchLevel stack frames before the call, ignoring MOP frames and desired exclude packages.- Parameters:
matchLevel
- how may call stacks down to look. If it is less than 1 it is treated as though it was 1.extraIgnoredPackages
- A collection of string names of packages to exclude in addition to the MOP packages when counting stack frames.- Returns:
- The Class of the matched caller, or null if there aren't enough stackframes to satisfy matchLevel
-
getDeclaredMethods
public static java.util.List<java.lang.reflect.Method> getDeclaredMethods(java.lang.Class<?> type, java.lang.String name, java.lang.Class<?>... parameterTypes) -
getMethods
public static java.util.List<java.lang.reflect.Method> getMethods(java.lang.Class<?> type, java.lang.String name, java.lang.Class<?>... parameterTypes) -
checkCanSetAccessible
public static boolean checkCanSetAccessible(java.lang.reflect.AccessibleObject accessibleObject, java.lang.Class<?> caller) -
checkAccessible
public static boolean checkAccessible(java.lang.Class<?> callerClass, java.lang.Class<?> declaringClass, int memberModifiers, boolean allowIllegalAccess) -
trySetAccessible
public static boolean trySetAccessible(java.lang.reflect.AccessibleObject ao) -
makeAccessibleInPrivilegedAction
public static java.util.Optional<java.lang.reflect.AccessibleObject> makeAccessibleInPrivilegedAction(java.lang.reflect.AccessibleObject ao) -
makeAccessible
public static java.util.Optional<java.lang.reflect.AccessibleObject> makeAccessible(java.lang.reflect.AccessibleObject ao) -
makeAccessible
public static java.lang.reflect.AccessibleObject[] makeAccessible(java.lang.reflect.AccessibleObject[] aoa) -
isSealed
public static boolean isSealed(java.lang.Class<?> c)
-