From 7b0378b06e28702379f8fd3ce67d0ed93537ddf1 Mon Sep 17 00:00:00 2001 From: Draknyte1 Date: Tue, 11 Jul 2017 22:01:19 +1000 Subject: + Added a few more circuit recipes to make compatibility 100%. + Tried adding a way to empty the Circuit Assembler recipe map. --- .../core/util/reflect/ReflectionUtils.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/Java/gtPlusPlus/core/util') 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); + } } -- cgit