code: public static Collection<Subquery> subqueries( Visitable visitable,
                                                     final boolean includeNestedSubqueries ) {
          final Collection<Subquery> subqueries = new LinkedList<Subquery>();
          Visitors.visitAll(visitable, new Visitors.AbstractVisitor() {
              @Override
              public void visit( Subquery subquery ) {
                  subqueries.add(subquery);
                  if (includeNestedSubqueries) {
                      // Now look for any subqueries in the subquery ...
                      subquery.getQuery().accept(this);
                  }
              }
          });
          return subqueries;
      }
docs: Using a visitor, obtain the {@link Subquery} objects that are contained within the supplied {@link Visitable object}. This
  method does find Subquery objets nested in other Subquery objects.
  
  @param visitable the visitable
  @param includeNestedSubqueries true if any Subquery objects within other Subquery objects should be included, or false if
  only the top-level Subquery objects should be included
  @return the collection of subqueries; never null but possibly empty if no subqueries were found