static Object[] addCtxParamIfRequired(EvaluationContext ctx, Object[] params, boolean isNamedParams, Method m) {
        logger.trace("addCtxParamIfRequired {} {} {} {}", ctx, params, isNamedParams, m);
        Object[] actualParams;
        // Here, we check if any of the parameters is an EvaluationContext
        boolean injectCtx = Arrays.stream(m.getParameterTypes()).anyMatch(EvaluationContext.class::isAssignableFrom);
        if (injectCtx) {
            actualParams = new Object[params.length + 1];
            int j = 0;
            for (int i = 0; i < m.getParameterCount(); i++) {
                if (EvaluationContext.class.isAssignableFrom(m.getParameterTypes()[i])) {
                    if (isNamedParams) {
                        actualParams[i] = new NamedParameter("ctx", ctx);
                    } else {
                        actualParams[i] = ctx;
                    }
                } else if (j < params.length) {
                    actualParams[i] = params[j];
                    j++;
                }
            }
        } else {
            actualParams = params;
        }
        return actualParams;
    }
@Test
    void addCtxParamIfRequired() throws NoSuchMethodException {
        // AllFunction.invoke(@ParameterName( "list" ) List list)
        Method method = AllFunction.class.getMethod("invoke", List.class);
        assertNotNull(method);
        Object[] parameters = {List.of(true, false)};

        Object[] retrieved = BaseFEELFunctionHelper.addCtxParamIfRequired(ctx, parameters, true, method);
        assertNotNull(retrieved);
        assertEquals(parameters.length, retrieved.length);
        for (int i = 0; i < parameters.length; i++) {
            assertEquals(parameters[i], retrieved[i]);
        }

        // SortFunction.invoke(@ParameterName( "ctx" ) EvaluationContext ctx,
        //                                             @ParameterName("list") List list,
        //                                             @ParameterName("precedes") FEELFunction function)
        method = SortFunction.class.getMethod("invoke", EvaluationContext.class, List.class, FEELFunction.class);
        assertNotNull(method);
        parameters = new Object[]{List.of(1, 2), AllFunction.INSTANCE};
        // direct reference to ctx
        retrieved = BaseFEELFunctionHelper.addCtxParamIfRequired(ctx, parameters, false, method);
        assertNotNull(retrieved);
        assertEquals(parameters.length + 1, retrieved.length);
        assertEquals(ctx, retrieved[0]);
        for (int i = 0; i < parameters.length; i++) {
            assertEquals(parameters[i], retrieved[i + 1]);
        }

        // NamedParameter reference to ctx
        retrieved = BaseFEELFunctionHelper.addCtxParamIfRequired(ctx, parameters, true, method);
        assertNotNull(retrieved);
        assertEquals(parameters.length + 1, retrieved.length);
        assertEquals(NamedParameter.class, retrieved[0].getClass());
        NamedParameter retrievedNamedParameter = (NamedParameter) retrieved[0];
        assertEquals("ctx", retrievedNamedParameter.getName());
        assertEquals(ctx, retrievedNamedParameter.getValue());
        for (int i = 0; i < parameters.length; i++) {
            assertEquals(parameters[i], retrieved[i + 1]);
        }
    }