Search in sources :

Example 1 with ASTEventBase

use of org.kie.dmn.feel.runtime.events.ASTEventBase in project drools by kiegroup.

the class CompiledFEELSemanticMappings method range.

/**
 * Represents a [n..m] construct
 */
public static RangeImpl range(EvaluationContext ctx, Range.RangeBoundary lowBoundary, Object lowEndPoint, Object highEndPoint, Range.RangeBoundary highBoundary) {
    Comparable left = asComparable(lowEndPoint);
    Comparable right = asComparable(highEndPoint);
    if (left != null && right != null && !compatible(left, right)) {
        ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.INCOMPATIBLE_TYPE_FOR_RANGE, left.getClass().getSimpleName()), null));
        return null;
    }
    return new RangeImpl(lowBoundary, left, right, highBoundary);
}
Also used : ASTEventBase(org.kie.dmn.feel.runtime.events.ASTEventBase) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl)

Example 2 with ASTEventBase

use of org.kie.dmn.feel.runtime.events.ASTEventBase in project drools by kiegroup.

the class CompiledFEELSupport method invoke.

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));
    } else if (function instanceof Range) {
        // alignment to FunctionInvocationNode
        List<?> ps = (List<?>) params;
        if (ps.size() == 1) {
            return ((Range) function).includes(ps.get(0));
        } else {
            feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.CAN_T_INVOKE_AN_UNARY_TEST_WITH_S_PARAMETERS_UNARY_TESTS_REQUIRE_1_SINGLE_PARAMETER, ps.size()), null));
        }
    }
    feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.CANNOT_INVOKE, MsgUtil.clipToString(function, 50)), null));
    return null;
}
Also used : FEELFunction(org.kie.dmn.feel.runtime.FEELFunction) ASTEventBase(org.kie.dmn.feel.runtime.events.ASTEventBase) ArrayList(java.util.ArrayList) NodeList(com.github.javaparser.ast.NodeList) List(java.util.List) Range(org.kie.dmn.feel.runtime.Range) UnaryTest(org.kie.dmn.feel.runtime.UnaryTest)

Example 3 with ASTEventBase

use of org.kie.dmn.feel.runtime.events.ASTEventBase in project drools by kiegroup.

the class CompiledFEELSemanticMappings method between.

public static Boolean between(EvaluationContext ctx, Object value, Object start, Object end) {
    if (value == null) {
        ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "value"), null));
        return null;
    }
    if (start == null) {
        ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "start"), null));
        return null;
    }
    if (end == null) {
        ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "end"), null));
        return null;
    }
    Boolean gte = gte(value, start);
    if (gte == null) {
        ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, "value", "start"), null));
    }
    Boolean lte = lte(value, end);
    if (lte == null) {
        ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, "value", "end"), null));
    }
    // do not use Java && to avoid potential NPE due to FEEL 3vl.
    return and(gte, lte);
}
Also used : ASTEventBase(org.kie.dmn.feel.runtime.events.ASTEventBase)

Aggregations

ASTEventBase (org.kie.dmn.feel.runtime.events.ASTEventBase)3 NodeList (com.github.javaparser.ast.NodeList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FEELFunction (org.kie.dmn.feel.runtime.FEELFunction)1 Range (org.kie.dmn.feel.runtime.Range)1 UnaryTest (org.kie.dmn.feel.runtime.UnaryTest)1 RangeImpl (org.kie.dmn.feel.runtime.impl.RangeImpl)1