Search in sources :

Example 1 with MapCreationLiteralExpressionKeyValuePair

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

the class ExpressionTyper method mapCreationLiteral.

private Optional<TypedExpressionCursor> mapCreationLiteral(MapCreationLiteralExpression mapCreationLiteralExpression, java.lang.reflect.Type originalTypeCursor) {
    ClassOrInterfaceType hashMapType = (ClassOrInterfaceType) parseType(HashMap.class.getCanonicalName());
    BlockStmt initializationStmt = new BlockStmt();
    InitializerDeclaration body = new InitializerDeclaration(false, initializationStmt);
    ObjectCreationExpr newHashMapExpr = new ObjectCreationExpr(null, hashMapType, nodeList(), nodeList(), nodeList(body));
    for (Expression e : mapCreationLiteralExpression.getExpressions()) {
        MapCreationLiteralExpressionKeyValuePair expr = (MapCreationLiteralExpressionKeyValuePair) e;
        Expression key = resolveCreationLiteralNameExpr(originalTypeCursor, expr.getKey());
        Expression value = resolveCreationLiteralNameExpr(originalTypeCursor, expr.getValue());
        initializationStmt.addStatement(new MethodCallExpr(null, "put", nodeList(key, value)));
    }
    return of(new TypedExpressionCursor(newHashMapExpr, HashMap.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) HashMap(java.util.HashMap) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) MapCreationLiteralExpressionKeyValuePair(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpressionKeyValuePair) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) 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 HashMap (java.util.HashMap)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 MapCreationLiteralExpression (org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression)1 MapCreationLiteralExpressionKeyValuePair (org.drools.mvel.parser.ast.expr.MapCreationLiteralExpressionKeyValuePair)1 NullSafeMethodCallExpr (org.drools.mvel.parser.ast.expr.NullSafeMethodCallExpr)1