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

Method invokeStaticAny

app/src/main/java/cc/ioctl/tmoe/util/Reflex.java:124–173  ·  view source on GitHub ↗
(Class<?> clazz, Object... argsTypesAndReturnType)

Source from the content-addressed store, hash-verified

122 }
123
124 public static Object invokeStaticAny(Class<?> clazz, Object... argsTypesAndReturnType)
125 throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IllegalArgumentException {
126 int argc = argsTypesAndReturnType.length / 2;
127 Class[] argt = new Class[argc];
128 Object[] argv = new Object[argc];
129 Class returnType = null;
130 if (argc * 2 + 1 == argsTypesAndReturnType.length) {
131 returnType = (Class) argsTypesAndReturnType[argsTypesAndReturnType.length - 1];
132 }
133 int i, ii;
134 Method[] m;
135 Method method = null;
136 Class[] _argt;
137 for (i = 0; i < argc; i++) {
138 argt[i] = (Class) argsTypesAndReturnType[argc + i];
139 argv[i] = argsTypesAndReturnType[i];
140 }
141 loop_main:
142 do {
143 m = clazz.getDeclaredMethods();
144 loop:
145 for (i = 0; i < m.length; i++) {
146 _argt = m[i].getParameterTypes();
147 if (_argt.length == argt.length) {
148 for (ii = 0; ii < argt.length; ii++) {
149 if (!argt[ii].equals(_argt[ii])) {
150 continue loop;
151 }
152 }
153 if (returnType != null && !returnType.equals(m[i].getReturnType())) {
154 continue;
155 }
156 if (method == null) {
157 method = m[i];
158 //here we go through this class
159 } else {
160 throw new NoSuchMethodException(
161 "Multiple methods found for __attribute__((any))" + paramsTypesToString(
162 argt) + " in " + clazz.getName());
163 }
164 }
165 }
166 } while (method == null && !Object.class.equals(clazz = clazz.getSuperclass()));
167 if (method == null) {
168 throw new NoSuchMethodException(
169 "__attribute__((a))" + paramsTypesToString(argt) + " in " + clazz.getName());
170 }
171 method.setAccessible(true);
172 return method.invoke(null, argv);
173 }
174
175 public static Object invokeVirtualDeclaredModifierAny(Object obj, int requiredMask,
176 int excludedMask, Object... argsTypesAndReturnType)

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