Top Description Inners Fields Constructors Methods
org.codehaus.groovy.reflection

public Class ReflectionUtils

extends Object
Class Inheritance
Annotations
@SuppressWarnings:rawtypes
Imports
org.codehaus.groovy.classgen.asm.util.TypeUtil, org.codehaus.groovy.vmplugin.VMPlugin, .VMPluginFactory, java.lang.reflect.AccessibleObject, .Array, .Method, java.security.AccessController, .PrivilegedAction, java.util.ArrayList, .Collection, .Collections, .HashSet, .LinkedList, .List, .Optional, .Set, java.util.function.Function

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ReflectionUtils.ClassContextHelper

Deprecated as a consequence of SecurityManager being deprecated.

Field Summary

Modifier and TypeField and Description
private static final ReflectionUtils.ClassContextHelper
HELPER

Deprecated as a consequence of ReflectionUtils.ClassContextHelper being deprecated.
private static final Set<String>
IGNORED_PACKAGES

The packages in the call stack that are only part of the Groovy MOP.

private static final VMPlugin

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean
checkAccessible(final Class<?> callerClass, final Class<?> declaringClass, final int memberModifiers, final boolean allowIllegalAccess)

public static boolean
checkCanSetAccessible(final AccessibleObject accessibleObject, final Class<?> caller)

private static boolean
classShouldBeIgnored(final Class<T> c, final Collection<String> extraIgnoredPackages)

private static List<Method>
doGetMethods(final Class<?> type, final String name, final Class<?>[] parameterTypes, final Function<? super Class<?>, ? extends Method[]> f)

public static Class<T>

Returns:

The Class of the caller
getCallingClass
()

Gets the immediate calling class, ignoring MOP frames.

public static Class<T>

Returns:

The Class of the matched caller, or null if there aren't enough stackframes to satisfy matchLevel
getCallingClass
(final int
how may call stacks down to look. If it is less than 1 it is treated as though it was 1.
matchLevel
)

Gets the called that is matchLevel stack frames before the call, ignoring MOP frames.

public static Class<T>

Returns:

The Class of the matched caller, or null if there aren't enough stackframes to satisfy matchLevel
getCallingClass
(final int
how may call stacks down to look. If it is less than 1 it is treated as though it was 1.
matchLevel
,
final Collection<String>
A collection of string names of packages to exclude in addition to the MOP packages when counting stack frames.
extraIgnoredPackages
)

Gets the called that is matchLevel stack frames before the call, ignoring MOP frames and desired exclude packages.

public static List<Method>
getDeclaredMethods(final Class<?> type, final String name, final Class<?>... parameterTypes)

public static List<Method>
getMethods(final Class<?> type, final String name, final Class<?>... parameterTypes)

public static boolean

Returns:

true if getCallingClass can return anything but null, false if it will only return null.
isCallingClassReflectionAvailable
()

Determines whether or not the getCallingClass methods will return any sensible results.

public static boolean
public static Optional<AccessibleObject>
public static AccessibleObject[]
public static Optional<AccessibleObject>
public static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HELPERback to summary
private static final ReflectionUtils.ClassContextHelper HELPER

Deprecated

as a consequence of ReflectionUtils.ClassContextHelper being deprecated. See corresponding docs for further information.

IGNORED_PACKAGESback to summary
private static final Set<String> IGNORED_PACKAGES

The packages in the call stack that are only part of the Groovy MOP.

VM_PLUGINback to summary
private static final VMPlugin VM_PLUGIN

Constructor Detail

ReflectionUtilsback to summary
private ReflectionUtils()

Method Detail

checkAccessibleback to summary
public static boolean checkAccessible(final Class<?> callerClass, final Class<?> declaringClass, final int memberModifiers, final boolean allowIllegalAccess)
checkCanSetAccessibleback to summary
public static boolean checkCanSetAccessible(final AccessibleObject accessibleObject, final Class<?> caller)
classShouldBeIgnoredback to summary
private static boolean classShouldBeIgnored(final Class<T> c, final Collection<String> extraIgnoredPackages)
doGetMethodsback to summary
private static List<Method> doGetMethods(final Class<?> type, final String name, final Class<?>[] parameterTypes, final Function<? super Class<?>, ? extends Method[]> f)
getCallingClassback to summary
public static Class<T> getCallingClass()

Gets the immediate calling class, ignoring MOP frames.

Returns:Class<T>

The Class of the caller

getCallingClassback to summary
public static Class<T> getCallingClass(final int matchLevel)

Gets the called that is matchLevel stack frames before the call, ignoring MOP frames.

Parameters
matchLevel:int

how may call stacks down to look. If it is less than 1 it is treated as though it was 1.

Returns:Class<T>

The Class of the matched caller, or null if there aren't enough stackframes to satisfy matchLevel

getCallingClassback to summary
public static Class<T> getCallingClass(final int matchLevel, final Collection<String> extraIgnoredPackages)

Gets the called that is matchLevel stack frames before the call, ignoring MOP frames and desired exclude packages.

Parameters
matchLevel:int

how may call stacks down to look. If it is less than 1 it is treated as though it was 1.

extraIgnoredPackages:Collection<String>

A collection of string names of packages to exclude in addition to the MOP packages when counting stack frames.

Returns:Class<T>

The Class of the matched caller, or null if there aren't enough stackframes to satisfy matchLevel

getDeclaredMethodsback to summary
public static List<Method> getDeclaredMethods(final Class<?> type, final String name, final Class<?>... parameterTypes)
getMethodsback to summary
public static List<Method> getMethods(final Class<?> type, final String name, final Class<?>... parameterTypes)
isCallingClassReflectionAvailableback to summary
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:boolean

true if getCallingClass can return anything but null, false if it will only return null.

isSealedback to summary
public static boolean isSealed(Class<?> c)
makeAccessibleback to summary
public static Optional<AccessibleObject> makeAccessible(final AccessibleObject ao)
makeAccessibleback to summary
public static AccessibleObject[] makeAccessible(final AccessibleObject[] aoa)
makeAccessibleInPrivilegedActionback to summary
public static Optional<AccessibleObject> makeAccessibleInPrivilegedAction(final AccessibleObject ao)
trySetAccessibleback to summary
public static boolean trySetAccessible(final AccessibleObject ao)
org.codehaus.groovy.reflection back to summary

private Class ReflectionUtils.ClassContextHelper

extends SecurityManager
Class Inheritance

Deprecated

as a consequence of SecurityManager being deprecated. See corresponding docs for further information.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Class<T>[]
getClassContext()

Overrides java.lang.SecurityManager.getClassContext.

Returns the current execution stack as an array of classes.
Inherited from java.lang.SecurityManager:
checkAcceptcheckAccesscheckAccesscheckConnectcheckConnectcheckCreateClassLoadercheckDeletecheckExeccheckExitcheckLinkcheckListencheckMulticastcheckMulticastcheckPackageAccesscheckPackageDefinitioncheckPermissioncheckPermissioncheckPrintJobAccesscheckPropertiesAccesscheckPropertyAccesscheckReadcheckReadcheckReadcheckSecurityAccesscheckSetFactorycheckWritecheckWritegetSecurityContextgetThreadGroup

Constructor Detail

ClassContextHelperback to summary
private ClassContextHelper()

Method Detail

getClassContextback to summary
public Class<T>[] getClassContext()

Overrides java.lang.SecurityManager.getClassContext.

Doc from java.lang.SecurityManager.getClassContext.

Returns the current execution stack as an array of classes.

The length of the array is the number of methods on the execution stack. The element at index 0 is the class of the currently executing method, the element at index 1 is the class of that method's caller, and so on.

Returns:Class<T>[]

the execution stack.

Annotations
@Override