Search in sources :

Example 66 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class FromHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final FromDescr fromDescr = (FromDescr) parser.getCurrent();
    Object parent = parser.getParent();
    final PatternDescr patternDescr = (PatternDescr) parent;
    final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parser.getParent(1);
    if (element.getElementsByTagName("expression").getLength() > 0) {
        patternDescr.setSource(fromDescr);
    }
    return fromDescr;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) Element(org.w3c.dom.Element) FromDescr(org.drools.drl.ast.descr.FromDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 67 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class ExprConstraintHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final String expression = ((org.w3c.dom.Text) element.getChildNodes().item(0)).getWholeText();
    emptyContentCheck(localName, expression, parser);
    PatternDescr p = (PatternDescr) parser.getParent();
    ExprConstraintDescr descr = new ExprConstraintDescr(expression);
    p.getConstraint().addDescr(descr);
    return descr;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) Element(org.w3c.dom.Element) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr)

Example 68 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class CollectHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final CollectDescr collectDescr = (CollectDescr) parser.getCurrent();
    final Object parent = parser.getParent();
    if (parent.getClass().getName().equals(FromDescr.class.getName())) {
        final PatternDescr resultPattern = (PatternDescr) parser.getParent(1);
        resultPattern.setSource(collectDescr);
    } else if (parent instanceof ConditionalElementDescr) {
        final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent;
        parentDescr.addDescr(collectDescr);
    }
    return collectDescr;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) CollectDescr(org.drools.drl.ast.descr.CollectDescr) Element(org.w3c.dom.Element) FromDescr(org.drools.drl.ast.descr.FromDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 69 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class RuleBuilder method getLhsForRuleUnit.

private static AndDescr getLhsForRuleUnit(RuleImpl rule, AndDescr lhs) {
    if (rule.hasRuleUnit()) {
        PatternDescr unitPattern = new PatternDescr(rule.getRuleUnitClassName(), RULE_UNIT_DECLARATION);
        unitPattern.setSource(EntryPointDescr.RULE_UNIT_ENTRY_POINT_DESCR);
        unitPattern.setResource(rule.getResource());
        lhs.getDescrs().add(0, unitPattern);
    }
    return lhs;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr)

Example 70 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class AccumulateVisitor method binaryExprParameter.

private Optional<NewBinding> binaryExprParameter(PatternDescr basePattern, AccumulateDescr.AccumulateFunctionCallDescr function, MethodCallExpr functionDSL, String bindingId, String accumulateFunctionParameterStr) {
    final DrlxParseResult parseResult = ConstraintParser.defaultConstraintParser(context, packageModel).drlxParse(Object.class, bindingId, accumulateFunctionParameterStr);
    Optional<NewBinding> optNewBinding = parseResult.acceptWithReturnValue(new ParseResultVisitor<Optional<NewBinding>>() {

        @Override
        public Optional<NewBinding> onSuccess(DrlxParseSuccess drlxParseResult) {
            SingleDrlxParseSuccess singleResult = (SingleDrlxParseSuccess) drlxParseResult;
            Class<?> exprRawClass = singleResult.getExprRawClass();
            AccumulateFunction accumulateFunction = getAccumulateFunction(function, exprRawClass);
            validateAccFunctionTypeAgainstPatternType(context, basePattern, accumulateFunction);
            final String bindExpressionVariable = context.getExprId(accumulateFunction.getResultType(), singleResult.getLeft().toString());
            singleResult.setExprBinding(bindExpressionVariable);
            context.addDeclarationReplacing(new DeclarationSpec(singleResult.getPatternBinding(), exprRawClass));
            context.getExpressions().forEach(expression -> replaceTypeInExprLambda(bindingId, exprRawClass, expression));
            functionDSL.addArgument(createAccSupplierExpr(accumulateFunction));
            final MethodCallExpr newBindingFromBinary = AccumulateVisitor.this.buildBinding(bindExpressionVariable, singleResult.getUsedDeclarations(), singleResult.getExpr());
            context.addDeclarationReplacing(new DeclarationSpec(bindExpressionVariable, exprRawClass));
            functionDSL.addArgument(context.getVarExpr(bindExpressionVariable));
            return Optional.of(new NewBinding(Collections.emptyList(), newBindingFromBinary));
        }

        @Override
        public Optional<NewBinding> onFail(DrlxParseFail failure) {
            return Optional.empty();
        }
    });
    return optNewBinding;
}
Also used : SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) REACT_ON_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.REACT_ON_CALL) ModelGeneratorVisitor(org.drools.modelcompiler.builder.generator.visitor.ModelGeneratorVisitor) ACCUMULATE_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.ACCUMULATE_CALL) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) PatternDescr(org.drools.drl.ast.descr.PatternDescr) InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) ExpressionTyperContext(org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyperContext) LiteralExpr(com.github.javaparser.ast.expr.LiteralExpr) AccumulateUtil(org.drools.compiler.rule.builder.util.AccumulateUtil) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) Expression(com.github.javaparser.ast.expr.Expression) ConstraintParser(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintParser) PatternExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.PatternExpressionBuilder) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) Node(com.github.javaparser.ast.Node) PackageModel(org.drools.modelcompiler.builder.PackageModel) NodeList(com.github.javaparser.ast.NodeList) AND_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.AND_CALL) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Set(java.util.Set) LambdaUtil(org.drools.modelcompiler.util.LambdaUtil) BaseDescr(org.drools.drl.ast.descr.BaseDescr) VALUE_OF_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.VALUE_OF_CALL) Objects(java.util.Objects) List(java.util.List) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail) DrlxParseUtil.validateDuplicateBindings(org.drools.modelcompiler.builder.generator.DrlxParseUtil.validateDuplicateBindings) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) AbstractExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.AbstractExpressionBuilder) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) Parameter(com.github.javaparser.ast.body.Parameter) Pattern(org.drools.core.rule.Pattern) ArrayList(java.util.ArrayList) ACC_FUNCTION_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.ACC_FUNCTION_CALL) HashSet(java.util.HashSet) CollectListAccumulateFunction(org.drools.core.base.accumulators.CollectListAccumulateFunction) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) DrlxParseUtil.getLiteralExpressionType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getLiteralExpressionType) DslMethodNames.createDslTopLevelMethod(org.drools.modelcompiler.builder.generator.DslMethodNames.createDslTopLevelMethod) AndDescr(org.drools.drl.ast.descr.AndDescr) ReplaceTypeInLambda.replaceTypeInExprLambda(org.drools.modelcompiler.util.lambdareplace.ReplaceTypeInLambda.replaceTypeInExprLambda) BIND_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.BIND_CALL) Optional.ofNullable(java.util.Optional.ofNullable) BIND_AS_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.BIND_AS_CALL) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr) ExpressionTyper(org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyper) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) Collectors.toList(java.util.stream.Collectors.toList) CollectAccumulator(org.drools.core.base.accumulators.CollectAccumulator) CollectSetAccumulateFunction(org.drools.core.base.accumulators.CollectSetAccumulateFunction) ParseResultVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVisitor) Collections(java.util.Collections) Optional(java.util.Optional) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) CollectListAccumulateFunction(org.drools.core.base.accumulators.CollectListAccumulateFunction) CollectSetAccumulateFunction(org.drools.core.base.accumulators.CollectSetAccumulateFunction) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

PatternDescr (org.drools.drl.ast.descr.PatternDescr)162 Test (org.junit.Test)131 RuleDescr (org.drools.drl.ast.descr.RuleDescr)103 PackageDescr (org.drools.drl.ast.descr.PackageDescr)84 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)65 AndDescr (org.drools.drl.ast.descr.AndDescr)61 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)18 AccumulateDescr (org.drools.drl.ast.descr.AccumulateDescr)18 FromDescr (org.drools.drl.ast.descr.FromDescr)16 BaseDescr (org.drools.drl.ast.descr.BaseDescr)15 NotDescr (org.drools.drl.ast.descr.NotDescr)14 Cheese (org.drools.mvel.compiler.Cheese)14 OrDescr (org.drools.drl.ast.descr.OrDescr)13 BindingDescr (org.drools.drl.ast.descr.BindingDescr)11 Element (org.w3c.dom.Element)9 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)8 InputStreamReader (java.io.InputStreamReader)7 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)7 GlobalDescr (org.drools.drl.ast.descr.GlobalDescr)7 MVELExprDescr (org.drools.drl.ast.descr.MVELExprDescr)7