JSqlParser parses your expression in this way:
AndExpression
AndExpression
a>10
b>20
c>30
I am curious to see which version you use, if the recursion will be indeed in the right item not the left. I use JSqlParser 0.9-SNAPSHOT. Nevertheless in my version of JSqlParser (and I think in all, because it is an LL parser), the in the other answers comment proposed codeblock
while(ex.getLeftExpression() != null) {
list.add(ex.getLeftExpression());
ex = ex.getRightExpression();
}
will not work. It finds (or collects):
a > 10 AND b > 20
which is an AndExpression
and fails on ex = ex.getRightExpression();
, because the right
will never be an AndExpression
. That is how JSqlParser works. The AndExpression
recursion would be in the leftExpression
.
So here is a solution and a litte test around it, using JSqlParser V0.9-SNAPSHOT, which uses the recursive way to visit these AndExpressions
and prints out the found expression. I did not add it to a List
. Forgive me for that.
public class JSqlParser1 {
public static void main(String[] args) throws JSQLParserException {
Expression expr = CCJSqlParserUtil.parseCondExpression("a>10 and b>20 and c>30");
expr.accept(new ExpressionVisitorAdapter() {
@Override
public void visit(AndExpression expr) {
if (expr.getLeftExpression() instanceof AndExpression) {
expr.getLeftExpression().accept(this);
} else {
System.out.println(expr.getLeftExpression());
}
System.out.println(expr.getRightExpression());
}
});
}
}
This one prints:
a > 10
b > 20
c > 30