diff options
author | Alkalus <draknyte1@hotmail.com> | 2020-03-31 02:40:07 +0000 |
---|---|---|
committer | Alkalus <draknyte1@hotmail.com> | 2020-03-31 02:40:07 +0000 |
commit | 6d6adf8039fb97f2025610eb313a4caa48df838b (patch) | |
tree | 80e377c85c8a89edeac671cc6b2f2655a150f41e /src/Java/gtPlusPlus/core/util/reflect | |
parent | 47816dec7729bde0bf247ff7db8ebf6b25b92048 (diff) | |
parent | 8a8048a6418ca8da9de0bd7b49f6ec39f9b0aad6 (diff) | |
download | GT5-Unofficial-6d6adf8039fb97f2025610eb313a4caa48df838b.tar.gz GT5-Unofficial-6d6adf8039fb97f2025610eb313a4caa48df838b.tar.bz2 GT5-Unofficial-6d6adf8039fb97f2025610eb313a4caa48df838b.zip |
Merged in AlkWork (pull request #4)
AlkWork
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/reflect')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 4d8a02d800..e45d27b926 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -365,7 +365,13 @@ public class ReflectionUtils { public static boolean setField(final Object object, final String fieldName, final Object fieldValue) { - Class<?> clazz = object.getClass(); + Class<?> clazz; + if (object instanceof Class) { + clazz = (Class<?>) object; + } + else { + clazz = object.getClass(); + } while (clazz != null) { try { final Field field = getField(clazz, fieldName); @@ -387,7 +393,13 @@ public class ReflectionUtils { } public static boolean setField(final Object object, final Field field, final Object fieldValue) { - Class<?> clazz = object.getClass(); + Class<?> clazz; + if (object instanceof Class) { + clazz = (Class<?>) object; + } + else { + clazz = object.getClass(); + } while (clazz != null) { try { final Field field2 = getField(clazz, field.getName()); @@ -522,6 +534,25 @@ public class ReflectionUtils { return false; } + + public static Object invokeNonBool(Object objectInstance, Method method, Object[] values){ + if (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()+"."); + 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("Invoke failed or did something wrong."); + return null; + } + public static Object invokeNonBool(Object objectInstance, String methodName, Class[] parameters, Object[] values){ if (objectInstance == null || methodName == null || parameters == null || values == null){ return false; @@ -973,9 +1004,9 @@ public class ReflectionUtils { */ private static void makeModifiable(Field nameField) throws Exception { nameField.setAccessible(true); - Field modifiers = getField(Field.class, "modifiers"); - modifiers.setAccessible(true); - modifiers.setInt(nameField, nameField.getModifiers() & ~Modifier.FINAL); + Field modifiers = getField(Field.class, "modifiers"); + modifiers.setAccessible(true); + modifiers.setInt(nameField, nameField.getModifiers() & ~Modifier.FINAL); } |