Search in sources :

Example 1 with ParseResultVoidVisitor

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());
            }
        }
    });
}
Also used : DSLNode(org.drools.modelcompiler.builder.generator.visitor.DSLNode) DescrBuildError(org.drools.compiler.compiler.DescrBuildError) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) ParseResultVoidVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVoidVisitor) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail)

Aggregations

DescrBuildError (org.drools.compiler.compiler.DescrBuildError)1 DrlxParseFail (org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail)1 DrlxParseResult (org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult)1 DrlxParseSuccess (org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess)1 ParseResultVoidVisitor (org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVoidVisitor)1 SingleDrlxParseSuccess (org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess)1 DSLNode (org.drools.modelcompiler.builder.generator.visitor.DSLNode)1