Search in sources :

Example 1 with MapPutExprT

use of org.drools.mvelcompiler.ast.MapPutExprT in project drools by kiegroup.

the class LHSPhase method visit.

@Override
public TypedExpression visit(AssignExpr n, Void arg) {
    logPhase("AssignExpr {}", n);
    TypedExpression target = n.getTarget().accept(this, arg);
    Optional<TypedExpression> bigDecimalConversion = withBigDecimalConversion(n, target, rhsOrError());
    if (bigDecimalConversion.isPresent()) {
        return bigDecimalConversion.get();
    }
    if (target instanceof FieldToAccessorTExpr || target instanceof VariableDeclaratorTExpr || target instanceof MapPutExprT) {
        return target;
    }
    return new AssignExprT(n.getOperator(), target, rhsOrNull());
}
Also used : MapPutExprT(org.drools.mvelcompiler.ast.MapPutExprT) AssignExprT(org.drools.mvelcompiler.ast.AssignExprT) VariableDeclaratorTExpr(org.drools.mvelcompiler.ast.VariableDeclaratorTExpr) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression) FieldToAccessorTExpr(org.drools.mvelcompiler.ast.FieldToAccessorTExpr)

Example 2 with MapPutExprT

use of org.drools.mvelcompiler.ast.MapPutExprT in project drools by kiegroup.

the class LHSPhase method visit.

@Override
public TypedExpression visit(ArrayAccessExpr n, Void arg) {
    if (parentIsExpressionStmt(n)) {
        return rhsOrError();
    }
    TypedExpression name = n.getName().accept(this, arg);
    Optional<Type> type = name.getType();
    if (type.filter(TypeUtils::isCollection).isPresent()) {
        Expression index = n.getIndex();
        if (index.isStringLiteralExpr() || index.isNameExpr()) {
            return new MapPutExprT(name, index, rhsOrNull(), name.getType());
        } else {
            return new ListAccessExprT(name, index, type.get());
        }
    }
    return new UnalteredTypedExpression(n, type.orElse(null));
}
Also used : MapPutExprT(org.drools.mvelcompiler.ast.MapPutExprT) Type(java.lang.reflect.Type) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) Expression(com.github.javaparser.ast.expr.Expression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression) ListAccessExprT(org.drools.mvelcompiler.ast.ListAccessExprT) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression)

Aggregations

MapPutExprT (org.drools.mvelcompiler.ast.MapPutExprT)2 TypedExpression (org.drools.mvelcompiler.ast.TypedExpression)2 UnalteredTypedExpression (org.drools.mvelcompiler.ast.UnalteredTypedExpression)2 Expression (com.github.javaparser.ast.expr.Expression)1 Type (java.lang.reflect.Type)1 AssignExprT (org.drools.mvelcompiler.ast.AssignExprT)1 FieldToAccessorTExpr (org.drools.mvelcompiler.ast.FieldToAccessorTExpr)1 ListAccessExprT (org.drools.mvelcompiler.ast.ListAccessExprT)1 VariableDeclaratorTExpr (org.drools.mvelcompiler.ast.VariableDeclaratorTExpr)1