use of org.fakereplace.data.ClassData in project fakereplace by fakereplace.
the class MethodReflection method getDeclaredMethod.
public static Method getDeclaredMethod(Class<?> clazz, String name, Class<?>... parameters) throws NoSuchMethodException {
ClassData cd = ClassDataStore.instance().getModifiedClassData(clazz.getClassLoader(), Descriptor.toJvmName(clazz.getName()));
if (cd == null || !cd.isReplaceable()) {
return clazz.getDeclaredMethod(name, parameters);
}
String args;
if (parameters != null) {
args = '(' + DescriptorUtils.classArrayToDescriptorString(parameters) + ')';
} else {
args = "()";
}
MethodData md = cd.getMethodData(name, args);
if (md == null) {
return clazz.getDeclaredMethod(name, parameters);
}
switch(md.getType()) {
case NORMAL:
return clazz.getDeclaredMethod(name, parameters);
case FAKE:
try {
Class<?> c = clazz.getClassLoader().loadClass(md.getClassName());
return c.getDeclaredMethod(name, parameters);
} catch (NoSuchMethodException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
throw new NoSuchMethodException();
}
use of org.fakereplace.data.ClassData in project fakereplace by fakereplace.
the class MethodReflection method getMethods.
public static Method[] getMethods(Class<?> clazz) {
try {
ClassData cd = ClassDataStore.instance().getModifiedClassData(clazz.getClassLoader(), Descriptor.toJvmName(clazz.getName()));
if (cd == null) {
return clazz.getMethods();
}
Method[] meth = clazz.getMethods();
List<Method> visible = new ArrayList<>(meth.length);
for (int i = 0; i < meth.length; ++i) {
MethodData mData = cd.getData(meth[i]);
if (mData == null || mData.getType() == MemberType.NORMAL) {
visible.add(meth[i]);
}
}
ClassData cta = cd;
while (cta != null) {
if (cta.isReplaceable()) {
for (MethodData i : cta.getMethods()) {
if (i.getType() == MemberType.FAKE && AccessFlag.isPublic(i.getAccessFlags())) {
Class<?> c = clazz.getClassLoader().loadClass(i.getClassName());
visible.add(i.getMethod(c));
} else if (i.getType() == MemberType.REMOVED) {
Class<?> c = clazz.getClassLoader().loadClass(i.getClassName());
visible.remove(i.getMethod(c));
}
}
}
cta = cta.getSuperClassInformation();
}
Method[] ret = new Method[visible.size()];
for (int i = 0; i < visible.size(); ++i) {
ret[i] = visible.get(i);
}
return ret;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations