Search in sources :

Example 1 with DMNIteratorEvaluator

use of org.kie.dmn.core.ast.DMNIteratorEvaluator in project drools by kiegroup.

the class DMNEvaluatorCompiler method compileIterator.

private DMNExpressionEvaluator compileIterator(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String exprName, Iterator expression) {
    if (expression.getIteratorVariable() == null || expression.getIteratorVariable().isEmpty()) {
        MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, node.getSource(), model, null, null, Msg.MISSING_EXPRESSION_FOR_ITERATOR, expression.getTypeRef().toString().toLowerCase(), node.getIdentifierString());
        return null;
    }
    DMNExpressionEvaluator inEvaluator = null;
    DMNExpressionEvaluator returnEvaluator = null;
    inEvaluator = compileExpression(ctx, model, node, exprName + " [in]", expression.getIn().getExpression());
    try {
        ctx.enterFrame();
        DMNType outputType = compiler.resolveTypeRef(model, null, node.getSource(), expression.getTypeRef());
        DMNType elementType = compiler.resolveTypeRefUsingString(model, null, node.getSource(), expression.getIn().getTypeRef());
        if (elementType != null && elementType.isCollection() && elementType instanceof BaseDMNTypeImpl) {
            elementType = extractOrSynthesizeGeneric(model, (BaseDMNTypeImpl) elementType);
        }
        ctx.setVariable(expression.getIteratorVariable(), elementType != null ? elementType : model.getTypeRegistry().unknown());
        ctx.setVariable("partial", outputType != null ? outputType : model.getTypeRegistry().unknown());
        returnEvaluator = compileExpression(ctx, model, node, exprName + " [return]", expression instanceof For ? ((For) expression).getReturn().getExpression() : ((Quantified) expression).getSatisfies().getExpression());
    } finally {
        ctx.exitFrame();
    }
    if (inEvaluator == null) {
        MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, node.getSource(), model, null, null, Msg.MISSING_EXPRESSION_FOR_ITERATOR, "in", node.getIdentifierString());
        return null;
    }
    if (returnEvaluator == null) {
        MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, node.getSource(), model, null, null, Msg.MISSING_EXPRESSION_FOR_ITERATOR, expression instanceof For ? "return" : "satisfies", node.getIdentifierString());
        return null;
    }
    return new DMNIteratorEvaluator(exprName, node.getSource(), expression, expression.getIteratorVariable(), inEvaluator, returnEvaluator);
}
Also used : DMNExpressionEvaluator(org.kie.dmn.core.api.DMNExpressionEvaluator) Quantified(org.kie.dmn.model.api.Quantified) For(org.kie.dmn.model.api.For) BaseDMNTypeImpl(org.kie.dmn.core.impl.BaseDMNTypeImpl) DMNIteratorEvaluator(org.kie.dmn.core.ast.DMNIteratorEvaluator) DMNType(org.kie.dmn.api.core.DMNType)

Aggregations

DMNType (org.kie.dmn.api.core.DMNType)1 DMNExpressionEvaluator (org.kie.dmn.core.api.DMNExpressionEvaluator)1 DMNIteratorEvaluator (org.kie.dmn.core.ast.DMNIteratorEvaluator)1 BaseDMNTypeImpl (org.kie.dmn.core.impl.BaseDMNTypeImpl)1 For (org.kie.dmn.model.api.For)1 Quantified (org.kie.dmn.model.api.Quantified)1