(Class paramType, Object arg)
| 592 | } |
| 593 | |
| 594 | static Object boxArg(Class paramType, Object arg){ |
| 595 | if(arg instanceof IFn && Compiler.FISupport.maybeFIMethod(paramType) != null && !(paramType.isInstance(arg))) |
| 596 | // Adapt IFn obj to targetType using dynamic proxy |
| 597 | return Proxy.newProxyInstance(RT.baseLoader(), |
| 598 | new Class[]{paramType}, |
| 599 | (proxy, method, methodArgs) -> { |
| 600 | Object ret = ((IFn) arg).applyTo(RT.seq(methodArgs)); |
| 601 | return coerceAdapterReturn(ret, method.getReturnType()); |
| 602 | }); |
| 603 | else if(!paramType.isPrimitive()) |
| 604 | return paramType.cast(arg); |
| 605 | else if(paramType == boolean.class) |
| 606 | return Boolean.class.cast(arg); |
| 607 | else if(paramType == char.class) |
| 608 | return Character.class.cast(arg); |
| 609 | else if(arg instanceof Number) |
| 610 | { |
| 611 | Number n = (Number) arg; |
| 612 | if(paramType == int.class) |
| 613 | return n.intValue(); |
| 614 | else if(paramType == float.class) |
| 615 | return n.floatValue(); |
| 616 | else if(paramType == double.class) |
| 617 | return n.doubleValue(); |
| 618 | else if(paramType == long.class) |
| 619 | return n.longValue(); |
| 620 | else if(paramType == short.class) |
| 621 | return n.shortValue(); |
| 622 | else if(paramType == byte.class) |
| 623 | return n.byteValue(); |
| 624 | } |
| 625 | throw new IllegalArgumentException("Unexpected param type, expected: " + paramType + |
| 626 | ", given: " + arg.getClass().getName()); |
| 627 | } |
| 628 | |
| 629 | static Object[] boxArgs(Class[] params, Object[] args){ |
| 630 | if(params.length == 0) |
no test coverage detected