Class ReflectionDriver
java.lang.Object
nonapi.io.github.classgraph.reflection.ReflectionDriver
- Direct Known Subclasses:
JVMDriverReflectionDriver
,NarcissusReflectionDriver
,StandardReflectionDriver
Reflection driver
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Method
private final SingletonMap
<Class<?>, ReflectionDriver.ClassMemberCache, Exception> private static Method
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) abstract Class
<?> Find a class by name.protected Field
Get the field of the class that has a given field name.protected Field
findInstanceField
(Object obj, String fieldName) Get the non-static field of the class that has a given field name.protected Method
findInstanceMethod
(Object obj, String methodName, Class<?>... paramTypes) Get a non-static method by name and parameter types.protected Method
findMethod
(Class<?> cls, Object obj, String methodName, Class<?>... paramTypes) Get a method by name and parameter types.protected Field
findStaticField
(Class<?> cls, String fieldName) Get the static field of the class that has a given field name.protected Method
findStaticMethod
(Class<?> cls, String methodName, Class<?>... paramTypes) Get a static method by name and parameter types.(package private) abstract <T> Constructor<T>[]
getDeclaredConstructors
(Class<T> cls) Get declared constructors for class.(package private) abstract Field[]
getDeclaredFields
(Class<?> cls) Get declared fields for class.(package private) abstract Method[]
getDeclaredMethods
(Class<?> cls) Get declared methods for class.(package private) abstract Object
Get the value of a non-static field, boxing the value if necessary.(package private) abstract Object
getStaticField
(Field field) Get the value of a static field, boxing the value if necessary.(package private) abstract Object
invokeMethod
(Object object, Method method, Object... args) Invoke a non-static method, boxing the result if necessary.(package private) abstract Object
invokeStaticMethod
(Method method, Object... args) Invoke a static method, boxing the result if necessary.(package private) boolean
isAccessible
(Object instance, AccessibleObject fieldOrMethod) Check whether a field or method is accessible.(package private) abstract boolean
makeAccessible
(Object instance, AccessibleObject fieldOrMethod) Make a field or method accessible.(package private) abstract void
Set the value of a non-static field, unboxing the value if necessary.(package private) abstract void
setStaticField
(Field field, Object value) Set the value of a static field, unboxing the value if necessary.
-
Field Details
-
classToClassMemberCache
private final SingletonMap<Class<?>,ReflectionDriver.ClassMemberCache, classToClassMemberCacheException> -
isAccessibleMethod
-
canAccessMethod
-
-
Constructor Details
-
ReflectionDriver
ReflectionDriver()
-
-
Method Details
-
findClass
Find a class by name.- Parameters:
className
- the class name- Returns:
- the class reference
- Throws:
Exception
-
getDeclaredMethods
Get declared methods for class.- Parameters:
cls
- the class- Returns:
- the declared methods
- Throws:
Exception
-
getDeclaredConstructors
Get declared constructors for class.- Type Parameters:
T
- the generic type- Parameters:
cls
- the class- Returns:
- the declared constructors
- Throws:
Exception
-
getDeclaredFields
Get declared fields for class.- Parameters:
cls
- the class- Returns:
- the declared fields
- Throws:
Exception
-
getField
Get the value of a non-static field, boxing the value if necessary.- Parameters:
object
- the object instance to get the field value fromfield
- the non-static field- Returns:
- the value of the field
- Throws:
Exception
-
setField
Set the value of a non-static field, unboxing the value if necessary.- Parameters:
object
- the object instance to get the field value fromfield
- the non-static fieldvalue
- the value to set- Throws:
Exception
-
getStaticField
Get the value of a static field, boxing the value if necessary.- Parameters:
field
- the static field- Returns:
- the static field
- Throws:
Exception
-
setStaticField
Set the value of a static field, unboxing the value if necessary.- Parameters:
field
- the static fieldvalue
- the value to set- Throws:
Exception
-
invokeMethod
Invoke a non-static method, boxing the result if necessary.- Parameters:
object
- the object instance to invoke the method onmethod
- the non-static methodargs
- the method arguments (ornew Object[0]
if there are no args)- Returns:
- the return value (possibly a boxed value)
- Throws:
Exception
-
invokeStaticMethod
Invoke a static method, boxing the result if necessary.- Parameters:
method
- the static methodargs
- the method arguments (ornew Object[0]
if there are no args)- Returns:
- the return value (possibly a boxed value)
- Throws:
Exception
-
makeAccessible
Make a field or method accessible.- Parameters:
instance
- the object instance, or null if static.fieldOrMethod
- the field or method.- Returns:
- true if successful.
-
isAccessible
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
- the object instance, or null if static.fieldOrMethod
- the field or method.- Returns:
- true if accessible.
-
findField
Get the field of the class that has a given field name. -
findStaticField
Get the static field of the class that has a given field name. -
findInstanceField
Get the non-static field of the class that has a given field name. -
findMethod
protected Method findMethod(Class<?> cls, Object obj, String methodName, Class<?>... paramTypes) throws Exception Get a method by name and parameter types.- Parameters:
cls
- the class.obj
- the object instance, or null for a static method.methodName
- The name of the method.paramTypes
- The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.- Returns:
- The
Method
object for the matching method, or null if no such method was found in the class. - Throws:
Exception
- if the method could not be found.
-
findStaticMethod
protected Method findStaticMethod(Class<?> cls, String methodName, Class<?>... paramTypes) throws Exception Get a static method by name and parameter types.- Parameters:
cls
- the class.methodName
- The name of the method.paramTypes
- The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.- Returns:
- The
Method
object for the matching method, or null if no such method was found in the class. - Throws:
Exception
- if the method could not be found.
-
findInstanceMethod
protected Method findInstanceMethod(Object obj, String methodName, Class<?>... paramTypes) throws Exception Get a non-static method by name and parameter types.- Parameters:
obj
- the object instance, or null for a static method.methodName
- The name of the method.paramTypes
- The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.- Returns:
- The
Method
object for the matching method, or null if no such method was found in the class. - Throws:
Exception
- if the method could not be found.
-