Search in sources :

Example 1 with ListCreationLiteralExpressionElement

use of org.drools.mvel.parser.ast.expr.ListCreationLiteralExpressionElement in project drools by kiegroup.

the class ExpressionTyper method listCreationLiteral.

private Optional<TypedExpressionCursor> listCreationLiteral(ListCreationLiteralExpression listCreationLiteralExpression, java.lang.reflect.Type originalTypeCursor) {
    ClassOrInterfaceType arrayListType = (ClassOrInterfaceType) parseType(ArrayList.class.getCanonicalName());
    BlockStmt initializationStmt = new BlockStmt();
    InitializerDeclaration body = new InitializerDeclaration(false, initializationStmt);
    ObjectCreationExpr newArrayListExpr = new ObjectCreationExpr(null, arrayListType, nodeList(), nodeList(), nodeList(body));
    for (Expression e : listCreationLiteralExpression.getExpressions()) {
        ListCreationLiteralExpressionElement expr = (ListCreationLiteralExpressionElement) e;
        Expression value = resolveCreationLiteralNameExpr(originalTypeCursor, expr.getValue());
        initializationStmt.addStatement(new MethodCallExpr(null, "add", nodeList(value)));
    }
    return of(new TypedExpressionCursor(newArrayListExpr, ArrayList.class));
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) InitializerDeclaration(com.github.javaparser.ast.body.InitializerDeclaration) Expression(com.github.javaparser.ast.expr.Expression) UnificationTypedExpression(org.drools.modelcompiler.builder.generator.UnificationTypedExpression) MapCreationLiteralExpression(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression) DrlxParseUtil.isThisExpression(org.drools.modelcompiler.builder.generator.DrlxParseUtil.isThisExpression) ListCreationLiteralExpression(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ArrayList(java.util.ArrayList) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ListCreationLiteralExpressionElement(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpressionElement) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) NullSafeMethodCallExpr(org.drools.mvel.parser.ast.expr.NullSafeMethodCallExpr) DrlxParseUtil.nameExprToMethodCallExpr(org.drools.modelcompiler.builder.generator.DrlxParseUtil.nameExprToMethodCallExpr)

Aggregations

InitializerDeclaration (com.github.javaparser.ast.body.InitializerDeclaration)1 Expression (com.github.javaparser.ast.expr.Expression)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1 ArrayList (java.util.ArrayList)1 DrlxParseUtil.isThisExpression (org.drools.modelcompiler.builder.generator.DrlxParseUtil.isThisExpression)1 DrlxParseUtil.nameExprToMethodCallExpr (org.drools.modelcompiler.builder.generator.DrlxParseUtil.nameExprToMethodCallExpr)1 DrlxParseUtil.toClassOrInterfaceType (org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType)1 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)1 UnificationTypedExpression (org.drools.modelcompiler.builder.generator.UnificationTypedExpression)1 ListCreationLiteralExpression (org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression)1 ListCreationLiteralExpressionElement (org.drools.mvel.parser.ast.expr.ListCreationLiteralExpressionElement)1 MapCreationLiteralExpression (org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression)1 NullSafeMethodCallExpr (org.drools.mvel.parser.ast.expr.NullSafeMethodCallExpr)1