@RequiresEdt
  public static void removeSourceRoots(@NotNull Module module, @NotNull Collection<VirtualFile> roots) {
    if (roots.isEmpty()) {
      return;
    }

    ApplicationManager.getApplication().runWriteAction(
      () -> {
        final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        for (ContentEntry entry : model.getContentEntries()) {
          for (SourceFolder folder : entry.getSourceFolders()) {
            if (roots.contains(folder.getFile())) {
              entry.removeSourceFolder(folder);
            }
          }

          if (roots.contains(entry.getFile()) && entry.getSourceFolders().length == 0) {
            model.removeContentEntry(entry);
          }
        }
        model.commit();
      }
    );
  }
@RequiresEdt
  public static void removeSourceRoots(@NotNull Module module, @NotNull Collection<VirtualFile> roots)