class QueryPruningVisitor extends BaseVisitor {

    public static JexlNode reduce(JexlNode node, boolean showPrune) {
        QueryPruningVisitor visitor = new QueryPruningVisitor(true, showPrune);
        
        String before = null;
        String after;
        
        if (showPrune) {
            before = JexlStringBuildingVisitor.buildQuery(node);
        }
        
        // flatten the tree and create a copy
        JexlNode copy = TreeFlatteningRebuildingVisitor.flatten(node);
        
        copy.jjtAccept(visitor, null);
        
        if (showPrune) {
            after = JexlStringBuildingVisitor.buildQuery(copy);
            if (StringUtils.equals(before, after)) {
                log.debug("Query was not pruned");
            } else {
                log.debug("Query before prune: " + before + "\nQuery after prune: " + after);
            }
        }
        
        return copy;
    }

    private  QueryPruningVisitor(boolean rewrite);
    private  QueryPruningVisitor(boolean rewrite, boolean debugPrune);

}