diff options
| author | Alexdoru <57050655+Alexdoru@users.noreply.github.com> | 2024-09-28 13:25:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-28 11:25:01 +0000 |
| commit | 86f1765b171f4cc6f163b8027d1330f4e5094e2d (patch) | |
| tree | b6e293bd3c976558fc4e4b7190e4d342c2ddc555 /src/main/java/gtPlusPlus | |
| parent | 6b1f145f5028f1bc92cf478e5963224e7d94b5cd (diff) | |
| download | GT5-Unofficial-86f1765b171f4cc6f163b8027d1330f4e5094e2d.tar.gz GT5-Unofficial-86f1765b171f4cc6f163b8027d1330f4e5094e2d.tar.bz2 GT5-Unofficial-86f1765b171f4cc6f163b8027d1330f4e5094e2d.zip | |
Remove more reflection + reorganize mixin accessors packages (#3260)
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: boubou19 <miisterunknown@gmail.com>
Diffstat (limited to 'src/main/java/gtPlusPlus')
23 files changed, 92 insertions, 1052 deletions
diff --git a/src/main/java/gtPlusPlus/GTplusplus.java b/src/main/java/gtPlusPlus/GTplusplus.java index 893446ea72..5de4fef23b 100644 --- a/src/main/java/gtPlusPlus/GTplusplus.java +++ b/src/main/java/gtPlusPlus/GTplusplus.java @@ -4,12 +4,13 @@ import static gregtech.api.enums.Mods.GTPlusPlus; import static gregtech.api.enums.Mods.Names; import static gregtech.api.enums.Mods.Thaumcraft; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.HashMap; import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.launchwrapper.Launch; import com.gtnewhorizon.gtnhlib.config.ConfigException; @@ -25,7 +26,6 @@ import cpw.mods.fml.common.event.FMLMissingMappingsEvent.MissingMapping; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; -import cpw.mods.fml.common.event.FMLServerStoppingEvent; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -44,7 +44,9 @@ import gtPlusPlus.core.handler.Recipes.RegistrationHandler; import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.data.LocaleUtils; -import gtPlusPlus.plugin.manager.CoreManager; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.plugin.agrichem.block.AgrichemFluids; +import gtPlusPlus.plugin.fixes.vanilla.VanillaBedHeightFix; import gtPlusPlus.xmod.gregtech.common.MetaGTProxy; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtTools; @@ -76,7 +78,7 @@ import gtPlusPlus.xmod.thaumcraft.commands.CommandDumpAspects; + " after:TGregworks;" + " after:StevesCarts;" + " required-after:gtnhlib@[0.0.10,);") -public class GTplusplus implements ActionListener { +public class GTplusplus { public enum INIT_PHASE { @@ -149,8 +151,6 @@ public class GTplusplus implements ActionListener { @EventHandler public void preInit(final FMLPreInitializationEvent event) { INIT_PHASE.PRE_INIT.setPhaseActive(true); - // Load all class objects within the plugin package. - CoreManager.veryEarlyInit(); PacketHandler.init(); // Give this a go mate. @@ -162,7 +162,9 @@ public class GTplusplus implements ActionListener { proxy.preInit(event); Logger.INFO("Setting up our own GTProxy."); MetaGTProxy.preInit(); - CoreManager.preInit(); + AgrichemFluids.preInit(); + fixVanillaOreDict(); + new VanillaBedHeightFix(); } @EventHandler @@ -171,7 +173,6 @@ public class GTplusplus implements ActionListener { proxy.init(event); proxy.registerNetworkStuff(); MetaGTProxy.init(); - CoreManager.init(); // Used by foreign players to generate .lang files for translation. if (Configuration.debug.dumpItemAndBlockData) { LocaleUtils.generateFakeLocaleFile(); @@ -184,7 +185,6 @@ public class GTplusplus implements ActionListener { proxy.postInit(event); BookHandler.runLater(); MetaGTProxy.postInit(); - CoreManager.postInit(); Logger.INFO("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Logger.INFO( @@ -218,18 +218,9 @@ public class GTplusplus implements ActionListener { if (Thaumcraft.isModLoaded()) { event.registerServerCommand(new CommandDumpAspects()); } - CoreManager.serverStart(); INIT_PHASE.STARTED.setPhaseActive(true); } - @EventHandler - public synchronized void serverStopping(final FMLServerStoppingEvent event) { - CoreManager.serverStop(); - } - - @Override - public void actionPerformed(final ActionEvent arg0) {} - /** * This {@link EventHandler} is called after the {@link FMLPostInitializationEvent} stages of all loaded mods * executes successfully. {@link #onLoadComplete(FMLLoadCompleteEvent)} exists to inject recipe generation after @@ -383,4 +374,39 @@ public class GTplusplus implements ActionListener { mapping.remap(block); Logger.INFO("Remapping block " + mapping.name + " to " + GTPlusPlus.ID + ":" + block.getUnlocalizedName()); } + + private static void fixVanillaOreDict() { + registerToOreDict(ItemUtils.getSimpleStack(Items.blaze_rod), "rodBlaze"); + registerToOreDict(ItemUtils.getSimpleStack(Items.nether_wart), "cropNetherWart"); + registerToOreDict(ItemUtils.getSimpleStack(Items.reeds), "sugarcane"); + registerToOreDict(ItemUtils.getSimpleStack(Items.paper), "paper"); + registerToOreDict(ItemUtils.getSimpleStack(Items.ender_pearl), "enderpearl"); + registerToOreDict(ItemUtils.getSimpleStack(Items.bone), "bone"); + registerToOreDict(ItemUtils.getSimpleStack(Items.gunpowder), "gunpowder"); + registerToOreDict(ItemUtils.getSimpleStack(Items.string), "string"); + registerToOreDict(ItemUtils.getSimpleStack(Items.nether_star), "netherStar"); + registerToOreDict(ItemUtils.getSimpleStack(Items.leather), "leather"); + registerToOreDict(ItemUtils.getSimpleStack(Items.feather), "feather"); + registerToOreDict(ItemUtils.getSimpleStack(Items.egg), "egg"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.end_stone), "endstone"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.vine), "vine"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.cactus), "blockCactus"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.grass), "grass"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.obsidian), "obsidian"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.crafting_table), "workbench"); + } + + private static void registerToOreDict(ItemStack aStack, String aString) { + if (aStack.getItem() == Items.blaze_rod) { + Logger + .INFO("Registering " + aStack.getDisplayName() + " to OreDictionary under the tag '" + aString + "'."); + } else { + Logger.INFO( + "Registering " + aStack.getDisplayName() + + " to OreDictionary under the tag '" + + aString + + "'. (Added to Forge in 1.8.9)"); + } + ItemUtils.addItemToOreDictionary(aStack, aString); + } } diff --git a/src/main/java/gtPlusPlus/api/interfaces/IPlugin.java b/src/main/java/gtPlusPlus/api/interfaces/IPlugin.java deleted file mode 100644 index d70a19925e..0000000000 --- a/src/main/java/gtPlusPlus/api/interfaces/IPlugin.java +++ /dev/null @@ -1,41 +0,0 @@ -package gtPlusPlus.api.interfaces; - -import gtPlusPlus.api.objects.Logger; - -public interface IPlugin { - - /** - * @return A {@link String} object which returns the {@link IPlugin}'s name. - */ - public String getPluginName(); - - /** - * @return A {@link String} object which returns the {@link IPlugin}'s short name. This String should only contain 4 - * Characters. - */ - public String getPluginAbbreviation(); - - /** - * @param message - A {@link String} object which holds a message to be logged to console. - */ - default void log(String message) { - Logger.INFO("[" + getPluginAbbreviation() + "] " + message); - } - - /** - * @param message - A {@link String} object which holds a warning/error message to be logged to console. - */ - default void logDebug(String message) { - Logger.WARNING("[" + getPluginAbbreviation() + "] " + message); - } - - public boolean preInit(); - - public boolean init(); - - public boolean postInit(); - - public boolean serverStart(); - - public boolean serverStop(); -} diff --git a/src/main/java/gtPlusPlus/api/objects/Logger.java b/src/main/java/gtPlusPlus/api/objects/Logger.java index 2214e50e78..6650668894 100644 --- a/src/main/java/gtPlusPlus/api/objects/Logger.java +++ b/src/main/java/gtPlusPlus/api/objects/Logger.java @@ -23,7 +23,7 @@ public class Logger { private static final boolean enabled = !ASMConfiguration.debug.disableAllLogging; - public static final org.apache.logging.log4j.Logger getLogger() { + public static org.apache.logging.log4j.Logger getLogger() { return modLogger; } @@ -38,8 +38,7 @@ public class Logger { public static void MACHINE_INFO(String s, Object... args) { if (enabled) { if (Configuration.debug.MachineInfo || GTCorePlugin.isDevEnv()) { - final String name1 = gtPlusPlus.core.util.reflect.ReflectionUtils.getMethodName(2); - modLogger.info("Machine Info: " + s + " | " + name1, args); + modLogger.info("Machine Info: " + s + " ", args); } } } diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java b/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java index 6852c93f05..867f247b6e 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java @@ -6,7 +6,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.ShapedOreRecipe; -import gregtech.api.interfaces.IRecipeMutableAccess; +import gregtech.mixin.interfaces.accessors.IRecipeMutableAccess; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.util.minecraft.ItemUtils; @@ -25,14 +25,11 @@ public class ShapedRecipe implements IRecipeMutableAccess { } public ShapedRecipe(Object[] aInputs, ItemStack aOutput) { - String aGridWhole = ""; - String aGrid[] = new String[3]; + StringBuilder aGridWhole = new StringBuilder(); + String[] aGrid = new String[3]; char[] aChar = new char[9]; String[] aLoggingInfo = new String[9]; - - if (mBlackList == null) { - mBlackList = new ItemStack[] {}; - } + mBlackList = new ItemStack[] {}; // Just to be safe try { @@ -68,7 +65,7 @@ public class ShapedRecipe implements IRecipeMutableAccess { Object[] mVarags2 = null; Logger.RECIPE("Generating Shaped Crafting Recipe for " + aOutput.getDisplayName()); - if (aInputs.length < 9 || aInputs.length > 9) { + if (aInputs.length != 9) { Logger.RECIPE( "[Fix] Recipe for " + aOutput.getDisplayName() + " has incorrect number of inputs. Size: " @@ -118,7 +115,7 @@ public class ShapedRecipe implements IRecipeMutableAccess { for (Pair<Character, Object> h : aRecipePairs) { if (h.getKey() != null) { - aGridWhole += String.valueOf(h.getKey()); + aGridWhole.append(String.valueOf(h.getKey())); Logger.RECIPE("Adding '" + String.valueOf(h.getKey()) + "' to aGridWhole."); } } diff --git a/src/main/java/gtPlusPlus/core/config/ASMConfiguration.java b/src/main/java/gtPlusPlus/core/config/ASMConfiguration.java index a348998ef0..63d65b32c9 100644 --- a/src/main/java/gtPlusPlus/core/config/ASMConfiguration.java +++ b/src/main/java/gtPlusPlus/core/config/ASMConfiguration.java @@ -11,7 +11,6 @@ import gregtech.api.enums.Mods; public class ASMConfiguration { public static Debug debug = new Debug(); - public static General general = new General(); // Debug @Config.Comment("Debug section") @@ -27,14 +26,4 @@ public class ASMConfiguration { } - @Config.Comment("General section") - public static class General { - // General Features - - @Config.Comment("Set to a value greater than 0 to reduce the ticks taken to delay between BGM tracks. Acceptable Values are 1-32767, where 0 is disabled. Vanilla Uses 12,000 & 24,000. 200 is 10s.") - @Config.DefaultInt(0) - @Config.RangeInt(min = 0, max = Short.MAX_VALUE) - public int enableWatchdogBGM; - - } } diff --git a/src/main/java/gtPlusPlus/core/handler/PacketHandler.java b/src/main/java/gtPlusPlus/core/handler/PacketHandler.java index 9c5d6b25d2..504afc55d8 100644 --- a/src/main/java/gtPlusPlus/core/handler/PacketHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/PacketHandler.java @@ -9,12 +9,9 @@ import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.relauncher.Side; -import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.network.handler.AbstractClientMessageHandler; -import gtPlusPlus.core.network.packet.AbstractPacket; import gtPlusPlus.core.network.packet.PacketVolumetricFlaskGui; import gtPlusPlus.core.network.packet.PacketVolumetricFlaskGui2; -import gtPlusPlus.core.util.reflect.ReflectionUtils; public class PacketHandler { @@ -37,14 +34,6 @@ public class PacketHandler { private static void registerMessage(Class handlerClass, Class messageClass, Side side) { INSTANCE.registerMessage(handlerClass, messageClass, packetId++, side); - if (AbstractPacket.class.isInstance(messageClass.getClass())) { - AbstractPacket aPacket = ReflectionUtils.createNewInstanceFromConstructor( - ReflectionUtils.getConstructor(messageClass, new Class[] {}), - new Object[] {}); - if (aPacket != null) { - Logger.INFO("Registered Packet: " + aPacket.getPacketName()); - } - } } /** diff --git a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java index 33649b4ff2..41755d6abc 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java @@ -11,7 +11,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import gregtech.mixin.interfaces.PotionExt; +import gregtech.mixin.interfaces.accessors.PotionAccessor; import gtPlusPlus.core.util.math.MathUtils; public class PlayerSleepEventHandler { @@ -43,7 +43,7 @@ public class PlayerSleepEventHandler { final List<Integer> potionToRemove = new ArrayList<>(); for (PotionEffect potionEffect : player.getActivePotionEffects()) { final Potion potion = Potion.potionTypes[potionEffect.getPotionID()]; - if (potion instanceof PotionExt && ((PotionExt) potion).gt5u$isBadEffect()) { + if (potion instanceof PotionAccessor && ((PotionAccessor) potion).gt5u$isBadEffect()) { potionToRemove.add(potion.id); } } diff --git a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 40b32fed86..5dd9f9f426 100644 --- a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -1,56 +1,19 @@ package gtPlusPlus.core.util.reflect; -import java.io.IOException; -import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.Map; -import org.apache.commons.lang3.ArrayUtils; - -import com.google.common.reflect.ClassPath; import com.gtnewhorizon.gtnhlib.reflect.Fields; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.util.data.StringUtils; @SuppressWarnings({ "unchecked", "rawtypes" }) public class ReflectionUtils { - public static Map<String, CachedMethod> mCachedMethods = new LinkedHashMap<>(); - public static Map<String, CachedField> mCachedFields = new LinkedHashMap<>(); - public static Map<String, CachedConstructor> mCachedConstructors = new LinkedHashMap<>(); - public static Map<Field, Fields.ClassFields.Field> mCachedFieldAccessors = new LinkedHashMap<>(); - - private static class CachedConstructor { - - private final Constructor<?> METHOD; - - public CachedConstructor(Constructor<?> aCons) { - METHOD = aCons; - } - - public Constructor<?> get() { - return METHOD; - } - } - - private static class CachedMethod { - - private final Method METHOD; - - public CachedMethod(Method aMethod, boolean isStatic) { - METHOD = aMethod; - } - - public Method get() { - return METHOD; - } - - } + public static Map<String, CachedField> mCachedFields = new HashMap<>(); + public static Map<Field, Fields.ClassFields.Field> mCachedFieldAccessors = new HashMap<>(); private static class CachedField { @@ -73,22 +36,6 @@ public class ReflectionUtils { .getUntypedField(Fields.LookupType.DECLARED_IN_HIERARCHY, field.getName())); } - private static boolean cacheMethod(Class<?> aClass, Method aMethod) { - if (aMethod == null) { - return false; - } - boolean isStatic = Modifier.isStatic(aMethod.getModifiers()); - CachedMethod y = mCachedMethods - .get(aClass.getName() + "." + aMethod.getName() + "." + ArrayUtils.toString(aMethod.getParameterTypes())); - if (y == null) { - mCachedMethods.put( - aClass.getName() + "." + aMethod.getName() + "." + ArrayUtils.toString(aMethod.getParameterTypes()), - new CachedMethod(aMethod, isStatic)); - return true; - } - return false; - } - private static boolean cacheField(Class<?> aClass, Field aField) { if (aField == null) { return false; @@ -102,85 +49,6 @@ public class ReflectionUtils { return false; } - private static void cacheConstructor(Class<?> aClass, Constructor<?> aConstructor) { - if (aConstructor == null) { - return; - } - mCachedConstructors.computeIfAbsent( - aClass.getName() + "." + ArrayUtils.toString(aConstructor.getParameterTypes()), - k -> new CachedConstructor(aConstructor)); - } - - /** - * Returns a cached {@link Constructor} object. - * - * @param aClass - Class containing the Constructor. - * @param aTypes - Varags Class Types for objects constructor. - * @return - Valid, non-final, {@link Method} object, or {@link null}. - */ - public static Constructor<?> getConstructor(Class<?> aClass, Class<?>... aTypes) { - if (aClass == null || aTypes == null) { - return null; - } - - String aMethodKey = ArrayUtils.toString(aTypes); - // Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); - CachedConstructor y = mCachedConstructors.get(aClass.getName() + "." + aMethodKey); - if (y == null) { - Constructor<?> u = getConstructor_Internal(aClass, aTypes); - if (u != null) { - Logger.REFLECTION("Caching Constructor: " + aClass.getName() + "." + aMethodKey); - cacheConstructor(aClass, u); - return u; - } else { - return null; - } - } else { - return y.get(); - } - } - - /** - * Returns a cached {@link Method} object. Wraps {@link #getMethod(Class, String, Class...)}. - * - * @param aObject - Object containing the Method. - * @param aMethodName - Method's name in {@link String} form. - * @param aTypes - Class Array of Types for {@link Method}'s constructor. - * @return - Valid, non-final, {@link Method} object, or {@link null}. - */ - public static Method getMethod(Object aObject, String aMethodName, Class[] aTypes) { - return getMethod(aObject.getClass(), aMethodName, aTypes); - } - - /** - * Returns a cached {@link Method} object. - * - * @param aClass - Class containing the Method. - * @param aMethodName - Method's name in {@link String} form. - * @param aTypes - Varags Class Types for {@link Method}'s constructor. - * @return - Valid, non-final, {@link Method} object, or {@link null}. - */ - public static Method getMethod(Class<?> aClass, String aMethodName, Class<?>... aTypes) { - if (aClass == null || aMethodName == null || aMethodName.length() <= 0) { - return null; - } - String aMethodKey = ArrayUtils.toString(aTypes); - // Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); - CachedMethod y = mCachedMethods.get(aClass.getName() + "." + aMethodName + "." + aMethodKey); - if (y == null) { - Method u = getMethod_Internal(aClass, aMethodName, aTypes); - if (u != null) { - Logger.REFLECTION("Caching Method: " + aMethodName + "." + aMethodKey); - cacheMethod(aClass, u); - return u; - } else { - return null; - } - } else { - return y.get(); - } - } - /** * Returns a cached {@link Field} object. * @@ -237,79 +105,6 @@ public class ReflectionUtils { } } - public static void makeMethodAccessible(final Method field) { - if (!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic( - field.getDeclaringClass() - .getModifiers())) { - field.setAccessible(true); - } - } - - /** - * Get the method name for a depth in call stack. <br /> - * Utility function - * - * @param depth depth in the call stack (0 means current method, 1 means call method, ...) - * @return Method name - */ - public static String getMethodName(final int depth) { - final StackTraceElement[] ste = new Throwable().getStackTrace(); - // System. out.println(ste[ste.length-depth].getClassName()+"#"+ste[ste.length-depth].getMethodName()); - if (ste.length < depth) { - return "No valid stack."; - } - return ste[depth + 1].getMethodName(); - } - - /** - * - * @param aPackageName - The full {@link Package} name in {@link String} form. - * @return - {@link Boolean} object. True if loaded > 0 classes. - */ - public static boolean dynamicallyLoadClassesInPackage(String aPackageName) { - ClassLoader classLoader = ReflectionUtils.class.getClassLoader(); - int loaded = 0; - try { - ClassPath path = ClassPath.from(classLoader); - for (ClassPath.ClassInfo info : path.getTopLevelClassesRecursive(aPackageName)) { - Class<?> clazz = Class.forName(info.getName(), true, classLoader); - if (clazz != null) { - loaded++; - Logger.INFO("Found " + clazz.getCanonicalName() + ". [" + loaded + "]"); - } - } - } catch (ClassNotFoundException | IOException e) { - - } - - return loaded > 0; - } - - public static boolean setField(final Object object, final String fieldName, final Object fieldValue) { - Class<?> clazz; - if (object instanceof Class) { - clazz = (Class<?>) object; - } else { - clazz = object.getClass(); - } - while (clazz != null) { - try { - final Field field = getField(clazz, fieldName); - if (field != null) { - setFieldValue_Internal(object, field, fieldValue); - return true; - } - } catch (final NoSuchFieldException e) { - Logger.REFLECTION("setField(" + object + ", " + fieldName + ") failed."); - clazz = clazz.getSuperclass(); - } catch (final Exception e) { - Logger.REFLECTION("setField(" + object + ", " + fieldName + ") failed."); - throw new IllegalStateException(e); - } - } - return false; - } - public static boolean setField(final Object object, final Field field, final Object fieldValue) { if (field == null) return false; Class<?> clazz; @@ -336,51 +131,6 @@ public class ReflectionUtils { return false; } - /** - * Allows to change the state of an immutable instance. Huh?!? - */ - public static void setFinalFieldValue(Class<?> clazz, String fieldName, Object newValue) { - Field nameField = getField(clazz, fieldName); - try { - setFieldValue_Internal(clazz, nameField, newValue); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - public static void setByte(Object clazz, String fieldName, byte newValue) { - Field nameField = getField(clazz.getClass(), fieldName); - cacheAccessor(nameField).setValue(null, newValue); - } - - public static boolean invokeVoid(Object objectInstance, String methodName, Class[] parameters, Object[] values) { - if (objectInstance == null || methodName == null || parameters == null || values == null) { - return false; - } - Class<?> mLocalClass = (objectInstance instanceof Class ? (Class<?>) objectInstance - : objectInstance.getClass()); - Logger.REFLECTION( - "Trying to invoke " + methodName + " on an instance of " + mLocalClass.getCanonicalName() + "."); - try { - Method mInvokingMethod = mLocalClass.getDeclaredMethod(methodName, parameters); - if (mInvokingMethod != null) { - Logger.REFLECTION(methodName + " was not null."); - mInvokingMethod.invoke(objectInstance, values); - Logger.REFLECTION("Successfully invoked " + methodName + "."); - return true; - } 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()); - } - - Logger.REFLECTION("Invoke failed or did something wrong."); - return false; - } - /* * Below Code block is used for determining generic types associated with type<E> */ @@ -407,108 +157,6 @@ public class ReflectionUtils { } } - private static Method getMethod_Internal(Class<?> aClass, String aMethodName, Class<?>... aTypes) { - Method m = null; - try { - Logger.REFLECTION("Method: Internal Lookup: " + aMethodName); - m = aClass.getDeclaredMethod(aMethodName, aTypes); - if (m != null) { - m.setAccessible(true); - } - } catch (Throwable t) { - Logger.REFLECTION("Method: Internal Lookup Failed: " + aMethodName); - try { - m = getMethodRecursively(aClass, aMethodName); - } catch (NoSuchMethodException e) { - Logger.REFLECTION("Unable to find method '" + aMethodName + "'"); - e.printStackTrace(); - dumpClassInfo(aClass); - } - } - return m; - } - - private static Constructor<?> getConstructor_Internal(Class<?> aClass, Class<?>... aTypes) { - Constructor<?> c = null; - try { - Logger.REFLECTION("Constructor: Internal Lookup: " + aClass.getName()); - c = aClass.getDeclaredConstructor(aTypes); - if (c != null) { - c.setAccessible(true); - } - } catch (Throwable t) { - Logger.REFLECTION("Constructor: Internal Lookup Failed: " + aClass.getName()); - try { - c = getConstructorRecursively(aClass, aTypes); - } catch (Exception e) { - Logger.REFLECTION("Unable to find method '" + aClass.getName() + "'"); - e.printStackTrace(); - dumpClassInfo(aClass); - } - } - return c; - } - - private static Constructor<?> getConstructorRecursively(Class<?> aClass, Class<?>... aTypes) throws Exception { - try { - Logger.REFLECTION("Constructor: Recur |
