Interface CqnVisitor


public interface CqnVisitor
A CqnToken tree visitor conform to the visitor design pattern. Classes implementing this interface operate on a tree of CqnTokens, such as CQN expressions, predicates and values. When a visitor is passed as an argument to a token's accept method, generally the accept methods of the token's children are called first. Afterwards the visit method that is most specific to the parent token is invoked. Classes implementing this interface may override the default visit method to perform arbitrary operations.

Consider the following example with the visitor implementation:

 CqnVisitor visitor = new CqnVisitor() {
        @Override
        public void visit(CqnComparisonPredicate comparison) {
                System.out.println(comparison.operator());
        }

        @Override
        public void visit(CqnElementRef elementRef) {
                System.out.println(elementRef.displayName());
        }

        @Override
        public void visit(CqnStringLiteral literal) {
                System.out.println(literal.value());
        }
 };
 
and the comparison predicate:
 Predicate compPredicate = CQL.comparison(CQL.get("name"), Operator.IS, CQL.constant("Peter"));
 
Calling the compPredicate.accept(visitor) will produce the following output:
 name
 Peter
 IS
 
Note the order in which the nodes are visited. As per CqnComparisonPredicate.accept(com.sap.cds.ql.cqn.CqnVisitor) the visitor is first dispatched to the left and right values of the comparison. Afterwards the visit(CqnComparisonPredicate comparison) method is called.