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 Methodprivate 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 FieldGet the field of the class that has a given field name.protected FieldfindInstanceField(Object obj, String fieldName) Get the non-static field of the class that has a given field name.protected MethodfindInstanceMethod(Object obj, String methodName, Class<?>... paramTypes) Get a non-static method by name and parameter types.protected MethodfindMethod(Class<?> cls, Object obj, String methodName, Class<?>... paramTypes) Get a method by name and parameter types.protected FieldfindStaticField(Class<?> cls, String fieldName) Get the static field of the class that has a given field name.protected MethodfindStaticMethod(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 ObjectGet the value of a non-static field, boxing the value if necessary.(package private) abstract ObjectgetStaticField(Field field) Get the value of a static field, boxing the value if necessary.(package private) abstract ObjectinvokeMethod(Object object, Method method, Object... args) Invoke a non-static method, boxing the result if necessary.(package private) abstract ObjectinvokeStaticMethod(Method method, Object... args) Invoke a static method, boxing the result if necessary.(package private) booleanisAccessible(Object instance, AccessibleObject fieldOrMethod) Check whether a field or method is accessible.(package private) abstract booleanmakeAccessible(Object instance, AccessibleObject fieldOrMethod) Make a field or method accessible.(package private) abstract voidSet the value of a non-static field, unboxing the value if necessary.(package private) abstract voidsetStaticField(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, Exception> classToClassMemberCache -
isAccessibleMethod
-
canAccessMethod
-
-
Constructor Details
-
ReflectionDriver
ReflectionDriver()
-
-
Method Details
-
findClass
-
getDeclaredMethods
-
getDeclaredConstructors
Get declared constructors for class.- Type Parameters:
T- the generic type- Parameters:
cls- the class- Returns:
- the declared constructors
- Throws:
Exception
-
getDeclaredFields
-
getField
-
setField
-
getStaticField
-
setStaticField
-
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
Methodobject 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
Methodobject 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
Methodobject for the matching method, or null if no such method was found in the class. - Throws:
Exception- if the method could not be found.
-