Search in sources :

Example 6 with NullSafeFieldAccessExpr

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

the class AstUtils method transformHalfBinaryArg.

private static Expression transformHalfBinaryArg(TokenRange tokenRange, Expression scope, Expression name, Expression expr, boolean nullSafe) {
    if (expr instanceof HalfBinaryExpr) {
        Expression left = scope == null ? name : (nullSafe ? new NullSafeFieldAccessExpr(scope, null, name.asNameExpr().getName()) : new FieldAccessExpr(scope, null, name.asNameExpr().getName()));
        return new BinaryExpr(tokenRange, left, ((HalfBinaryExpr) expr).getRight(), ((HalfBinaryExpr) expr).getOperator().toBinaryExprOperator());
    }
    if (expr instanceof EnclosedExpr) {
        return transformHalfBinaryArg(tokenRange, scope, name, ((EnclosedExpr) expr).getInner(), nullSafe);
    }
    if (expr instanceof BinaryExpr) {
        BinaryExpr binary = (BinaryExpr) expr;
        Expression rewrittenLeft = transformHalfBinaryArg(tokenRange, scope, name, binary.getLeft(), nullSafe);
        Expression rewrittenRight = binary.getRight() instanceof HalfBinaryExpr && !(binary.getLeft() instanceof EnclosedExpr) ? binary.getRight() : transformHalfBinaryArg(tokenRange, scope, name, binary.getRight(), nullSafe);
        rewrittenRight.setParentNode(rewrittenLeft);
        return new BinaryExpr(tokenRange, rewrittenLeft, rewrittenRight, binary.getOperator());
    }
    throw new IllegalStateException();
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) NullSafeFieldAccessExpr(org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr) EnclosedExpr(com.github.javaparser.ast.expr.EnclosedExpr) NullSafeFieldAccessExpr(org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)6 NullSafeFieldAccessExpr (org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr)6 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)5 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)5 FieldAccessExpr (com.github.javaparser.ast.expr.FieldAccessExpr)5 HalfBinaryExpr (org.drools.mvel.parser.ast.expr.HalfBinaryExpr)5 Node (com.github.javaparser.ast.Node)4 ArrayAccessExpr (com.github.javaparser.ast.expr.ArrayAccessExpr)4 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)4 ArrayList (java.util.ArrayList)4 NodeList (com.github.javaparser.ast.NodeList)3 NodeList.nodeList (com.github.javaparser.ast.NodeList.nodeList)3 InitializerDeclaration (com.github.javaparser.ast.body.InitializerDeclaration)3 ArrayCreationExpr (com.github.javaparser.ast.expr.ArrayCreationExpr)3 ArrayInitializerExpr (com.github.javaparser.ast.expr.ArrayInitializerExpr)3 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)3 CastExpr (com.github.javaparser.ast.expr.CastExpr)3 CharLiteralExpr (com.github.javaparser.ast.expr.CharLiteralExpr)3 ClassExpr (com.github.javaparser.ast.expr.ClassExpr)3 DoubleLiteralExpr (com.github.javaparser.ast.expr.DoubleLiteralExpr)3