0

fix полечение метода

This commit is contained in:
2021-01-08 16:39:33 +03:00
parent aab3b43e57
commit 8e97d33be4

View File

@@ -84,15 +84,39 @@ public class ReflectionObject {
} }
} }
public List<ReflectionMethod> methodsAllList() {
final Class clazz = object.getClass();
Method[] declaredMethods = clazz.getMethods();
if (declaredMethods.length > 0) {
List<ReflectionMethod> result = new ArrayList<>(declaredMethods.length);
for (Method method : declaredMethods) {
result.add(new ReflectionMethod(object, method));
}
return result;
} else {
return Collections.emptyList();
}
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ReflectionMethod method(String methodName, Class<?>... parameterTypes) { public ReflectionMethod method(String methodName, Class<?>... parameterTypes) {
final Class clazz = object.getClass(); final Class clazz = object.getClass();
Method method;
try { try {
return new ReflectionMethod(object, clazz.getDeclaredMethod(methodName, parameterTypes)); method = clazz.getDeclaredMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new ReflectionException(e); try {
method = clazz.getMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e1) {
throw new ReflectionException(e1);
}
} }
return new ReflectionMethod(object, method);
} }
@Override @Override