use of org.kie.dmn.feel.lang.ast.DashNode in project drools by kiegroup.
the class FEELImpl method evaluateUnaryTests.
@Override
public List<UnaryTest> evaluateUnaryTests(String expression, Map<String, Type> variableTypes) {
// DMN defines a special case where, unless the expressions are unary tests
// or ranges, they need to be converted into an equality test unary expression.
// This way, we have to compile and check the low level AST nodes to properly
// deal with this case
CompilerContext ctx = newCompilerContext();
for (Map.Entry<String, Type> e : variableTypes.entrySet()) {
ctx.addInputVariableType(e.getKey(), e.getValue());
}
CompiledExpressionImpl compiledExpression = (CompiledExpressionImpl) compileExpressionList(expression, ctx);
if (compiledExpression != null) {
ListNode listNode = (ListNode) compiledExpression.getExpression();
List<BaseNode> tests = new ArrayList<>();
for (BaseNode o : listNode.getElements()) {
if (o == null) {
// not much we can do, so just skip it. Error was reported somewhere else
continue;
} else if (o instanceof UnaryTestNode || o instanceof DashNode) {
tests.add(o);
} else if (o instanceof RangeNode || o instanceof ListNode) {
tests.add(new UnaryTestNode("in", o));
} else {
tests.add(new UnaryTestNode("=", o));
}
}
listNode.setElements(tests);
compiledExpression.setExpression(listNode);
// now we can evaluate the expression to build the list of unary tests
List<UnaryTest> uts = (List<UnaryTest>) evaluate(compiledExpression, FEELImpl.EMPTY_INPUT);
return uts;
}
return Collections.emptyList();
}
Aggregations