void (@NotNull Project project, final ContentEntry[] contentEntries, final Runnable finishRunnable) { final HashMap<ContentEntry, Collection<JavaModuleSourceRoot>> entryToRootMap = new HashMap<>(); final Map<File, ContentEntry> fileToEntryMap = new HashMap<>(); for (final ContentEntry contentEntry : contentEntries) { final VirtualFile file = contentEntry.getFile(); if (file != null) { entryToRootMap.put(contentEntry, null); fileToEntryMap.put(VfsUtilCore.virtualToIoFile(file), contentEntry); } } final ProgressWindow progressWindow = new ProgressWindow(true, project); final ProgressIndicator progressIndicator = new SmoothProgressAdapter(progressWindow, project); final Runnable searchRunnable = () -> { final Runnable process = () -> { for (final File file : fileToEntryMap.keySet()) { progressIndicator.setText(JavaUiBundle.message("module.paths.searching.source.roots.progress", file.getPath())); final Collection<JavaModuleSourceRoot> roots = JavaSourceRootDetectionUtil.suggestRoots(file); entryToRootMap.put(fileToEntryMap.get(file), roots); } }; progressWindow.setTitle(JavaUiBundle.message("module.paths.searching.source.roots.title")); ProgressManager.getInstance().runProcess(process, progressIndicator); }; final Runnable addSourcesRunnable = () -> { for (final ContentEntry contentEntry : contentEntries) { final Collection<JavaModuleSourceRoot> suggestedRoots = entryToRootMap.get(contentEntry); if (suggestedRoots != null) { for (final JavaModuleSourceRoot suggestedRoot : suggestedRoots) { final VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByIoFile(suggestedRoot.getDirectory()); final VirtualFile fileContent = contentEntry.getFile(); if (sourceRoot != null && fileContent != null && VfsUtilCore.isAncestor(fileContent, sourceRoot, false)) { contentEntry.addSourceFolder(sourceRoot, false, suggestedRoot.getPackagePrefix()); } } } } if (finishRunnable != null) { finishRunnable.run(); } }; new SwingWorker() { @Override public Object construct() { searchRunnable.run(); return null; } @Override public void finished() { addSourcesRunnable.run(); } }.start(); }