boolean (@NotNull Project project, @NotNull Document document) { final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); boolean okWritable; if (psiFile == null) { okWritable = document.isWritable(); } else { final VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile != null) { okWritable = ensureFilesWritable(project, virtualFile); } else { okWritable = psiFile.isWritable(); } } return okWritable; }