void (@NotNull Project project, @NotNull Document @NotNull [] documents) { List<PsiFile> allFiles = new ArrayList<>(); List<PsiFile> filesToFormat = new ArrayList<>(); List<PsiFile> filesToOptimizeImports = new ArrayList<>(); PsiDocumentManager manager = PsiDocumentManager.getInstance(project); FormatOnSaveOptions formatOptions = FormatOnSaveOptions.getInstance(project); OptimizeImportsOnSaveOptions optimizeImportsOptions = OptimizeImportsOnSaveOptions.getInstance(project); for (Document document : documents) { PsiFile psiFile = manager.getPsiFile(document); if (psiFile == null || !LanguageFormatting.INSTANCE.isAutoFormatAllowed(psiFile)) continue; allFiles.add(psiFile); if (formatOptions.isRunOnSaveEnabled() && (formatOptions.isAllFileTypesSelected() || formatOptions.isFileTypeSelected(psiFile.getFileType()))) { filesToFormat.add(psiFile); } if (optimizeImportsOptions.isRunOnSaveEnabled() && (optimizeImportsOptions.isAllFileTypesSelected() || optimizeImportsOptions.isFileTypeSelected(psiFile.getFileType()))) { filesToOptimizeImports.add(psiFile); } } if (filesToFormat.isEmpty() && filesToOptimizeImports.isEmpty() && !RearrangeCodeOnSaveActionInfo.isRearrangeCodeOnSaveEnabled(project) && !CodeCleanupOnSaveActionInfo.isCodeCleanupOnSaveEnabled(project)) { // nothing to do return; } processFiles(project, allFiles, filesToFormat, filesToOptimizeImports); }