DocumentEx (UndoableAction action) { // We use bulk update only for EditorChangeAction, cause we know that it only changes document. Other actions can do things // not allowed in bulk update. if (!(action instanceof EditorChangeAction)) return null; //noinspection ConstantConditions DocumentReference newDocumentRef = action.getAffectedDocuments()[0]; if (newDocumentRef == null) return null; VirtualFile file = newDocumentRef.getFile(); if (file != null && !file.isValid()) return null; return (DocumentEx)newDocumentRef.getDocument(); }