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

Method invokeVirtualAny

app/src/main/java/cc/ioctl/tmoe/util/Reflex.java:52–103  ·  view source on GitHub ↗
(Object obj, Object... argsTypesAndReturnType)

Source from the content-addressed store, hash-verified

50 }
51
52 public static Object invokeVirtualAny(Object obj, Object... argsTypesAndReturnType)
53 throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IllegalArgumentException {
54 Class clazz = obj.getClass();
55 int argc = argsTypesAndReturnType.length / 2;
56 Class[] argt = new Class[argc];
57 Object[] argv = new Object[argc];
58 Class returnType = null;
59 if (argc * 2 + 1 == argsTypesAndReturnType.length) {
60 returnType = (Class) argsTypesAndReturnType[argsTypesAndReturnType.length - 1];
61 }
62 int i, ii;
63 Method[] m;
64 Method method = null;
65 Class[] _argt;
66 for (i = 0; i < argc; i++) {
67 argt[i] = (Class) argsTypesAndReturnType[argc + i];
68 argv[i] = argsTypesAndReturnType[i];
69 }
70 loop_main:
71 do {
72 m = clazz.getDeclaredMethods();
73 loop:
74 for (i = 0; i < m.length; i++) {
75 _argt = m[i].getParameterTypes();
76 if (_argt.length == argt.length) {
77 for (ii = 0; ii < argt.length; ii++) {
78 if (!argt[ii].equals(_argt[ii])) {
79 continue loop;
80 }
81 }
82 if (returnType != null && !returnType.equals(m[i].getReturnType())) {
83 continue;
84 }
85 if (method == null) {
86 method = m[i];
87 //here we go through this class
88 } else {
89 throw new NoSuchMethodException(
90 "Multiple methods found for __attribute__((any))" + paramsTypesToString(
91 argt) + " in " + obj.getClass().getName());
92 }
93 }
94 }
95 } while (method == null && !Object.class.equals(clazz = clazz.getSuperclass()));
96 if (method == null) {
97 throw new NoSuchMethodException(
98 "__attribute__((a))" + paramsTypesToString(argt) + " in " + obj.getClass()
99 .getName());
100 }
101 method.setAccessible(true);
102 return method.invoke(obj, argv);
103 }
104
105
106 public static String paramsTypesToString(Class... c) {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected