void () { if (EDT.isCurrentThreadEdt()) { ApplicationManagerEx.getApplicationEx().runUnlockingIntendedWrite(() -> { PlatformTestUtil.dispatchAllEventsInIdeEventQueue(); PlatformTestUtil.dispatchAllEventsInIdeEventQueue(); return null; }); } else if (ApplicationManager.getApplication().isWriteIntentLockAcquired()) { LaterInvocator.pollWriteThreadEventsOnce(); ApplicationManagerEx.getApplicationEx().runUnlockingIntendedWrite(() -> { ApplicationManager.getApplication().invokeAndWait(EmptyRunnable.getInstance(), ModalityState.any()); return null; }); } else { Semaphore semaphore = new Semaphore(1); ApplicationManager.getApplication().invokeLaterOnWriteThread(semaphore::up, ModalityState.any()); semaphore.waitFor(); ApplicationManager.getApplication().invokeAndWait(EmptyRunnable.getInstance(), ModalityState.any()); } }