aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util/reflect
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/reflect')
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
index b52c13c563..7ef9ef6632 100644
--- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
+++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
@@ -169,6 +169,17 @@ public class ReflectionUtils {
return y.get();
}
}
+
+ public static boolean isStaticMethod(Class<?> aClass, String aMethodName, Class<?>... aTypes) {
+ return isStaticMethod(ReflectionUtils.getMethod(aClass, aMethodName, aTypes));
+ }
+
+ public static boolean isStaticMethod(Method aMethod) {
+ if (aMethod != null && Modifier.isStatic(aMethod.getModifiers())) {
+ return true;
+ }
+ return false;
+ }
@@ -381,7 +392,6 @@ public class ReflectionUtils {
public static boolean invoke(Object objectInstance, String methodName, Class[] parameters, Object[] values){
if (objectInstance == null || methodName == null || parameters == null || values == null){
- //Logger.REFLECTION("Null value when trying to Dynamically invoke "+methodName+" on an object of type: "+objectInstance.getClass().getName());
return false;
}
Class<?> mLocalClass = (objectInstance instanceof Class ? (Class<?>) objectInstance : objectInstance.getClass());
@@ -389,6 +399,28 @@ public class ReflectionUtils {
try {
Method mInvokingMethod = mLocalClass.getDeclaredMethod(methodName, parameters);
if (mInvokingMethod != null){
+ return invoke(objectInstance, mInvokingMethod, values);
+ }
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalArgumentException e) {
+ Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+mLocalClass.getName());
+ }
+
+ Logger.REFLECTION("Invoke failed or did something wrong.");
+ return false;
+ }
+
+ public static boolean invoke(Object objectInstance, Method method, Object[] values){
+ if (method == null || values == null || (!ReflectionUtils.isStaticMethod(method) && objectInstance == null)){
+ //Logger.REFLECTION("Null value when trying to Dynamically invoke "+methodName+" on an object of type: "+objectInstance.getClass().getName());
+ return false;
+ }
+ String methodName = method.getName();
+ String classname = objectInstance != null ? objectInstance.getClass().getCanonicalName() : method.getDeclaringClass().getCanonicalName();
+ Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+classname+".");
+ try {
+ Method mInvokingMethod = method;
+ if (mInvokingMethod != null){
Logger.REFLECTION(methodName+" was not null.");
if ((boolean) mInvokingMethod.invoke(objectInstance, values)){
Logger.REFLECTION("Successfully invoked "+methodName+".");
@@ -398,14 +430,10 @@ public class ReflectionUtils {
Logger.REFLECTION("Invocation failed for "+methodName+".");
}
}
- else {
- Logger.REFLECTION(methodName+" is null.");
- }
}
- catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+mLocalClass.getName());
- }
-
+ catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+classname);
+ }
Logger.REFLECTION("Invoke failed or did something wrong.");
return false;
}