void (@NotNull Project project, @NotNull List<PsiFile> allFiles, @NotNull List<PsiFile> filesToFormat, @NotNull List<PsiFile> filesToOptimizeImports) { boolean onlyChangedLines = VcsFacade.getInstance().hasActiveVcss(project) && FormatOnSaveOptions.getInstance(project).isFormatOnlyChangedLines(); AbstractLayoutCodeProcessor processor = new ReformatCodeProcessor(project, allFiles.toArray(PsiFile.EMPTY_ARRAY), null, onlyChangedLines) { @Override protected @NotNull FutureTask<Boolean> prepareTask(@NotNull PsiFile file, boolean processChangedTextOnly) { return filesToFormat.contains(file) ? super.prepareTask(file, processChangedTextOnly) : emptyTask(); } }; if (OptimizeImportsOnSaveOptions.getInstance(project).isRunOnSaveEnabled()) { processor = new OptimizeImportsProcessor(processor) { @Override protected @NotNull FutureTask<Boolean> prepareTask(@NotNull PsiFile file, boolean processChangedTextOnly) { return filesToOptimizeImports.contains(file) ? super.prepareTask(file, processChangedTextOnly) : emptyTask(); } }; } if (RearrangeCodeOnSaveActionInfo.isRearrangeCodeOnSaveEnabled(project)) { processor = new RearrangeCodeProcessor(processor); } if (CodeCleanupOnSaveActionInfo.isCodeCleanupOnSaveEnabled(project) && !DumbService.isDumb(project)) { processor = new CodeCleanupCodeProcessor(processor); } // This guarantees that per-file undo chain won't break and there won't be the "Following files affected by this action have been already changed" modal error dialog. processor.setProcessAllFilesAsSingleUndoStep(false); processor.run(); }