void () { List<OptimizeRequest> requests; synchronized (queue) { requests = new ArrayList<>(queue); queue.clear(); } for (OptimizeRequest request : requests) { if (myProject.isDisposed()) { break; } PsiFile psiFile = request.psiFile(); if (psiFile.getModificationStamp() != request.modificationStampBefore()) { continue; } if (!psiFile.isWritable()) { continue; } if (!DaemonCodeAnalyzerEx.getInstanceEx(myProject).isErrorAnalyzingFinished(psiFile)) { // re-fire when daemon is really finished scheduleOnDaemonFinish(psiFile, request.optimizeFix()); continue; } // later because should invoke when highlighting is finished (OptimizeImportsFix relies on that) AppUIExecutor.onUiThread().later().withDocumentsCommitted(myProject).execute(() -> { if (myProject.isDisposed()) return; long stampAfter = psiFile.getModificationStamp(); if (stampAfter != request.modificationStampBefore()) { return; } if (request.optimizeFix().isAvailable(myProject, null, psiFile)) { request.optimizeFix().invoke(myProject, null, psiFile); } }); } }