void (@NotNull final Runnable runnable, @NotNull final PsiFile file, @NotNull final Editor editor) { final long stamp = editor.getDocument().getModificationStamp(); Project project = file.getProject(); ApplicationManager.getApplication().invokeLater(() -> { if (project.isDisposed() || editor.isDisposed() || editor.getDocument().getModificationStamp() != stamp) return; //no need to optimize imports on the fly during undo/redo if (UndoManager.getInstance(project).isUndoOrRedoInProgress()) return; PsiDocumentManager.getInstance(project).commitAllDocuments(); String beforeText = file.getText(); final long oldStamp = editor.getDocument().getModificationStamp(); DocumentUtil.writeInRunUndoTransparentAction(runnable); if (oldStamp != editor.getDocument().getModificationStamp()) { String afterText = file.getText(); if (Comparing.strEqual(beforeText, afterText)) { String path = file.getViewProvider().getVirtualFile().getPath(); LOG.error("Import optimizer hasn't optimized any imports", new Attachment(path, afterText)); } } }); }