public static void reformatDirectory(@NotNull Project project,
                                       @NotNull PsiDirectory dir,
                                       @NotNull DirectoryFormattingOptions options) {
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    AbstractLayoutCodeProcessor processor = new ReformatCodeProcessor(
      project, dir, options.isIncludeSubdirectories(), options.getTextRangeType() == TextRangeType.VCS_CHANGED_TEXT
    );

    registerScopeFilter(processor, options.getSearchScope());
    registerFileMaskFilter(processor, options.getFileTypeMask());

    if (options.isOptimizeImports()) {
      processor = new OptimizeImportsProcessor(processor);
    }
    if (options.isRearrangeCode()) {
      processor = new RearrangeCodeProcessor(processor);
    }
    if (options.isCodeCleanup()) {
      processor = new CodeCleanupCodeProcessor(processor);
    }

    processor.run();
  }
public static void reformatDirectory(@NotNull Project project,
                                       @NotNull PsiDirectory dir,
                                       @NotNull DirectoryFormattingOptions options)