MCPcopy Index your code
hub / github.com/java-native-access/jna / invoke

Method invoke

src/com/sun/jna/Library.java:213–272  ·  view source on GitHub ↗
(Object proxy, Method method, Object[] inArgs)

Source from the content-addressed store, hash-verified

211 }
212
213 @Override
214 public Object invoke(Object proxy, Method method, Object[] inArgs)
215 throws Throwable {
216
217 // Intercept Object methods
218 if (OBJECT_TOSTRING.equals(method)) {
219 return "Proxy interface to " + nativeLibrary;
220 } else if (OBJECT_HASHCODE.equals(method)) {
221 return Integer.valueOf(hashCode());
222 } else if (OBJECT_EQUALS.equals(method)) {
223 Object o = inArgs[0];
224 if (o != null && Proxy.isProxyClass(o.getClass())) {
225 return Function.valueOf(Proxy.getInvocationHandler(o) == this);
226 }
227 return Boolean.FALSE;
228 }
229
230 // Using the double-checked locking pattern to speed up function calls
231 FunctionInfo f = functions.get(method);
232 if(f == null) {
233 synchronized(functions) {
234 f = functions.get(method);
235 if (f == null) {
236 boolean isDefault = ReflectionUtils.isDefault(method);
237 if(! isDefault) {
238 boolean isVarArgs = Function.isVarArgs(method);
239 InvocationHandler handler = null;
240 if (invocationMapper != null) {
241 handler = invocationMapper.getInvocationHandler(nativeLibrary, method);
242 }
243 Function function = null;
244 Class<?>[] parameterTypes = null;
245 Map<String, Object> options = null;
246 if (handler == null) {
247 // Find the function to invoke
248 function = nativeLibrary.getFunction(method.getName(), method);
249 parameterTypes = method.getParameterTypes();
250 options = new HashMap<>(this.options);
251 options.put(Function.OPTION_INVOKING_METHOD, method);
252 }
253 f = new FunctionInfo(handler, function, parameterTypes, isVarArgs, options);
254 } else {
255 f = new FunctionInfo(ReflectionUtils.getMethodHandle(method));
256 }
257 functions.put(method, f);
258 }
259 }
260 }
261 if (f.methodHandle != null) {
262 return ReflectionUtils.invokeDefaultMethod(proxy, f.methodHandle, inArgs);
263 } else {
264 if (f.isVarArgs) {
265 inArgs = Function.concatenateVarArgs(inArgs);
266 }
267 if (f.handler != null) {
268 return f.handler.invoke(proxy, method, inArgs);
269 }
270 return f.function.invoke(method, f.parameterTypes, method.getReturnType(), inArgs, f.options);

Callers

nothing calls this directly

Calls 15

valueOfMethod · 0.95
isDefaultMethod · 0.95
isVarArgsMethod · 0.95
getMethodHandleMethod · 0.95
invokeDefaultMethodMethod · 0.95
concatenateVarArgsMethod · 0.95
getInvocationHandlerMethod · 0.80
putMethod · 0.80
getNameMethod · 0.65
getParameterTypesMethod · 0.65
invokeMethod · 0.65
getReturnTypeMethod · 0.65

Tested by

no test coverage detected