private static void putProvidersOnModulePath(Project project, Set<PsiJavaModule> initialModules, Set<PsiJavaModule> forModulePath) {
    Set<String> interfaces = new HashSet<>();
    for (PsiJavaModule explicitModule : initialModules) {
      for (PsiUsesStatement use : explicitModule.getUses()) {
        PsiClassType useClassType = use.getClassType();
        if (useClassType != null) {
          interfaces.add(useClassType.getCanonicalText());
        }
      }
    }

    if (interfaces.isEmpty()) return;

    Set<PsiJavaModule> added = new HashSet<>();
    Consumer<PsiJavaModule> registerProviders = javaModule -> {
      if (forModulePath.add(javaModule)) {
        added.add(javaModule);
      }
    };
    JavaModuleNameIndex index = JavaModuleNameIndex.getInstance();
    for (String key : index.getAllKeys(project)) {
      nextModule: 
      for (PsiJavaModule aModule : index.getModules(key, project, GlobalSearchScope.allScope(project))) {
        if (forModulePath.contains(aModule)) continue;
        for (PsiProvidesStatement provide : aModule.getProvides()) {
          PsiClassType provideInterfaceType = provide.getInterfaceType();
          if (provideInterfaceType != null && interfaces.contains(provideInterfaceType.getCanonicalText())) {
            registerProviders.accept(aModule);
            JavaModuleGraphUtil.getAllDependencies(aModule).forEach(registerProviders);
            continue nextModule;
          }
        }
      }
    }
    if (!added.isEmpty()) {
      putProvidersOnModulePath(project, added, forModulePath);
    }
  }
private static void putProvidersOnModulePath(Project project, Set<PsiJavaModule> initialModules, Set<PsiJavaModule> forModulePath)