GlobalSearchScope (@NotNull GlobalSearchScope scope) { if (equals(scope)) { return this; } if (scope instanceof DirectoryScope) { DirectoryScope other = (DirectoryScope)scope; if (myDirectories.contains(other.myDirectory) || VfsUtilCore.isUnder(other.myDirectory, myDirectoriesWithSubdirectories)) { return this; } Set<? extends VirtualFile> directories = myDirectories; Set<? extends VirtualFile> directoriesWithSubdirectories = myDirectoriesWithSubdirectories; if (other.myWithSubdirectories) { Set<VirtualFile> copy = new HashSet<>(directoriesWithSubdirectories); copy.add(other.myDirectory); directoriesWithSubdirectories = copy; } else { Set<VirtualFile> copy = new HashSet<>(directories); copy.add(other.myDirectory); directories = copy; } return new DirectoriesScope(Objects.requireNonNull(getProject()), directories, directoriesWithSubdirectories); } if (scope instanceof DirectoriesScope) { DirectoriesScope other = (DirectoriesScope)scope; Set<? extends VirtualFile> directories = myDirectories; Set<? extends VirtualFile> directoriesWithSubdirectories = myDirectoriesWithSubdirectories; if (!other.myDirectories.isEmpty()) { Set<VirtualFile> copy = new HashSet<>(directories); copy.addAll(other.myDirectories); directories = copy; } if (!other.myDirectoriesWithSubdirectories.isEmpty()) { Set<VirtualFile> copy = new HashSet<>(directoriesWithSubdirectories); copy.addAll(other.myDirectoriesWithSubdirectories); directoriesWithSubdirectories = copy; } return new DirectoriesScope(Objects.requireNonNull(getProject()), directories, directoriesWithSubdirectories); } return super.uniteWith(scope); }