Search in sources :

Example 11 with TypedExpressionResult

use of org.drools.modelcompiler.builder.generator.expressiontyper.TypedExpressionResult in project drools by kiegroup.

the class Query method createFromExpr.

private MethodCallExpr createFromExpr(String variableName, Expression expr) {
    MethodCallExpr dslExpr = createDslTopLevelMethod(PATTERN_CALL);
    dslExpr.addArgument(context.getVarExpr(variableName));
    context.addExpression(dslExpr);
    MethodCallExpr fromExpr = createDslTopLevelMethod(FROM_CALL);
    LambdaExpr lambdaExpr = new LambdaExpr();
    lambdaExpr.setEnclosingParameters(true);
    TypedExpressionResult result = new ExpressionTyper(context).toTypedExpression(expr);
    for (String usedDeclration : result.getExpressionTyperContext().getUsedDeclarations()) {
        fromExpr.addArgument(context.getVarExpr(usedDeclration));
        lambdaExpr.addParameter(new Parameter(context.getDelarationType(usedDeclration), usedDeclration));
    }
    fromExpr.addArgument(lambdaExpr);
    if (result.getTypedExpression().isPresent()) {
        lambdaExpr.setBody(new ExpressionStmt(result.getTypedExpression().get().getExpression()));
    }
    return fromExpr;
}
Also used : LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) Parameter(com.github.javaparser.ast.body.Parameter) QueryParameter(org.drools.modelcompiler.builder.generator.QueryParameter) ExpressionTyper(org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyper) TypedExpressionResult(org.drools.modelcompiler.builder.generator.expressiontyper.TypedExpressionResult) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

ExpressionTyper (org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyper)11 TypedExpressionResult (org.drools.modelcompiler.builder.generator.expressiontyper.TypedExpressionResult)11 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)8 Expression (com.github.javaparser.ast.expr.Expression)6 NameExpr (com.github.javaparser.ast.expr.NameExpr)5 ExpressionTyperContext (org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyperContext)5 DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)5 ArrayList (java.util.ArrayList)4 ParseExpressionErrorResult (org.drools.modelcompiler.builder.errors.ParseExpressionErrorResult)4 DrlxParseUtil.getLiteralExpressionType (org.drools.modelcompiler.builder.generator.DrlxParseUtil.getLiteralExpressionType)4 DrlNameExpr (org.drools.mvel.parser.ast.expr.DrlNameExpr)4 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)3 DeclarationSpec (org.drools.modelcompiler.builder.generator.DeclarationSpec)3 PointFreeExpr (org.drools.mvel.parser.ast.expr.PointFreeExpr)3 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)2 CastExpr (com.github.javaparser.ast.expr.CastExpr)2 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)2 SimpleName (com.github.javaparser.ast.expr.SimpleName)2 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)2 ThisExpr (com.github.javaparser.ast.expr.ThisExpr)2