Search in sources :

Example 21 with StringLiteralExpr

use of org.drools.javaparser.ast.expr.StringLiteralExpr 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

StringLiteralExpr (org.drools.javaparser.ast.expr.StringLiteralExpr)21 MethodCallExpr (org.drools.javaparser.ast.expr.MethodCallExpr)19 ClassExpr (org.drools.javaparser.ast.expr.ClassExpr)6 Expression (org.drools.javaparser.ast.expr.Expression)6 NameExpr (org.drools.javaparser.ast.expr.NameExpr)5 ArrayList (java.util.ArrayList)4 AssignExpr (org.drools.javaparser.ast.expr.AssignExpr)4 BinaryExpr (org.drools.javaparser.ast.expr.BinaryExpr)4 ClassOrInterfaceType (org.drools.javaparser.ast.type.ClassOrInterfaceType)4 HashMap (java.util.HashMap)3 JavaParser.parseExpression (org.drools.javaparser.JavaParser.parseExpression)3 VariableDeclarationExpr (org.drools.javaparser.ast.expr.VariableDeclarationExpr)3 List (java.util.List)2 Map (java.util.Map)2 AnnotationDescr (org.drools.compiler.lang.descr.AnnotationDescr)2 MethodDeclaration (org.drools.javaparser.ast.body.MethodDeclaration)2 PointFreeExpr (org.drools.javaparser.ast.drlx.expr.PointFreeExpr)2 CastExpr (org.drools.javaparser.ast.expr.CastExpr)2 EnclosedExpr (org.drools.javaparser.ast.expr.EnclosedExpr)2 IntegerLiteralExpr (org.drools.javaparser.ast.expr.IntegerLiteralExpr)2