void (@NotNull Project project, @NotNull VirtualFile requiredFile, @NotNull Map<String, UniqueNameBuilder<VirtualFile>> valueMap, boolean skipNonOpenedFiles, @NotNull GlobalSearchScope scope) { boolean useIndex = !skipNonOpenedFiles && !LightEdit.owns(project); VirtualFile[] openFiles = FileEditorManager.getInstance(project).getOpenFiles(); List<VirtualFile> recentFiles = EditorHistoryManager.getInstance(project).getFileList(); final MultiMap<String, VirtualFile> multiMap = MultiMap.createSet(); if (useIndex) { Set<String> names = JBIterable.of(requiredFile).append(openFiles).append(recentFiles).map(UniqueVFilePathBuilderImpl::getName).toSet(); ThrowableComputable<Boolean, RuntimeException> query = () -> FilenameIndex.processFilesByNames( names, true, scope, null, file -> { String name = getName(file); if (names.contains(name)) { // not-up-to-date index check multiMap.putValue(name, file); } return true; }); if (DumbService.isDumb(project)) { DumbModeAccessType.RELIABLE_DATA_ONLY.ignoreDumbMode(query); } else { disableIndexUpToDateCheckInEdt(query); } } String requiredFileName = getName(requiredFile); for (VirtualFile file : JBIterable.of(openFiles).append(skipNonOpenedFiles ? Collections.emptyList() : recentFiles)) { if (getName(file).equals(requiredFileName)) { multiMap.putValue(requiredFileName, file); } } for (String fileName : multiMap.keySet()) { Collection<VirtualFile> files = multiMap.get(fileName); if (files.size() < 2) { valueMap.put(fileName, ourEmptyBuilder); continue; } String path = project.getBasePath(); path = path == null ? "" : FileUtil.toSystemIndependentName(path); UniqueNameBuilder<VirtualFile> builder = new UniqueNameBuilder<>(path, File.separator); for (VirtualFile virtualFile : files) { String presentablePath = virtualFile instanceof VirtualFilePathWrapper ? ((VirtualFilePathWrapper)virtualFile).getPresentablePath() : virtualFile.getPath(); builder.addPath(virtualFile, presentablePath); } valueMap.put(fileName, builder); } }