public static void getDependencies(@NotNull Module module, @NotNull Set<? super Module> modules) {
    if (modules.contains(module)) return;
    modules.add(module);
    Module[] dependencies = ModuleRootManager.getInstance(module).getDependencies();
    for (Module dependency : dependencies) {
      getDependencies(dependency, modules);
    }
  }
public static void getDependencies(@NotNull Module module, @NotNull Set<? super Module> modules)