Search in sources :

Example 1 with BREAKING_CALL

use of org.drools.modelcompiler.builder.generator.visitor.NamedConsequenceVisitor.BREAKING_CALL in project drools by kiegroup.

the class Consequence method createCall.

public MethodCallExpr createCall(RuleDescr ruleDescr, String consequenceString, BlockStmt ruleVariablesBlock, boolean isBreaking) {
    BlockStmt ruleConsequence = rewriteConsequence(consequenceString);
    if (ruleConsequence != null) {
        ruleConsequence.findAll(Expression.class).stream().filter(s -> isNameExprWithName(s, "kcontext")).forEach(n -> n.replace(new NameExpr("drools")));
    }
    Collection<String> usedDeclarationInRHS = extractUsedDeclarations(ruleConsequence, consequenceString);
    MethodCallExpr onCall = onCall(usedDeclarationInRHS);
    if (isBreaking) {
        onCall = new MethodCallExpr(onCall, BREAKING_CALL);
    }
    MethodCallExpr executeCall = null;
    if (context.getRuleDialect() == RuleContext.RuleDialect.JAVA) {
        executeCall = executeCall(ruleVariablesBlock, ruleConsequence, usedDeclarationInRHS, onCall);
    } else if (context.getRuleDialect() == RuleContext.RuleDialect.MVEL) {
        executeCall = executeScriptCall(ruleDescr, onCall);
    }
    return executeCall;
}
Also used : BitMask(org.drools.model.BitMask) ClassOrInterfaceType(org.drools.javaparser.ast.type.ClassOrInterfaceType) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) Expression(org.drools.javaparser.ast.expr.Expression) DrlxParseUtil.isNameExprWithName(org.drools.modelcompiler.builder.generator.DrlxParseUtil.isNameExprWithName) DroolsImpl(org.drools.modelcompiler.consequence.DroolsImpl) JavaParser(org.drools.javaparser.JavaParser) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BlockStmt(org.drools.javaparser.ast.stmt.BlockStmt) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AssignExpr(org.drools.javaparser.ast.expr.AssignExpr) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr) BREAKING_CALL(org.drools.modelcompiler.builder.generator.visitor.NamedConsequenceVisitor.BREAKING_CALL) LambdaExpr(org.drools.javaparser.ast.expr.LambdaExpr) JavaParser.parseExpression(org.drools.javaparser.JavaParser.parseExpression) Statement(org.drools.javaparser.ast.stmt.Statement) Collectors.toSet(java.util.stream.Collectors.toSet) PackageModel(org.drools.modelcompiler.builder.PackageModel) ObjectCreationExpr(org.drools.javaparser.ast.expr.ObjectCreationExpr) DrlxParseUtil.hasScope(org.drools.modelcompiler.builder.generator.DrlxParseUtil.hasScope) Parameter(org.drools.javaparser.ast.body.Parameter) ClassUtils(org.drools.core.util.ClassUtils) Collection(java.util.Collection) DrlxParseUtil.parseBlock(org.drools.modelcompiler.builder.generator.DrlxParseUtil.parseBlock) Set(java.util.Set) EmptyStmt(org.drools.javaparser.ast.stmt.EmptyStmt) ClassExpr(org.drools.javaparser.ast.expr.ClassExpr) NameExpr(org.drools.javaparser.ast.expr.NameExpr) StringLiteralExpr(org.drools.javaparser.ast.expr.StringLiteralExpr) Objects(java.util.Objects) VariableDeclarationExpr(org.drools.javaparser.ast.expr.VariableDeclarationExpr) UnknownType(org.drools.javaparser.ast.type.UnknownType) DrlxParseUtil.findAllChildrenRecursive(org.drools.modelcompiler.builder.generator.DrlxParseUtil.findAllChildrenRecursive) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Modifier(org.drools.javaparser.ast.Modifier) SimpleName(org.drools.javaparser.ast.expr.SimpleName) StringUtils(org.drools.core.util.StringUtils) Expression(org.drools.javaparser.ast.expr.Expression) JavaParser.parseExpression(org.drools.javaparser.JavaParser.parseExpression) BlockStmt(org.drools.javaparser.ast.stmt.BlockStmt) NameExpr(org.drools.javaparser.ast.expr.NameExpr) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)1 ClassUtils (org.drools.core.util.ClassUtils)1 StringUtils (org.drools.core.util.StringUtils)1 JavaParser (org.drools.javaparser.JavaParser)1 JavaParser.parseExpression (org.drools.javaparser.JavaParser.parseExpression)1 Modifier (org.drools.javaparser.ast.Modifier)1 Parameter (org.drools.javaparser.ast.body.Parameter)1 AssignExpr (org.drools.javaparser.ast.expr.AssignExpr)1 ClassExpr (org.drools.javaparser.ast.expr.ClassExpr)1 Expression (org.drools.javaparser.ast.expr.Expression)1 LambdaExpr (org.drools.javaparser.ast.expr.LambdaExpr)1