Class NarcissusReflectionDriver
- java.lang.Object
-
- nonapi.io.github.classgraph.reflection.ReflectionDriver
-
- nonapi.io.github.classgraph.reflection.NarcissusReflectionDriver
-
class NarcissusReflectionDriver extends ReflectionDriver
Narcissus reflection driver (uses the Narcissus library, if it is available, which allows access to non-public fields and methods, circumventing encapsulation and visibility controls via JNI).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class nonapi.io.github.classgraph.reflection.ReflectionDriver
ReflectionDriver.ClassMemberCache
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.MethodfindClassprivate java.lang.reflect.MethodgetDeclaredConstructorsprivate java.lang.reflect.MethodgetDeclaredFieldsprivate java.lang.reflect.MethodgetDeclaredMethodsprivate java.lang.reflect.MethodgetFieldprivate java.lang.reflect.MethodgetStaticFieldprivate java.lang.reflect.MethodinvokeMethodprivate java.lang.reflect.MethodinvokeStaticMethodprivate java.lang.Class<?>narcissusClassprivate java.lang.reflect.MethodsetFieldprivate java.lang.reflect.MethodsetStaticField
-
Constructor Summary
Constructors Constructor Description NarcissusReflectionDriver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.Class<?>findClass(java.lang.String className)Find a class by name.(package private) <T> java.lang.reflect.Constructor<T>[]getDeclaredConstructors(java.lang.Class<T> cls)Get declared constructors for class.(package private) java.lang.reflect.Field[]getDeclaredFields(java.lang.Class<?> cls)Get declared fields for class.(package private) java.lang.reflect.Method[]getDeclaredMethods(java.lang.Class<?> cls)Get declared methods for class.(package private) java.lang.ObjectgetField(java.lang.Object object, java.lang.reflect.Field field)Get the value of a non-static field, boxing the value if necessary.(package private) java.lang.ObjectgetStaticField(java.lang.reflect.Field field)Get the value of a static field, boxing the value if necessary.(package private) java.lang.ObjectinvokeMethod(java.lang.Object object, java.lang.reflect.Method method, java.lang.Object... args)Invoke a non-static method, boxing the result if necessary.(package private) java.lang.ObjectinvokeStaticMethod(java.lang.reflect.Method method, java.lang.Object... args)Invoke a static method, boxing the result if necessary.booleanisAccessible(java.lang.Object instance, java.lang.reflect.AccessibleObject obj)Check whether a field or method is accessible.booleanmakeAccessible(java.lang.Object instance, java.lang.reflect.AccessibleObject accessibleObject)Make a field or method accessible.(package private) voidsetField(java.lang.Object object, java.lang.reflect.Field field, java.lang.Object value)Set the value of a non-static field, unboxing the value if necessary.(package private) voidsetStaticField(java.lang.reflect.Field field, java.lang.Object value)Set the value of a static field, unboxing the value if necessary.-
Methods inherited from class nonapi.io.github.classgraph.reflection.ReflectionDriver
findField, findInstanceField, findInstanceMethod, findMethod, findStaticField, findStaticMethod
-
-
-
-
Field Detail
-
narcissusClass
private final java.lang.Class<?> narcissusClass
-
getDeclaredMethods
private final java.lang.reflect.Method getDeclaredMethods
-
findClass
private final java.lang.reflect.Method findClass
-
getDeclaredConstructors
private final java.lang.reflect.Method getDeclaredConstructors
-
getDeclaredFields
private final java.lang.reflect.Method getDeclaredFields
-
getField
private final java.lang.reflect.Method getField
-
setField
private final java.lang.reflect.Method setField
-
getStaticField
private final java.lang.reflect.Method getStaticField
-
setStaticField
private final java.lang.reflect.Method setStaticField
-
invokeMethod
private final java.lang.reflect.Method invokeMethod
-
invokeStaticMethod
private final java.lang.reflect.Method invokeStaticMethod
-
-
Method Detail
-
isAccessible
public boolean isAccessible(java.lang.Object instance, java.lang.reflect.AccessibleObject obj)Description copied from class:ReflectionDriverCheck 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.
- Overrides:
isAccessiblein classReflectionDriver- Parameters:
instance- the object instance, or null if static.obj- the field or method.- Returns:
- true if accessible.
-
makeAccessible
public boolean makeAccessible(java.lang.Object instance, java.lang.reflect.AccessibleObject accessibleObject)Description copied from class:ReflectionDriverMake a field or method accessible.- Specified by:
makeAccessiblein classReflectionDriver- Parameters:
instance- the object instance, or null if static.accessibleObject- the field or method.- Returns:
- true if successful.
-
findClass
java.lang.Class<?> findClass(java.lang.String className) throws java.lang.ExceptionDescription copied from class:ReflectionDriverFind a class by name.- Specified by:
findClassin classReflectionDriver- Parameters:
className- the class name- Returns:
- the class reference
- Throws:
java.lang.Exception
-
getDeclaredMethods
java.lang.reflect.Method[] getDeclaredMethods(java.lang.Class<?> cls) throws java.lang.ExceptionDescription copied from class:ReflectionDriverGet declared methods for class.- Specified by:
getDeclaredMethodsin classReflectionDriver- Parameters:
cls- the class- Returns:
- the declared methods
- Throws:
java.lang.Exception
-
getDeclaredConstructors
<T> java.lang.reflect.Constructor<T>[] getDeclaredConstructors(java.lang.Class<T> cls) throws java.lang.ExceptionDescription copied from class:ReflectionDriverGet declared constructors for class.- Specified by:
getDeclaredConstructorsin classReflectionDriver- Type Parameters:
T- the generic type- Parameters:
cls- the class- Returns:
- the declared constructors
- Throws:
java.lang.Exception
-
getDeclaredFields
java.lang.reflect.Field[] getDeclaredFields(java.lang.Class<?> cls) throws java.lang.ExceptionDescription copied from class:ReflectionDriverGet declared fields for class.- Specified by:
getDeclaredFieldsin classReflectionDriver- Parameters:
cls- the class- Returns:
- the declared fields
- Throws:
java.lang.Exception
-
getField
java.lang.Object getField(java.lang.Object object, java.lang.reflect.Field field) throws java.lang.ExceptionDescription copied from class:ReflectionDriverGet the value of a non-static field, boxing the value if necessary.- Specified by:
getFieldin classReflectionDriver- Parameters:
object- the object instance to get the field value fromfield- the non-static field- Returns:
- the value of the field
- Throws:
java.lang.Exception
-
setField
void setField(java.lang.Object object, java.lang.reflect.Field field, java.lang.Object value) throws java.lang.ExceptionDescription copied from class:ReflectionDriverSet the value of a non-static field, unboxing the value if necessary.- Specified by:
setFieldin classReflectionDriver- Parameters:
object- the object instance to get the field value fromfield- the non-static fieldvalue- the value to set- Throws:
java.lang.Exception
-
getStaticField
java.lang.Object getStaticField(java.lang.reflect.Field field) throws java.lang.ExceptionDescription copied from class:ReflectionDriverGet the value of a static field, boxing the value if necessary.- Specified by:
getStaticFieldin classReflectionDriver- Parameters:
field- the static field- Returns:
- the static field
- Throws:
java.lang.Exception
-
setStaticField
void setStaticField(java.lang.reflect.Field field, java.lang.Object value) throws java.lang.ExceptionDescription copied from class:ReflectionDriverSet the value of a static field, unboxing the value if necessary.- Specified by:
setStaticFieldin classReflectionDriver- Parameters:
field- the static fieldvalue- the value to set- Throws:
java.lang.Exception
-
invokeMethod
java.lang.Object invokeMethod(java.lang.Object object, java.lang.reflect.Method method, java.lang.Object... args) throws java.lang.ExceptionDescription copied from class:ReflectionDriverInvoke a non-static method, boxing the result if necessary.- Specified by:
invokeMethodin classReflectionDriver- 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:
java.lang.Exception
-
invokeStaticMethod
java.lang.Object invokeStaticMethod(java.lang.reflect.Method method, java.lang.Object... args) throws java.lang.ExceptionDescription copied from class:ReflectionDriverInvoke a static method, boxing the result if necessary.- Specified by:
invokeStaticMethodin classReflectionDriver- 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:
java.lang.Exception
-
-