Search in sources :

Example 11 with DrlxParseSuccess

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));
        }
    });
}
Also used : DrlxParseUtil.validateDuplicateBindings(org.drools.modelcompiler.builder.generator.DrlxParseUtil.validateDuplicateBindings) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) AggregateKey(org.drools.modelcompiler.builder.generator.AggregateKey) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) PatternSourceDescr(org.drools.drl.ast.descr.PatternSourceDescr) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) DescrBuildError(org.drools.compiler.compiler.DescrBuildError) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) ConstraintExpression(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintExpression) DrlxParseUtil.getPatternListenedProperties(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getPatternListenedProperties) PatternDescr(org.drools.drl.ast.descr.PatternDescr) InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) GENERATED_VARIABLE_PREFIX(org.drools.model.impl.VariableImpl.GENERATED_VARIABLE_PREFIX) ConstraintUtil(org.drools.modelcompiler.builder.generator.ConstraintUtil) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) NamesGenerator.generateName(org.drools.model.impl.NamesGenerator.generateName) Expression(com.github.javaparser.ast.expr.Expression) ConstraintParser(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintParser) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) PackageModel(org.drools.modelcompiler.builder.PackageModel) WindowReferenceGenerator(org.drools.modelcompiler.builder.generator.WindowReferenceGenerator) ClassUtils(org.drools.core.util.ClassUtils) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Set(java.util.Set) PatternBuilder.lookAheadFieldsOfIdentifier(org.drools.compiler.rule.builder.PatternBuilder.lookAheadFieldsOfIdentifier) StreamUtils.optionalToStream(org.drools.modelcompiler.util.StreamUtils.optionalToStream) FromVisitor(org.drools.modelcompiler.builder.generator.visitor.FromVisitor) Collectors(java.util.stream.Collectors) BaseDescr(org.drools.drl.ast.descr.BaseDescr) Objects(java.util.Objects) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) List(java.util.List) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) DSLNode(org.drools.modelcompiler.builder.generator.visitor.DSLNode) ParseResultVoidVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVoidVisitor) Watch(org.kie.api.definition.rule.Watch) Optional(java.util.Optional) ParseResultVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVisitor) Collections(java.util.Collections) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail) ConstraintExpression(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) ParseResultVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVisitor) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail)

Aggregations

DrlxParseSuccess (org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess)11 DrlxParseResult (org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult)8 SingleDrlxParseSuccess (org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess)7 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)5 ArrayList (java.util.ArrayList)5 ConstraintParser (org.drools.modelcompiler.builder.generator.drlxparse.ConstraintParser)5 DrlxParseFail (org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail)5 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)4 Expression (com.github.javaparser.ast.expr.Expression)4 Collection (java.util.Collection)4 List (java.util.List)4 Objects (java.util.Objects)4 AccumulateDescr (org.drools.drl.ast.descr.AccumulateDescr)4 BaseDescr (org.drools.drl.ast.descr.BaseDescr)4 MethodCallExpr (org.drools.javaparser.ast.expr.MethodCallExpr)4 DeclarationSpec (org.drools.modelcompiler.builder.generator.DeclarationSpec)4 DrlxParseUtil (org.drools.modelcompiler.builder.generator.DrlxParseUtil)4 ParseResultVisitor (org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVisitor)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3