Search in sources :

Example 61 with MethodCallExpr

use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.

the class AndVisitor method visit.

public void visit(AndDescr descr) {
    // if it's the first (implied) `and` wrapping the first level of patterns, skip adding it to the DSL.
    if (this.context.getExprPointerLevel() != 1) {
        final MethodCallExpr andDSL = new MethodCallExpr(null, "and");
        this.context.addExpression(andDSL);
        this.context.pushExprPointer(andDSL::addArgument);
    }
    for (BaseDescr subDescr : descr.getDescrs()) {
        this.context.parentDesc = descr;
        subDescr.accept(visitor);
    }
    if (this.context.getExprPointerLevel() != 1) {
        this.context.popExprPointer();
    }
}
Also used : BaseDescr(org.drools.compiler.lang.descr.BaseDescr) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 62 with MethodCallExpr

use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.

the class ConditionalElementVisitor method visit.

public void visit(ConditionalElementDescr descr, String methodName) {
    final MethodCallExpr ceDSL = new MethodCallExpr(null, methodName);
    this.context.addExpression(ceDSL);
    this.context.pushExprPointer(ceDSL::addArgument);
    for (BaseDescr subDescr : descr.getDescrs()) {
        subDescr.accept(visitor);
    }
    this.context.popExprPointer();
}
Also used : BaseDescr(org.drools.compiler.lang.descr.BaseDescr) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 63 with MethodCallExpr

use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.

the class NamedConsequenceVisitor method visit.

public void visit(ConditionalBranchDescr desc) {
    PatternDescr patternRelated = (PatternDescr) getReferringPatternDescr(desc, (AndDescr) context.parentDesc);
    Class<?> patternRelatedClass = getClassFromContext(context.getTypeResolver(), patternRelated.getObjectType());
    MethodCallExpr whenBlock = whenThenDSL(desc, patternRelated, patternRelatedClass, WHEN_CALL, null);
    recurseAmongElseBranch(patternRelatedClass, patternRelated, whenBlock, desc.getElseBranch());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 64 with MethodCallExpr

use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.

the class NamedConsequenceVisitor method recurseAmongElseBranch.

private void recurseAmongElseBranch(Class<?> patternType, PatternDescr patternRelated, MethodCallExpr parentMethodExpr, ConditionalBranchDescr branch) {
    if (branch != null) {
        MethodCallExpr elseWhenBlock = whenThenDSL(branch, patternRelated, patternType, ELSE_WHEN_CALL, parentMethodExpr);
        recurseAmongElseBranch(patternType, patternRelated, elseWhenBlock, branch.getElseBranch());
    } else {
        context.addExpression(parentMethodExpr);
    }
}
Also used : MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 65 with MethodCallExpr

use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.

the class NamedConsequenceVisitor method whenThenDSL.

private MethodCallExpr whenThenDSL(ConditionalBranchDescr desc, PatternDescr patternRelated, Class<?> patternType, String callMethod, MethodCallExpr parentExpression) {
    MethodCallExpr when = new MethodCallExpr(parentExpression, callMethod);
    final String condition = desc.getCondition().toString();
    if (!condition.equals("true")) {
        // Default case
        when.addArgument(new StringLiteralExpr(context.getConditionId(patternType, condition)));
        when.addArgument(new NameExpr(toVar(patternRelated.getIdentifier())));
        DrlxParseResult parseResult = new ConstraintParser(context, packageModel).drlxParse(patternType, patternRelated.getIdentifier(), condition);
        parseResult.accept(parseSuccess -> when.addArgument(generateLambdaWithoutParameters(Collections.emptySortedSet(), parseSuccess.getExpr())));
    }
    MethodCallExpr then = new MethodCallExpr(when, THEN_CALL);
    MethodCallExpr rhs = onDSL(desc.getConsequence());
    then.addArgument(rhs);
    return then;
}
Also used : ConstraintParser(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintParser) StringLiteralExpr(org.drools.javaparser.ast.expr.StringLiteralExpr) NameExpr(org.drools.javaparser.ast.expr.NameExpr) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Aggregations

MethodCallExpr (org.drools.javaparser.ast.expr.MethodCallExpr)75 NameExpr (org.drools.javaparser.ast.expr.NameExpr)36 Expression (org.drools.javaparser.ast.expr.Expression)32 StringLiteralExpr (org.drools.javaparser.ast.expr.StringLiteralExpr)26 ArrayList (java.util.ArrayList)16 List (java.util.List)15 ClassExpr (org.drools.javaparser.ast.expr.ClassExpr)15 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)14 FieldAccessExpr (org.drools.javaparser.ast.expr.FieldAccessExpr)13 PackageModel (org.drools.modelcompiler.builder.PackageModel)13 Parameter (org.drools.javaparser.ast.body.Parameter)11 LambdaExpr (org.drools.javaparser.ast.expr.LambdaExpr)11 ClassOrInterfaceType (org.drools.javaparser.ast.type.ClassOrInterfaceType)11 Collection (java.util.Collection)10 Optional (java.util.Optional)10 Type (org.drools.javaparser.ast.type.Type)10 RuleContext (org.drools.modelcompiler.builder.generator.RuleContext)10 BinaryExpr (org.drools.javaparser.ast.expr.BinaryExpr)9 DeclarationSpec (org.drools.modelcompiler.builder.generator.DeclarationSpec)9 JavaParser (org.drools.javaparser.JavaParser)8