void (@NotNull Module module, final Graph<Module> graph, Map<Module, Collection<Module>> map) { final Set<Module> deps = new HashSet<>(); map.put(module, deps); new Object() { void traverse(Module m) { for (Iterator<Module> iterator = graph.getIn(m); iterator.hasNext();) { final Module dep = iterator.next(); if (!deps.contains(dep)) { deps.add(dep); traverse(dep); } } } }.traverse(module); }