Search in sources :

Example 16 with HalfBinaryExpr

use of org.drools.mvel.parser.ast.expr.HalfBinaryExpr 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)

Example 17 with HalfBinaryExpr

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

the class DrlxParseUtil method trasformHalfBinaryToBinary.

public static Expression trasformHalfBinaryToBinary(Expression drlxExpr) {
    final Optional<Node> parent = drlxExpr.getParentNode();
    if (drlxExpr instanceof HalfBinaryExpr && parent.isPresent()) {
        HalfBinaryExpr halfBinaryExpr = (HalfBinaryExpr) drlxExpr;
        Expression parentLeft = findLeftLeafOfNameExprTraversingParent(halfBinaryExpr);
        Operator operator = toBinaryExprOperator(halfBinaryExpr.getOperator());
        return new BinaryExpr(parentLeft, halfBinaryExpr.getRight(), operator);
    }
    return drlxExpr;
}
Also used : Operator(com.github.javaparser.ast.expr.BinaryExpr.Operator) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Expression(com.github.javaparser.ast.expr.Expression) ListCreationLiteralExpression(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) MapCreationLiteralExpression(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression) Node(com.github.javaparser.ast.Node) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)17 HalfBinaryExpr (org.drools.mvel.parser.ast.expr.HalfBinaryExpr)17 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)16 DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)16 DrlxParser.parseExpression (org.drools.mvel.parser.DrlxParser.parseExpression)13 Test (org.junit.Test)13 NullSafeFieldAccessExpr (org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr)4 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)3 FieldAccessExpr (com.github.javaparser.ast.expr.FieldAccessExpr)3 Node (com.github.javaparser.ast.Node)2 NameExpr (com.github.javaparser.ast.expr.NameExpr)2 NodeList (com.github.javaparser.ast.NodeList)1 NodeList.nodeList (com.github.javaparser.ast.NodeList.nodeList)1 InitializerDeclaration (com.github.javaparser.ast.body.InitializerDeclaration)1 ArrayAccessExpr (com.github.javaparser.ast.expr.ArrayAccessExpr)1 ArrayCreationExpr (com.github.javaparser.ast.expr.ArrayCreationExpr)1 ArrayInitializerExpr (com.github.javaparser.ast.expr.ArrayInitializerExpr)1 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)1 Operator (com.github.javaparser.ast.expr.BinaryExpr.Operator)1 CastExpr (com.github.javaparser.ast.expr.CastExpr)1