aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util/reflect
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2019-03-01 03:00:51 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2019-03-01 03:00:51 +0000
commit35522722af5dddea144c841a71f4fa9087e68966 (patch)
tree39f2e3908901026411d9b0ca77d4416ffb8d18cb /src/Java/gtPlusPlus/core/util/reflect
parenta5f5766e189593f8cfe7fbef862b1bb77207720e (diff)
downloadGT5-Unofficial-35522722af5dddea144c841a71f4fa9087e68966.tar.gz
GT5-Unofficial-35522722af5dddea144c841a71f4fa9087e68966.tar.bz2
GT5-Unofficial-35522722af5dddea144c841a71f4fa9087e68966.zip
% More work on TiCon Compat.
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/reflect')
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
index 372bf81fe9..88175b0a82 100644
--- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
+++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
@@ -12,6 +12,7 @@ import java.util.Map;
import com.google.common.reflect.ClassPath;
import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.util.data.StringUtils;
public class ReflectionUtils {
@@ -116,6 +117,19 @@ public class ReflectionUtils {
}
+
+ /**
+ * 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.
@@ -127,7 +141,7 @@ public class ReflectionUtils {
String aMethodKey = aTypes.toString();
CachedMethod y = mCachedMethods.get(aMethodName + "." + aMethodKey);
if (y == null) {
- Method u = getMethod_Internal(aClass, aMethodKey, aTypes);
+ Method u = getMethod_Internal(aClass, aMethodName, aTypes);
if (u != null) {
Logger.REFLECTION("Caching Method: "+aMethodName + "." + aMethodKey);
cacheMethod(u);
@@ -457,6 +471,7 @@ 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);
@@ -468,6 +483,7 @@ public class ReflectionUtils {
}
}
catch (Throwable t) {
+ Logger.REFLECTION("Method: Internal Lookup Failed: "+aMethodName);
try {
m = getMethodRecursively(aClass, aMethodName);
} catch (NoSuchMethodException e) {
@@ -479,9 +495,10 @@ public class ReflectionUtils {
return m;
}
- private static Method getMethodRecursively(final Class<?> clazz, final String fieldName) throws NoSuchMethodException {
+ private static Method getMethodRecursively(final Class<?> clazz, final String aMethodName) throws NoSuchMethodException {
try {
- Method k = clazz.getDeclaredMethod(fieldName);
+ Logger.REFLECTION("Method: Recursion Lookup: "+aMethodName);
+ Method k = clazz.getDeclaredMethod(aMethodName);
makeMethodAccessible(k);
return k;
} catch (final NoSuchMethodException e) {
@@ -489,7 +506,7 @@ public class ReflectionUtils {
if (superClass == null || superClass == Object.class) {
throw e;
}
- return getMethod_Internal(superClass, fieldName);
+ return getMethod_Internal(superClass, aMethodName);
}
}
@@ -502,7 +519,7 @@ public class ReflectionUtils {
Logger.INFO("Dumping all Methods.");
for (Method method : methods) {
- System.out.println(method.getName());
+ System.out.println(method.getName()+" | "+StringUtils.getDataStringFromArray(method.getParameterTypes()));
}
Logger.INFO("Dumping all Fields.");
for (Field f : fields) {
@@ -510,7 +527,7 @@ public class ReflectionUtils {
}
Logger.INFO("Dumping all Constructors.");
for (Constructor c : consts) {
- System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+c.getParameterTypes().toString());
+ System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+StringUtils.getDataStringFromArray(c.getParameterTypes()));
}
}