use of org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess in project drools by kiegroup.
the class PatternDSL method addImplicitCastExpr.
private void addImplicitCastExpr(ConstraintParser constraintParser, String patternIdentifier, List<PatternConstraintParseResult> patternConstraintParseResults) {
final boolean hasInstanceOfExpr = patternConstraintParseResults.stream().anyMatch(r -> r.getDrlxParseResult().acceptWithReturnValue(new ParseResultVisitor<Boolean>() {
@Override
public Boolean onSuccess(DrlxParseSuccess t) {
Expression expr = t.getExpr();
return expr != null && expr.isInstanceOfExpr();
}
@Override
public Boolean onFail(DrlxParseFail failure) {
return false;
}
}));
final Optional<Expression> implicitCastExpression = patternConstraintParseResults.stream().flatMap(r -> optionalToStream(r.getDrlxParseResult().acceptWithReturnValue(new ParseResultVisitor<Optional<Expression>>() {
@Override
public Optional<Expression> onSuccess(DrlxParseSuccess t) {
return t.getImplicitCastExpression();
}
@Override
public Optional<Expression> onFail(DrlxParseFail failure) {
return Optional.empty();
}
}))).findFirst();
implicitCastExpression.ifPresent(ce -> {
if (!hasInstanceOfExpr) {
String instanceOfExpression = printNode(ce);
DrlxParseResult instanceOfExpressionParsed = constraintParser.drlxParse(patternType, patternIdentifier, instanceOfExpression, false);
patternConstraintParseResults.add(0, new PatternConstraintParseResult(instanceOfExpression, patternIdentifier, instanceOfExpressionParsed));
}
});
}
Aggregations