(Object[] args, int index,
Method invokingMethod, TypeMapper mapper,
boolean allowObjects, Class<?> expectedType)
| 502 | } |
| 503 | |
| 504 | private Object convertArgument(Object[] args, int index, |
| 505 | Method invokingMethod, TypeMapper mapper, |
| 506 | boolean allowObjects, Class<?> expectedType) { |
| 507 | Object arg = args[index]; |
| 508 | if (arg != null) { |
| 509 | Class<?> type = arg.getClass(); |
| 510 | ToNativeConverter converter = null; |
| 511 | if (NativeMapped.class.isAssignableFrom(type)) { |
| 512 | converter = NativeMappedConverter.getInstance(type); |
| 513 | } else if (mapper != null) { |
| 514 | converter = mapper.getToNativeConverter(type); |
| 515 | } |
| 516 | if (converter != null) { |
| 517 | ToNativeContext context; |
| 518 | if (invokingMethod != null) { |
| 519 | context = new MethodParameterContext(this, args, index, invokingMethod) ; |
| 520 | } |
| 521 | else { |
| 522 | context = new FunctionParameterContext(this, args, index); |
| 523 | } |
| 524 | arg = converter.toNative(arg, context); |
| 525 | } |
| 526 | } |
| 527 | if (arg == null || isPrimitiveArray(arg.getClass())) { |
| 528 | return arg; |
| 529 | } |
| 530 | |
| 531 | Class<?> argClass = arg.getClass(); |
| 532 | // Convert Structures to native pointers |
| 533 | if (arg instanceof Structure) { |
| 534 | Structure struct = (Structure)arg; |
| 535 | struct.autoWrite(); |
| 536 | if (struct instanceof Structure.ByValue) { |
| 537 | // Double-check against the method signature, if available |
| 538 | Class<?> ptype = struct.getClass(); |
| 539 | if (invokingMethod != null) { |
| 540 | Class<?>[] ptypes = invokingMethod.getParameterTypes(); |
| 541 | if (IS_VARARGS.isVarArgs(invokingMethod)) { |
| 542 | if (index < ptypes.length-1) { |
| 543 | ptype = ptypes[index]; |
| 544 | } else { |
| 545 | Class<?> etype = ptypes[ptypes.length-1].getComponentType(); |
| 546 | if (etype != Object.class) { |
| 547 | ptype = etype; |
| 548 | } |
| 549 | } |
| 550 | } else { |
| 551 | ptype = ptypes[index]; |
| 552 | } |
| 553 | } |
| 554 | if (Structure.ByValue.class.isAssignableFrom(ptype)) { |
| 555 | return struct; |
| 556 | } |
| 557 | } |
| 558 | return struct.getPointer(); |
| 559 | } else if (arg instanceof Callback) { |
| 560 | // Convert Callback to Pointer |
| 561 | return CallbackReference.getFunctionPointer((Callback)arg); |
no test coverage detected