/** All purpose MethodHandle invoke implementation, with or without args. * @param base represents the base object instance. * @param pars parameter arguments * @return invocation result * @throws Throwable combined exceptions */ private synchronized Object invokeTarget(Object base, Object[] pars) throws Throwable { Reflect.logInvokeMethod("Invoking method (entry): ", this, pars); List<Object> params = collectParamaters(base, pars); Reflect.logInvokeMethod("Invoking method (after): ", this, params); if (getParameterCount() > 0) return getMethodHandle().invokeWithArguments(params); if (isStatic() || this instanceof ConstructorInvocable) return getMethodHandle().invoke(); return getMethodHandle().invoke(params.get(0)); }
/** Pull the cascade inheritance chain for parameter collection. * Applies the varargs collection of parameters supplied as an array or * as separate args. * {@inheritDoc} */ @Override public List<Object> collectParamaters(Object base, Object[] params) throws Throwable { super.collectParamaters(base, params); if (isVarArgs()) { if (getLastParameterIndex() < params.length) { Object[] varargs; if (getParameterCount() == params.length && params[getLastParameterIndex()] instanceof Object[]) varargs = (Object[]) params[getLastParameterIndex()]; else varargs = Arrays.copyOfRange( params, getLastParameterIndex(), params.length); for (int i = 0; i < varargs.length; i++) parameters.add(super.coerceToType( varargs[i], getVarArgsComponentType())); } } else if (null != params && getLastParameterIndex() < params.length) parameters.add(super.coerceToType(params[getLastParameterIndex()], getParameterTypes()[getLastParameterIndex()])); return parameters; } }