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