void () { if (!myProject.isInitialized()) return; CommandProcessor.getInstance().executeCommand( myProject, () -> ApplicationManager.getApplication().runWriteAction( () -> { PsiFile originalPsiFile = resolveOriginalPsi(); if (originalPsiFile != null) { CodeStyleSettings settings = CodeStyle.getSettings(originalPsiFile); PsiFile psiFile = createPsi(originalPsiFile.getFileType()); psiFile.putUserData(PsiFileFactory.ORIGINAL_FILE, originalPsiFile); CodeStyle.doWithTemporarySettings( myProject, settings, () -> CodeStyleManager.getInstance(myProject).reformatText(psiFile, 0, psiFile.getTextLength())); myDocument.replaceString(0, myDocument.getTextLength(), psiFile.getText()); } }), EditorConfigBundle.message("command.name.reformat"), null); }