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