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));
}
Aggregations