Commit 71f821e4 authored by Administrator's avatar Administrator

双段反射支持更多接口

parent cc4e32ab
......@@ -19,6 +19,10 @@ public class FreeReflection {
private static Method getDeclaredConstructorMethod = null;
private static Method getDeclaredConstructorsMethod = null;
private static Method getDeclaredMethodsMethod = null;
private static Method getDeclaredFieldsMethod = null;
static {
......@@ -32,6 +36,12 @@ public class FreeReflection {
getFiledMethod = Class.class.getDeclaredMethod("getDeclaredField", String.class);
getDeclaredConstructorMethod = Class.class.getDeclaredMethod("getDeclaredConstructor", Class[].class);
getDeclaredFieldsMethod = Class.class.getDeclaredMethod("getDeclaredFields");
//java.lang.Class.getDeclaredConstructors
getDeclaredConstructorsMethod = Class.class.getDeclaredMethod("getDeclaredConstructors");
getDeclaredMethodsMethod = Class.class.getDeclaredMethod("getDeclaredMethods");
} catch (Throwable t) {
throw new RuntimeException(t);
}
......@@ -52,6 +62,16 @@ public class FreeReflection {
return clazz.getDeclaredMethod(methodName, parameterTypes);
}
public static Method[] getDeclaredMethods(Class<?> clazz) throws SecurityException {
if (use()) {
try {
return (Method[]) getDeclaredMethodsMethod.invoke(clazz);
} catch (Throwable e) {
//ignore
}
}
return clazz.getDeclaredMethods();
}
public static Constructor<?> getDeclaredConstructor(Class<?> clazz, Class<?>... parameterTypes) throws NoSuchMethodException {
if (use()) {
......@@ -64,6 +84,19 @@ public class FreeReflection {
return clazz.getDeclaredConstructor(parameterTypes);
}
public static Constructor<?>[] getDeclaredConstructors(Class<?> clazz) throws SecurityException {
if (use()) {
try {
return (Constructor<?>[]) getDeclaredConstructorsMethod.invoke(clazz);
} catch (Throwable e) {
//ignore
e.printStackTrace();
}
}
return clazz.getDeclaredConstructors();
}
public static Field getDeclaredField(Class<?> clazz, String field) throws NoSuchFieldException {
if (use()) {
try {
......
......@@ -425,7 +425,8 @@ public final class RposedHelpers {
Class<?> clz = clazz;
boolean considerPrivateMethods = true;
do {
for (Method method : clz.getDeclaredMethods()) {
for (Method method : FreeReflection.getDeclaredMethods(clz)) {
//for (Method method : clz.getDeclaredMethods()) {
// don't consider private methods of superclasses
if (!considerPrivateMethods && Modifier.isPrivate(method.getModifiers()))
continue;
......@@ -664,7 +665,8 @@ public final class RposedHelpers {
}
Constructor<?> bestMatch = null;
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
// Constructor<?>[] constructors = clazz.getDeclaredConstructors();
Constructor<?>[] constructors = FreeReflection.getDeclaredConstructors(clazz);
for (Constructor<?> constructor : constructors) {
// compare name and parameters
if (ClassUtils.isAssignable(parameterTypes, constructor.getParameterTypes(), true)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment