private String getSignature() { return getName()+"( "+parameters.stream().collect( Collectors.joining(", ") ) +" )"; }
@Override public String toString() { return "function "+getSignature(); } }
public static Object invoke(EvaluationContext feelExprCtx, Object function, Object params) { if (function == null) { feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.FUNCTION_NOT_FOUND, function), null)); return null; } if (function instanceof FEELFunction) { Object[] invocationParams = toFunctionParams(params); FEELFunction f = (FEELFunction) function; if (function instanceof CompiledCustomFEELFunction) { CompiledCustomFEELFunction ff = (CompiledCustomFEELFunction) function; if (ff.isProperClosure()) { return ff.invokeReflectively(ff.getEvaluationContext(), invocationParams); } } return f.invokeReflectively(feelExprCtx, invocationParams); } else if (function instanceof UnaryTest) { return ((UnaryTest) function).apply(feelExprCtx, ((List)params).get(0)); } return null; }
@Override public FEELFnResult<Object> invoke(EvaluationContext ctx, Object[] params ) { if( params.length != parameters.size() ) { return FEELFnResult.ofError(new InvalidInputEvent(Severity.ERROR, "Illegal invocation of function", getName(), getName() + "( " + Arrays.asList(params)+" )", getSignature())); } FEELEvent capturedException = null; try { ctx.enterFrame(); for ( int i = 0; i < parameters.size(); i++ ) { ctx.setValue( parameters.get( i ), params[i] ); } Object result = this.body.apply(ctx); return FEELFnResult.ofResult( result ); } catch( Exception e ) { capturedException = new FEELEventBase(Severity.ERROR, "Error invoking function", new RuntimeException("Error invoking function " + getSignature() + ".", e)); } finally { ctx.exitFrame(); } return FEELFnResult.ofError( capturedException ); }