use of org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVoidVisitor in project drools by kiegroup.
the class PatternDSL method buildConstraint.
void buildConstraint(PatternDescr pattern, Class<?> patternType, PatternConstraintParseResult patternConstraintParseResult) {
DrlxParseResult drlxParseResult = patternConstraintParseResult.getDrlxParseResult();
DrlxParseResult withBindingCheck = drlxParseResult.acceptWithReturnValue(new ParseResultVisitor<DrlxParseResult>() {
@Override
public DrlxParseResult onSuccess(DrlxParseSuccess drlxParseResult) {
String exprBinding = drlxParseResult.getExprBinding();
if (exprBinding == null && !drlxParseResult.isPredicate() && !drlxParseResult.getImplicitCastExpression().isPresent()) {
return new DrlxParseFail(new DescrBuildError(context.getRuleDescr(), context.getRuleDescr(), "", String.format("Predicate '%s' must be a Boolean expression", drlxParseResult.getOriginalDrlConstraint())));
} else {
return drlxParseResult;
}
}
@Override
public DrlxParseResult onFail(DrlxParseFail failure) {
return failure;
}
});
withBindingCheck.accept(new ParseResultVoidVisitor() {
@Override
public void onSuccess(DrlxParseSuccess drlxParseResult) {
DSLNode constraint = drlxParseResult.isOOPath() ? new ConstraintOOPath(context, packageModel, pattern, patternType, patternConstraintParseResult, drlxParseResult) : createSimpleConstraint(drlxParseResult, pattern);
constraint.buildPattern();
registerUsedBindingInOr(drlxParseResult.getExprBinding());
}
@Override
public void onFail(DrlxParseFail failure) {
if (failure.getError() != null) {
context.addCompilationError(failure.getError());
}
}
});
}
Aggregations