aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util/reflect
diff options
context:
space:
mode:
authorAlkalus <draknyte1@hotmail.com>2020-04-13 23:50:26 +0000
committerAlkalus <draknyte1@hotmail.com>2020-04-13 23:50:26 +0000
commite724a728061ec4a78cff73a4a2dd46eea4af4521 (patch)
treefee3354917be32870ec349b605990a091ace9e62 /src/Java/gtPlusPlus/core/util/reflect
parent24b1356471191a10fde6e4f1baf58ae74e87cfba (diff)
parent87ab3c0ab5f1b682295e2a010cc88cf4ae7db51c (diff)
downloadGT5-Unofficial-e724a728061ec4a78cff73a4a2dd46eea4af4521.tar.gz
GT5-Unofficial-e724a728061ec4a78cff73a4a2dd46eea4af4521.tar.bz2
GT5-Unofficial-e724a728061ec4a78cff73a4a2dd46eea4af4521.zip
Merged in MillingRecipes (pull request #7)
Milling Recipes & many other misc fixes
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/reflect')
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
index e45d27b926..e0634dfb14 100644
--- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
+++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
@@ -22,6 +22,7 @@ import com.google.common.reflect.ClassPath;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.util.data.StringUtils;
+import gtPlusPlus.xmod.gregtech.common.StaticFields59;
public class ReflectionUtils {
@@ -507,6 +508,30 @@ public class ReflectionUtils {
Logger.REFLECTION("Invoke failed or did something wrong.");
return false;
}
+
+ public static boolean invokeVoid(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.");
+ mInvokingMethod.invoke(objectInstance, values);
+ Logger.REFLECTION("Successfully invoked "+methodName+".");
+ return true;
+ }
+ }
+ 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;
+ }
public static boolean invokeVoid(Object objectInstance, String methodName, Class[] parameters, Object[] values){
if (objectInstance == null || methodName == null || parameters == null || values == null){
@@ -536,17 +561,17 @@ public class ReflectionUtils {
public static Object invokeNonBool(Object objectInstance, Method method, Object[] values){
- if (objectInstance == null || method == null || values == null){
+ if ((!ReflectionUtils.isStaticMethod(method) && objectInstance == null) || method == null || values == null){
return false;
}
String methodName = method.getName();
- Class<?> mLocalClass = (objectInstance instanceof Class ? (Class<?>) objectInstance : objectInstance.getClass());
- Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+mLocalClass.getCanonicalName()+".");
+ String classname = objectInstance != null ? objectInstance.getClass().getCanonicalName() : method.getDeclaringClass().getCanonicalName();
+ Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+classname+".");
try {
return method.invoke(objectInstance, values);
}
catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+mLocalClass.getName());
+ Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+classname);
}
Logger.REFLECTION("Invoke failed or did something wrong.");
@@ -1035,5 +1060,19 @@ public class ReflectionUtils {
return null;
}
+ public static <T> T createNewInstanceFromConstructor(Constructor aConstructor, Object[] aArgs) {
+ T aInstance;
+ try {
+ aInstance = (T) aConstructor.newInstance(aArgs);
+ if (aInstance != null) {
+ return aInstance;
+ }
+ }
+ catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
}