ReadonlyFragmentModificationHandler (final @NotNull Document document) { final Document doc = document instanceof DocumentWindow ? ((DocumentWindow)document).getDelegate() : document; final ReadonlyFragmentModificationHandler docHandler = doc instanceof DocumentImpl ? ((DocumentImpl)doc).getReadonlyFragmentModificationHandler() : null; return docHandler == null ? myReadonlyFragmentsHandler : docHandler; }