sige 1 year ago
parent
commit
f17a5bd289
  1. 23
      src/src/main/java/com/my/graphiteDigesterBg/diframe/util/DiClassHelper.java

23
src/src/main/java/com/my/graphiteDigesterBg/diframe/util/DiClassHelper.java

@ -1,6 +1,8 @@
package com.my.graphiteDigesterBg.diframe.util;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.ArrayList;
@ -8,8 +10,27 @@ import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
public class DiClassHelper {
// invoke method
public static Object invokeMethod(Object obj, String methodName, List<Object> args) throws NoSuchMethodException {
try {
Class<?>[] parameterTypes = new Class<?>[args.size()];
for (int i = 0; i < args.size(); i++) {
parameterTypes[i] = args.get(i).getClass();
}
Method method = obj.getClass().getMethod(methodName, parameterTypes);
if ( method.getReturnType().equals(Void.TYPE) ) {
method.invoke(obj, args.toArray());
return null;
} else {
return method.invoke(obj, args.toArray());
}
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
// get all classes in package
public static List<Class<?>> getAllClassesInPackage(String packageName) {
List<Class<?>> classes = new ArrayList<>();

Loading…
Cancel
Save