void (Document document, Runnable r) { letSaveAllDocumentsPassIfAny(); watchDocumentChanges(r::run, event -> { Document changed = event.getDocument(); if (changed != document) { VirtualFile file = FileDocumentManager.getInstance().getFile(changed); if (file != null && file.isInLocalFileSystem()) { throw new AssertionError("Unexpected document change: " + changed); } } }); }