void (@NotNull PsiFile file) { if (LightVirtualFile.shouldSkipEventSystem(file.getViewProvider().getVirtualFile())) { ensureDocumentCommitted(file); formatBlockingPostprocess(file); return; } final Runnable commandRunnable = () -> { if (file.isValid()) { WriteCommandAction.runWriteCommandAction( myProject, CodeStyleBundle.message("command.name.reformat"), null, () -> formatBlockingPostprocess(file), file); } }; CodeStyleCachingService.getInstance(myProject).scheduleWhenSettingsComputed( file, () -> { NonBlockingReadAction<CodeFormattingData> prepareDataAction = ReadAction.nonBlocking( () -> { return CodeFormattingData.prepare(file, Collections.singletonList(file.getTextRange())); } ) .expireWhen(() -> myProject.isDisposed()); if (ApplicationManager.getApplication().isUnitTestMode()) { ensureDocumentCommitted(file); commandRunnable.run(); } else if (ApplicationManager.getApplication().isHeadlessEnvironment()) { prepareDataAction.executeSynchronously(); commandRunnable.run(); } else { prepareDataAction .withDocumentsCommitted(myProject) .finishOnUiThread(ModalityState.nonModal(), data -> commandRunnable.run()) .submit(AppExecutorUtil.getAppExecutorService()); } } ); }