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();
}
}
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();
}
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());
}
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);
}
}
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;
}
Aggregations