Search in sources :

Example 31 with Expression

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);
    }
}
Also used : TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) Expression(org.drools.javaparser.ast.expr.Expression)

Example 32 with Expression

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);
}
Also used : Expression(org.drools.javaparser.ast.expr.Expression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) NameExpr(org.drools.javaparser.ast.expr.NameExpr) EnclosedExpr(org.drools.javaparser.ast.expr.EnclosedExpr) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 33 with Expression

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;
}
Also used : Expression(org.drools.javaparser.ast.expr.Expression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) NameExpr(org.drools.javaparser.ast.expr.NameExpr) EnclosedExpr(org.drools.javaparser.ast.expr.EnclosedExpr) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 34 with Expression

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;
}
Also used : UnknownType(org.drools.javaparser.ast.type.UnknownType) Expression(org.drools.javaparser.ast.expr.Expression) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) QueryGenerator(org.drools.modelcompiler.builder.generator.QueryGenerator) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) Optional.of(java.util.Optional.of) JavaParser(org.drools.javaparser.JavaParser) ArrayList(java.util.ArrayList) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr) FieldAccessExpr(org.drools.javaparser.ast.expr.FieldAccessExpr) ExpressionStmt(org.drools.javaparser.ast.stmt.ExpressionStmt) DrlxParseUtil.toVar(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toVar) LambdaExpr(org.drools.javaparser.ast.expr.LambdaExpr) EnclosedExpr(org.drools.javaparser.ast.expr.EnclosedExpr) Parameter(org.drools.javaparser.ast.body.Parameter) Collection(java.util.Collection) 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) UnknownType(org.drools.javaparser.ast.type.UnknownType) IndexUtil(org.drools.core.util.index.IndexUtil) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) List(java.util.List) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) Stream(java.util.stream.Stream) Optional(java.util.Optional) LambdaExpr(org.drools.javaparser.ast.expr.LambdaExpr) Parameter(org.drools.javaparser.ast.body.Parameter) ExpressionStmt(org.drools.javaparser.ast.stmt.ExpressionStmt)

Example 35 with Expression

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);
        });
    }
}
Also used : NullLiteralExpr(org.drools.javaparser.ast.expr.NullLiteralExpr) Expression(org.drools.javaparser.ast.expr.Expression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) BinaryExpr(org.drools.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.javaparser.ast.drlx.expr.HalfBinaryExpr) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression)

Aggregations

Expression (org.drools.javaparser.ast.expr.Expression)48 MethodCallExpr (org.drools.javaparser.ast.expr.MethodCallExpr)32 NameExpr (org.drools.javaparser.ast.expr.NameExpr)25 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)19 List (java.util.List)14 ArrayList (java.util.ArrayList)13 Optional (java.util.Optional)13 FieldAccessExpr (org.drools.javaparser.ast.expr.FieldAccessExpr)13 BinaryExpr (org.drools.javaparser.ast.expr.BinaryExpr)11 EnclosedExpr (org.drools.javaparser.ast.expr.EnclosedExpr)11 PackageModel (org.drools.modelcompiler.builder.PackageModel)11 RuleContext (org.drools.modelcompiler.builder.generator.RuleContext)11 Node (org.drools.javaparser.ast.Node)10 StringLiteralExpr (org.drools.javaparser.ast.expr.StringLiteralExpr)10 Collection (java.util.Collection)9 Parameter (org.drools.javaparser.ast.body.Parameter)9 LambdaExpr (org.drools.javaparser.ast.expr.LambdaExpr)9 DeclarationSpec (org.drools.modelcompiler.builder.generator.DeclarationSpec)9 DrlxParseUtil.toVar (org.drools.modelcompiler.builder.generator.DrlxParseUtil.toVar)8 JavaParser (org.drools.javaparser.JavaParser)7