AccessToken (@NotNull @NonNls String activityName, @Nullable Function<? super AWTEvent, String> errorFunction) { if (!EDT.isCurrentThreadEdt()) { return AccessToken.EMPTY_ACCESS_TOKEN; } ProhibitAWTEvents dispatcher = new ProhibitAWTEvents(activityName, errorFunction); IdeEventQueue.getInstance().addPostprocessor(dispatcher, (Disposable)null); return new AccessToken() { @Override public void finish() { IdeEventQueue.getInstance().removePostprocessor(dispatcher); } }; }