use of org.drools.javaparser.ast.expr.Expression in project drools by kiegroup.
the class AbstractExpressionBuilder method processExpression.
public void processExpression(DrlxParseSuccess drlxParseResult) {
if (drlxParseResult.hasUnificationVariable()) {
Expression dslExpr = buildUnificationExpression(drlxParseResult);
context.addExpression(dslExpr);
} else if (drlxParseResult.isValidExpression()) {
Expression dslExpr = buildExpressionWithIndexing(drlxParseResult);
context.addExpression(dslExpr);
}
if (drlxParseResult.getExprBinding() != null) {
Expression dslExpr = buildBinding(drlxParseResult);
context.addExpression(dslExpr);
}
}
use of org.drools.javaparser.ast.expr.Expression in project drools by kiegroup.
the class FlowExpressionBuilder method buildBinding.
public MethodCallExpr buildBinding(DrlxParseSuccess drlxParseResult) {
MethodCallExpr bindDSL = new MethodCallExpr(null, BIND_CALL);
if (drlxParseResult.hasUnificationVariable()) {
bindDSL.addArgument(new NameExpr(toVar(drlxParseResult.getUnificationVariable())));
} else {
bindDSL.addArgument(new NameExpr(toVar(drlxParseResult.getExprBinding())));
}
MethodCallExpr bindAsDSL = new MethodCallExpr(bindDSL, BIND_AS_CALL);
bindAsDSL.addArgument(new NameExpr(toVar(drlxParseResult.getPatternBinding())));
final Expression constraintExpression = drlxParseResult.getExpr() instanceof EnclosedExpr ? buildConstraintExpression(drlxParseResult, ((EnclosedExpr) drlxParseResult.getExpr()).getInner()) : buildConstraintExpression(drlxParseResult, drlxParseResult.getUsedDeclarationsOnLeft(), DrlxParseUtil.findLeftLeafOfMethodCall(drlxParseResult.getLeft().getExpression()));
bindAsDSL.addArgument(constraintExpression);
return buildReactOn(drlxParseResult, bindAsDSL);
}
use of org.drools.javaparser.ast.expr.Expression in project drools by kiegroup.
the class PatternExpressionBuilder method buildBinding.
@Override
public MethodCallExpr buildBinding(DrlxParseSuccess drlxParseResult) {
MethodCallExpr bindDSL = new MethodCallExpr(null, BIND_CALL);
if (drlxParseResult.hasUnificationVariable()) {
bindDSL.addArgument(new NameExpr(toVar(drlxParseResult.getUnificationVariable())));
} else {
bindDSL.addArgument(new NameExpr(toVar(drlxParseResult.getExprBinding())));
}
final Expression constraintExpression = drlxParseResult.getExpr() instanceof EnclosedExpr ? buildConstraintExpression(drlxParseResult, ((EnclosedExpr) drlxParseResult.getExpr()).getInner()) : buildConstraintExpression(drlxParseResult, drlxParseResult.getUsedDeclarationsOnLeft(), DrlxParseUtil.findLeftLeafOfMethodCall(drlxParseResult.getLeft().getExpression()));
bindDSL.addArgument(constraintExpression);
final Optional<MethodCallExpr> methodCallExpr = buildReactOn(drlxParseResult);
methodCallExpr.ifPresent(bindDSL::addArgument);
return bindDSL;
}
use of org.drools.javaparser.ast.expr.Expression in project drools by kiegroup.
the class PatternExpressionBuilder method generateLambdaWithoutParameters.
public Expression generateLambdaWithoutParameters(Collection<String> usedDeclarations, Expression expr, boolean skipFirstParamAsThis) {
if (skipFirstParamAsThis && usedDeclarations.isEmpty()) {
return expr;
}
LambdaExpr lambdaExpr = new LambdaExpr();
lambdaExpr.setEnclosingParameters(true);
if (!skipFirstParamAsThis) {
lambdaExpr.addParameter(new Parameter(new UnknownType(), "_this"));
}
usedDeclarations.stream().map(s -> new Parameter(new UnknownType(), s)).forEach(lambdaExpr::addParameter);
lambdaExpr.setBody(new ExpressionStmt(expr));
return lambdaExpr;
}
use of org.drools.javaparser.ast.expr.Expression in project drools by kiegroup.
the class ExpressionTyper method extractPrefixExpressions.
private void extractPrefixExpressions(NullSafeFieldAccessExpr drlxExpr, Expression previous) {
final BinaryExpr prefixExpression = new BinaryExpr(previous, new NullLiteralExpr(), BinaryExpr.Operator.NOT_EQUALS);
prefixExpressions.add(prefixExpression);
final Expression scope = drlxExpr.getScope();
if (scope != null) {
final Optional<TypedExpression> typedExpression1 = toTypedExpressionRec(scope);
typedExpression1.ifPresent(te -> {
final Expression expression = te.getExpression();
final BinaryExpr notNullScope = new BinaryExpr(expression, new NullLiteralExpr(), BinaryExpr.Operator.NOT_EQUALS);
prefixExpressions.add(0, notNullScope);
});
}
}
Aggregations