code: private static Set<ClassTemplateSpec> findAllReferencedTypes(
        Set<ClassTemplateSpec> current,
        Set<ClassTemplateSpec> visited,
        Set<ClassTemplateSpec> acc) {
  
      //val nextUnvisited = current.flatMap(_.directReferencedTypes).filterNot(visited.contains);
      Set<ClassTemplateSpec> nextUnvisited = new HashSet<ClassTemplateSpec>();
      for (ClassTemplateSpec currentSpec: current) {
        for (ClassTemplateSpec maybeNext: directReferencedTypes(currentSpec)) {
          if (!visited.contains(maybeNext)) {
            nextUnvisited.add(maybeNext);
          }
        }
      }
  
      Set<ClassTemplateSpec> accAndCurrent = new HashSet<ClassTemplateSpec>(acc);
      accAndCurrent.addAll(current);
  
      if (nextUnvisited.size() > 0) {
        Set<ClassTemplateSpec> currentAndVisited = new HashSet<ClassTemplateSpec>(current);
        currentAndVisited.addAll(visited);
  
        return findAllReferencedTypes(nextUnvisited, currentAndVisited, accAndCurrent);
      } else {
        return accAndCurrent;
      }
    }
docs: traverses the directReferencedTypes graph, keeping track of already visited ClassTemplateSpecs