void (@NotNull PsiElement element, @NotNull TextRange range, boolean canChangeWhitespaceOnly) { if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) { formatElement(element, range, canChangeWhitespaceOnly); } PsiFile file = element.getContainingFile(); Project project = file.getProject(); ReadAction .nonBlocking( () -> CodeFormattingData.prepare(file, Collections.singletonList(range))) .expireWhen(() -> project.isDisposed() || !file.isValid()) .finishOnUiThread(ModalityState.nonModal(), data -> { CommandProcessor.getInstance().runUndoTransparentAction(() -> { WriteAction.run(() -> { formatElement(element, range, canChangeWhitespaceOnly); }); }); }) .submit(AppExecutorUtil.getAppExecutorService()); }