boolean (Collection<? extends PsiElement> elements, boolean recursively, Collection<? super VirtualFile> readonly, Collection<? super VirtualFile> failed) { boolean seenNonWritablePsiFilesWithoutVirtualFile = false; for (PsiElement element : elements) { if (element instanceof PsiDirectory dir) { final VirtualFile vFile = dir.getVirtualFile(); if (vFile.getFileSystem().isReadOnly()) { failed.add(vFile); } else if (recursively) { collectReadOnlyFiles(vFile, readonly); } else { readonly.add(vFile); } } else if (element instanceof PsiDirectoryContainer) { final PsiDirectory[] directories = ((PsiDirectoryContainer)element).getDirectories(); for (PsiDirectory directory : directories) { VirtualFile virtualFile = directory.getVirtualFile(); if (recursively) { if (virtualFile.getFileSystem().isReadOnly()) { failed.add(virtualFile); } else { collectReadOnlyFiles(virtualFile, readonly); } } else if (virtualFile.getFileSystem().isReadOnly()) { failed.add(virtualFile); } else { readonly.add(virtualFile); } } } else { PsiFile file = element.getContainingFile(); if (file == null) { if (!element.isWritable()) { seenNonWritablePsiFilesWithoutVirtualFile = true; } } else { final VirtualFile vFile = file.getVirtualFile(); if (vFile != null) { readonly.add(vFile); } else if (!element.isWritable()) { seenNonWritablePsiFilesWithoutVirtualFile = true; } } } } return seenNonWritablePsiFilesWithoutVirtualFile; }