diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2017-07-11 22:01:19 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2017-07-11 22:01:19 +1000 |
commit | 7b0378b06e28702379f8fd3ce67d0ed93537ddf1 (patch) | |
tree | ff79b12165ffe5b8a340d3c0fef2f38f931277d0 /src/Java/gtPlusPlus/core/util/reflect | |
parent | fd46163f7afe8b45f2b965c1bcb242ea0c6cbf78 (diff) | |
download | GT5-Unofficial-7b0378b06e28702379f8fd3ce67d0ed93537ddf1.tar.gz GT5-Unofficial-7b0378b06e28702379f8fd3ce67d0ed93537ddf1.tar.bz2 GT5-Unofficial-7b0378b06e28702379f8fd3ce67d0ed93537ddf1.zip |
+ Added a few more circuit recipes to make compatibility 100%.
+ Tried adding a way to empty the Circuit Assembler recipe map.
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/reflect')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 88059acb49..ba48892112 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -97,5 +97,43 @@ public class ReflectionUtils { //System. out.println(ste[ste.length-depth].getClassName()+"#"+ste[ste.length-depth].getMethodName()); return ste[depth].getMethodName(); } + + + /** + * Allows to change the state of an immutable instance. Huh?!? + */ + public static void setFieldValue(Class clazz, String fieldName, Object newValue) throws Exception { + Field nameField = clazz.getDeclaredField(fieldName); + setValue(clazz, nameField, newValue); + } + + /** + * Allows to change the state of final statics. Huh?!? + */ + public static void setDefault(Class clazz, String fieldName, Object newValue) throws Exception { + Field staticField = clazz.getDeclaredField(fieldName); + setValue(null, staticField, newValue); + } + + /** + * + * Set the value of a field reflectively. + */ + protected static void setValue(Object owner, Field field, Object value) throws Exception { + makeModifiable(field); + field.set(owner, value); + } + + /** + * Force the field to be modifiable and accessible. + */ + protected static void makeModifiable(Field nameField) throws Exception { + nameField.setAccessible(true); + int modifiers = nameField.getModifiers(); + Field modifierField = nameField.getClass().getDeclaredField("modifiers"); + modifiers = modifiers & ~Modifier.FINAL; + modifierField.setAccessible(true); + modifierField.setInt(nameField, modifiers); + } } |