MCPcopy Index your code
hub / github.com/clojure/clojure / boxArg

Method boxArg

src/jvm/clojure/lang/Reflector.java:594–627  ·  view source on GitHub ↗
(Class paramType, Object arg)

Source from the content-addressed store, hash-verified

592}
593
594static 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
629static Object[] boxArgs(Class[] params, Object[] args){
630 if(params.length == 0)

Callers 4

setStaticFieldMethod · 0.95
setInstanceFieldMethod · 0.95
invokeInstanceMemberMethod · 0.95
boxArgsMethod · 0.95

Calls 15

baseLoaderMethod · 0.95
seqMethod · 0.95
coerceAdapterReturnMethod · 0.95
maybeFIMethodMethod · 0.80
isPrimitiveMethod · 0.80
castMethod · 0.80
shortValueMethod · 0.80
byteValueMethod · 0.80
applyToMethod · 0.65
getNameMethod · 0.65
getReturnTypeMethod · 0.45
intValueMethod · 0.45

Tested by

no test coverage detected