use of org.kie.dmn.feel.lang.Type in project drools by kiegroup.
the class InstanceOfNode method evaluate.
@Override
public Object evaluate(EvaluationContext ctx) {
Object value = expression.evaluate(ctx);
Type t = type.evaluate(ctx);
if (t != BuiltInType.DURATION) {
return t.isInstanceOf(value);
} else {
switch(type.getText()) {
case SimpleType.YEARS_AND_MONTHS_DURATION:
return value instanceof ChronoPeriod;
case SimpleType.DAYS_AND_TIME_DURATION:
return value instanceof Duration;
default:
return t.isInstanceOf(value);
}
}
}
use of org.kie.dmn.feel.lang.Type in project drools by kiegroup.
the class RangeNode method evaluate.
@Override
public Range evaluate(EvaluationContext ctx) {
Object s = start.evaluate(ctx);
Object e = end.evaluate(ctx);
Type sType = BuiltInType.determineTypeFromInstance(s);
Type eType = BuiltInType.determineTypeFromInstance(e);
if (s != null && e != null && sType != eType && !s.getClass().isAssignableFrom(e.getClass())) {
ctx.notifyEvt(astEvent(Severity.ERROR, Msg.createMessage(Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, "Start", "End")));
return null;
}
Comparable start = convertToComparable(ctx, s);
Comparable end = convertToComparable(ctx, e);
return new RangeImpl(lowerBound == IntervalBoundary.OPEN ? Range.RangeBoundary.OPEN : Range.RangeBoundary.CLOSED, start, end, upperBound == IntervalBoundary.OPEN ? Range.RangeBoundary.OPEN : Range.RangeBoundary.CLOSED);
}
use of org.kie.dmn.feel.lang.Type in project kie-wb-common by kiegroup.
the class FEELLanguageServiceTest method assertGetType.
private void assertGetType(final String expression, final BuiltInType expected) {
final String cursor = "|";
final int line = expression.substring(0, expression.indexOf(cursor)).split("\n").length;
final int column = expression.split("\n")[line - 1].indexOf(cursor);
final Position position = new Position(line, column);
final String expressionToParse = expression.replace(cursor, "");
final BaseNode astNode = getASTNode(expressionToParse);
final Type actual = service.getType(astNode, position);
assertEquals(expected, actual);
}
use of org.kie.dmn.feel.lang.Type in project kie-wb-common by kiegroup.
the class TypeStackUtils method getTypeStack.
private List<Type> getTypeStack(final ASTNode currentNode, final ASTNode nextNode, final Position position, final boolean isListOfParameters, final boolean isParentEligible) {
final List<Type> typeStack = new ArrayList<>();
if (currentNode == null) {
return typeStack;
}
final Type type = getType(currentNode);
final boolean isNextListOfParameters = currentNode instanceof FunctionInvocationNode;
final boolean isEligibleType = isEligibleType(currentNode, nextNode, position, isParentEligible) && !isListOfParameters;
if (isEligibleType) {
typeStack.add(type);
}
try {
forEach(getChildren(currentNode), (current, next) -> {
final boolean isParentEligibleType = isListOfParameters ? isParentEligible : isEligibleType;
typeStack.addAll(getTypeStack(current, next, position, isNextListOfParameters, isParentEligibleType));
});
} catch (final Exception e) {
// Ignore errors during node inspection.
}
return typeStack;
}
use of org.kie.dmn.feel.lang.Type in project drools-wb by kiegroup.
the class DMNUtilsTest method getRootType.
@Test
public void getRootType() {
SimpleTypeImpl simpleTypeAny = new SimpleTypeImpl(null, "tSimple", null, false, Collections.emptyList(), null, BuiltInType.UNKNOWN);
assertEquals(BuiltInType.UNKNOWN, DMNUtils.getRootType(simpleTypeAny));
Type aliasFeelType = new AliasFEELType("alias", BuiltInType.UNKNOWN);
CompositeTypeImpl aliasType = new CompositeTypeImpl(null, "tSimple", null, false, Collections.emptyMap(), simpleTypeAny, aliasFeelType);
assertEquals(BuiltInType.UNKNOWN, DMNUtils.getRootType(aliasType));
Type notBuiltInType = new AliasFEELType("notBuiltIn", BuiltInType.UNKNOWN);
SimpleTypeImpl notBuiltIn = new SimpleTypeImpl(null, "tSimple", null, false, Collections.emptyList(), null, notBuiltInType);
assertEquals(notBuiltInType, DMNUtils.getRootType(notBuiltIn));
}
Aggregations