MCPcopy Create free account
hub / github.com/cinit/TMoe / invokeStatic

Method invokeStatic

app/src/main/java/cc/ioctl/tmoe/util/Reflex.java:806–856  ·  view source on GitHub ↗
(Class<?> staticClass, String name, Object... argsTypesAndReturnType)

Source from the content-addressed store, hash-verified

804 }
805
806 public static Object invokeStatic(Class<?> staticClass, String name, Object... argsTypesAndReturnType)
807 throws NoSuchMethodException, InvocationTargetException, IllegalArgumentException {
808 Class clazz = staticClass;
809 int argc = argsTypesAndReturnType.length / 2;
810 Class[] argt = new Class[argc];
811 Object[] argv = new Object[argc];
812 Class returnType = null;
813 if (argc * 2 + 1 == argsTypesAndReturnType.length) {
814 returnType = (Class) argsTypesAndReturnType[argsTypesAndReturnType.length - 1];
815 }
816 int i, ii;
817 Method[] m;
818 Method method = null;
819 Class[] _argt;
820 for (i = 0; i < argc; i++) {
821 argt[i] = (Class) argsTypesAndReturnType[argc + i];
822 argv[i] = argsTypesAndReturnType[i];
823 }
824 loop_main:
825 do {
826 m = clazz.getDeclaredMethods();
827 loop:
828 for (i = 0; i < m.length; i++) {
829 if (m[i].getName().equals(name)) {
830 _argt = m[i].getParameterTypes();
831 if (_argt.length == argt.length) {
832 for (ii = 0; ii < argt.length; ii++) {
833 if (!argt[ii].equals(_argt[ii])) {
834 continue loop;
835 }
836 }
837 if (returnType != null && !returnType.equals(m[i].getReturnType())) {
838 continue;
839 }
840 method = m[i];
841 break loop_main;
842 }
843 }
844 }
845 } while (!Object.class.equals(clazz = clazz.getSuperclass()));
846 if (method == null) {
847 throw new NoSuchMethodException(name + paramsTypesToString(argt));
848 }
849 method.setAccessible(true);
850 try {
851 return method.invoke(null, argv);
852 } catch (IllegalAccessException e) {
853 // should not happen
854 throw new AssertionError(e);
855 }
856 }
857
858 public static Object getInstanceObjectOrNull(Object obj, String name) {
859 return getInstanceObjectOrNull(obj, name, null);

Callers 6

getStringImplMethod · 0.95
formatStringMethod · 0.95
getChatFormCacheMethod · 0.80
getUserFormCacheMethod · 0.80

Calls 5

paramsTypesToStringMethod · 0.95
getParameterTypesMethod · 0.80
getReturnTypeMethod · 0.80
equalsMethod · 0.45
invokeMethod · 0.45

Tested by

no test coverage detected