Top Description Inners Fields Constructors Methods
nonapi.io.github.classgraph.reflection

pack-priv abstract Class ReflectionDriver

extends Object
Class Inheritance
Known Direct Subclasses
nonapi.io.github.classgraph.reflection.StandardReflectionDriver, nonapi.io.github.classgraph.reflection.JVMDriverReflectionDriver, nonapi.io.github.classgraph.reflection.NarcissusReflectionDriver
Imports
java.lang.reflect.AccessibleObject, .Constructor, .Field, .Method, java.util.ArrayList, .Arrays, .HashMap, .HashSet, .LinkedList, .List, .Map, .Set, nonapi.io.github.classgraph.concurrency.SingletonMap, nonapi.io.github.classgraph.utils.LogNode

Reflection driver

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
ReflectionDriver.ClassMemberCache

Caches class members.

Field Summary

Modifier and TypeField and Description
private static Method
private final SingletonMap<Class<?>, ReflectionDriver.ClassMemberCache, Exception>
private static Method

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract Class<?>

Returns:

the class reference
findClass
(final String
the class name
className
)

Find a class by name.

protected Field

Returns:

The Field object for the requested field name, or null if no such field was found in the class.
findField
(final Class<?>
the class.
cls
,
final Object
the object instance, or null for a static field.
obj
,
final String
The name of the field.
fieldName
)

Get the field of the class that has a given field name.

protected Field

Returns:

The Field object for the requested field name, or null if no such field was found in the class.
findInstanceField
(final Object
the object instance, or null for a static field.
obj
,
final String
The name of the field.
fieldName
)

Get the non-static field of the class that has a given field name.

protected Method

Returns:

The Method object for the matching method, or null if no such method was found in the class.
findInstanceMethod
(final Object
the object instance, or null for a static method.
obj
,
final String
The name of the method.
methodName
,
final Class<?>...
The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.
paramTypes
)

Get a non-static method by name and parameter types.

protected Method

Returns:

The Method object for the matching method, or null if no such method was found in the class.
findMethod
(final Class<?>
the class.
cls
,
final Object
the object instance, or null for a static method.
obj
,
final String
The name of the method.
methodName
,
final Class<?>...
The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.
paramTypes
)

Get a method by name and parameter types.

protected Field

Returns:

The Field object for the requested field name, or null if no such field was found in the class.
findStaticField
(final Class<?>
the class.
cls
,
final String
The name of the field.
fieldName
)

Get the static field of the class that has a given field name.

protected Method

Returns:

The Method object for the matching method, or null if no such method was found in the class.
findStaticMethod
(final Class<?>
the class.
cls
,
final String
The name of the method.
methodName
,
final Class<?>...
The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.
paramTypes
)

Get a static method by name and parameter types.

pack-priv abstract <
the generic type
T
>
Constructor<T>[]

Returns:

the declared constructors
getDeclaredConstructors
(Class<T>
the class
cls
)

Get declared constructors for class.

pack-priv abstract Field[]

Returns:

the declared fields
getDeclaredFields
(Class<?>
the class
cls
)

Get declared fields for class.

pack-priv abstract Method[]

Returns:

the declared methods
getDeclaredMethods
(Class<?>
the class
cls
)

Get declared methods for class.

pack-priv abstract Object

Returns:

the value of the field
getField
(final Object
the object instance to get the field value from
object
,
final Field
the non-static field
field
)

Get the value of a non-static field, boxing the value if necessary.

pack-priv abstract Object

Returns:

the static field
getStaticField
(final Field
the static field
field
)

Get the value of a static field, boxing the value if necessary.

pack-priv abstract Object

Returns:

the return value (possibly a boxed value)
invokeMethod
(final Object
the object instance to invoke the method on
object
,
final Method
the non-static method
method
,
final Object...
the method arguments (or new Object[0] if there are no args)
args
)

Invoke a non-static method, boxing the result if necessary.

pack-priv abstract Object

Returns:

the return value (possibly a boxed value)
invokeStaticMethod
(final Method
the static method
method
,
final Object...
the method arguments (or new Object[0] if there are no args)
args
)

Invoke a static method, boxing the result if necessary.

pack-priv boolean

Returns:

true if accessible.
isAccessible
(final Object
the object instance, or null if static.
instance
,
final AccessibleObject
the field or method.
fieldOrMethod
)

Check whether a field or method is accessible.

pack-priv abstract boolean

Returns:

true if successful.
makeAccessible
(final Object
the object instance, or null if static.
instance
,
final AccessibleObject
the field or method.
fieldOrMethod
)

Make a field or method accessible.

pack-priv abstract void
setField(final Object
the object instance to get the field value from
object
,
final Field
the non-static field
field
,
Object
the value to set
value
)

Set the value of a non-static field, unboxing the value if necessary.

pack-priv abstract void
setStaticField(final Field
the static field
field
,
Object
the value to set
value
)

Set the value of a static field, unboxing the value if necessary.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

canAccessMethodback to summary
private static Method canAccessMethod
classToClassMemberCacheback to summary
private final SingletonMap<Class<?>, ReflectionDriver.ClassMemberCache, Exception> classToClassMemberCache
isAccessibleMethodback to summary
private static Method isAccessibleMethod

Constructor Detail

ReflectionDriverback to summary
pack-priv ReflectionDriver()

Method Detail

findClassback to summary
pack-priv abstract Class<?> findClass(final String className) throws Exception

Find a class by name.

Parameters
className:String

the class name

Returns:Class<?>

the class reference

findFieldback to summary
protected Field findField(final Class<?> cls, final Object obj, final String fieldName) throws Exception

Get the field of the class that has a given field name.

Parameters
cls:Class<?>

the class.

obj:Object

the object instance, or null for a static field.

fieldName:String

The name of the field.

Returns:Field

The Field object for the requested field name, or null if no such field was found in the class.

Exceptions
Exception:
if the field could not be found
findInstanceFieldback to summary
protected Field findInstanceField(final Object obj, final String fieldName) throws Exception

Get the non-static field of the class that has a given field name.

Parameters
obj:Object

the object instance, or null for a static field.

fieldName:String

The name of the field.

Returns:Field

The Field object for the requested field name, or null if no such field was found in the class.

Exceptions
Exception:
if the field could not be found
findInstanceMethodback to summary
protected Method findInstanceMethod(final Object obj, final String methodName, final Class<?>... paramTypes) throws Exception

Get a non-static method by name and parameter types.

Parameters
obj:Object

the object instance, or null for a static method.

methodName:String

The name of the method.

paramTypes:Class<?>[]

The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.

Returns:Method

The Method object for the matching method, or null if no such method was found in the class.

Exceptions
Exception:
if the method could not be found.
findMethodback to summary
protected Method findMethod(final Class<?> cls, final Object obj, final String methodName, final Class<?>... paramTypes) throws Exception

Get a method by name and parameter types.

Parameters
cls:Class<?>

the class.

obj:Object

the object instance, or null for a static method.

methodName:String

The name of the method.

paramTypes:Class<?>[]

The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.

Returns:Method

The Method object for the matching method, or null if no such method was found in the class.

Exceptions
Exception:
if the method could not be found.
findStaticFieldback to summary
protected Field findStaticField(final Class<?> cls, final String fieldName) throws Exception

Get the static field of the class that has a given field name.

Parameters
cls:Class<?>

the class.

fieldName:String

The name of the field.

Returns:Field

The Field object for the requested field name, or null if no such field was found in the class.

Exceptions
Exception:
if the field could not be found
findStaticMethodback to summary
protected Method findStaticMethod(final Class<?> cls, final String methodName, final Class<?>... paramTypes) throws Exception

Get a static method by name and parameter types.

Parameters
cls:Class<?>

the class.

methodName:String

The name of the method.

paramTypes:Class<?>[]

The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.

Returns:Method

The Method object for the matching method, or null if no such method was found in the class.

Exceptions
Exception:
if the method could not be found.
getDeclaredConstructorsback to summary
pack-priv abstract <T> Constructor<T>[] getDeclaredConstructors(Class<T> cls) throws Exception

Get declared constructors for class.

Parameters
<T>
the generic type
cls:Class<T>

the class

Returns:Constructor<T>[]

the declared constructors

getDeclaredFieldsback to summary
pack-priv abstract Field[] getDeclaredFields(Class<?> cls) throws Exception

Get declared fields for class.

Parameters
cls:Class<?>

the class

Returns:Field[]

the declared fields

getDeclaredMethodsback to summary
pack-priv abstract Method[] getDeclaredMethods(Class<?> cls) throws Exception

Get declared methods for class.

Parameters
cls:Class<?>

the class

Returns:Method[]

the declared methods

getFieldback to summary
pack-priv abstract Object getField(final Object object, final Field field) throws Exception

Get the value of a non-static field, boxing the value if necessary.

Parameters
object:Object

the object instance to get the field value from

field:Field

the non-static field

Returns:Object

the value of the field

getStaticFieldback to summary
pack-priv abstract Object getStaticField(final Field field) throws Exception

Get the value of a static field, boxing the value if necessary.

Parameters
field:Field

the static field

Returns:Object

the static field

invokeMethodback to summary
pack-priv abstract Object invokeMethod(final Object object, final Method method, final Object... args) throws Exception

Invoke a non-static method, boxing the result if necessary.

Parameters
object:Object

the object instance to invoke the method on

method:Method

the non-static method

args:Object[]

the method arguments (or new Object[0] if there are no args)

Returns:Object

the return value (possibly a boxed value)

invokeStaticMethodback to summary
pack-priv abstract Object invokeStaticMethod(final Method method, final Object... args) throws Exception

Invoke a static method, boxing the result if necessary.

Parameters
method:Method

the static method

args:Object[]

the method arguments (or new Object[0] if there are no args)

Returns:Object

the return value (possibly a boxed value)

isAccessibleback to summary
pack-priv boolean isAccessible(final Object instance, final AccessibleObject fieldOrMethod)

Check whether a field or method is accessible.

N.B. this is overridden in Narcissus driver to just return true, since everything is accessible to JNI.

Parameters
instance:Object

the object instance, or null if static.

fieldOrMethod:AccessibleObject

the field or method.

Returns:boolean

true if accessible.

makeAccessibleback to summary
pack-priv abstract boolean makeAccessible(final Object instance, final AccessibleObject fieldOrMethod)

Make a field or method accessible.

Parameters
instance:Object

the object instance, or null if static.

fieldOrMethod:AccessibleObject

the field or method.

Returns:boolean

true if successful.

setFieldback to summary
pack-priv abstract void setField(final Object object, final Field field, Object value) throws Exception

Set the value of a non-static field, unboxing the value if necessary.

Parameters
object:Object

the object instance to get the field value from

field:Field

the non-static field

value:Object

the value to set

setStaticFieldback to summary
pack-priv abstract void setStaticField(final Field field, Object value) throws Exception

Set the value of a static field, unboxing the value if necessary.

Parameters
field:Field

the static field

value:Object

the value to set

nonapi.io.github.classgraph.reflection back to summary

public Class ReflectionDriver.ClassMemberCache

extends Object
Class Inheritance
  • java.lang.Object
  • nonapi.io.github.classgraph.reflection.ReflectionDriver.ClassMemberCache

Caches class members.

Field Summary

Modifier and TypeField and Description
private final Map<String, Field>
private final Map<String, List<Method>>

Constructor Summary

AccessConstructor and Description
private
ClassMemberCache(final Class<?> cls)

Method Summary

Modifier and TypeMethod and Description
private void
cacheField(final Field field)

private void
cacheMethod(final Method method)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fieldNameToFieldback to summary
private final Map<String, Field> fieldNameToField
methodNameToMethodsback to summary
private final Map<String, List<Method>> methodNameToMethods

Constructor Detail

ClassMemberCacheback to summary
private ClassMemberCache(final Class<?> cls) throws Exception

Method Detail

cacheFieldback to summary
private void cacheField(final Field field)
cacheMethodback to summary
private void cacheMethod(final Method method)