void (@NotNull AnActionEvent event) { DataContext dataContext = event.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return; } final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); PsiFile file = null; PsiDirectory dir; boolean hasSelection = false; if (editor != null){ file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) return; dir = file.getContainingDirectory(); hasSelection = editor.getSelectionModel().hasSelection(); } else if (files != null && containsOnlyFiles(files)) { final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Arrays.asList(files)); if (!operationStatus.hasReadonlyFiles()) { ReformatFilesOptions selectedFlags = getReformatFilesOptions(project, files); if (selectedFlags == null) return; final boolean processOnlyChangedText = selectedFlags.getTextRangeType() == TextRangeType.VCS_CHANGED_TEXT; final boolean shouldOptimizeImports = selectedFlags.isOptimizeImports() && !DumbService.getInstance(project).isDumb(); AbstractLayoutCodeProcessor processor = new ReformatCodeProcessor(project, convertToPsiFiles(files, project), null, processOnlyChangedText); if (shouldOptimizeImports) { processor = new OptimizeImportsProcessor(processor); } if (selectedFlags.isRearrangeCode()) { processor = new RearrangeCodeProcessor(processor); } if (selectedFlags.isCodeCleanup()) { processor = new CodeCleanupCodeProcessor(processor); } processor.run(); } return; } else if (PlatformCoreDataKeys.PROJECT_CONTEXT.getData(dataContext) != null || LangDataKeys.MODULE_CONTEXT.getData(dataContext) != null) { Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext); ReformatFilesOptions selectedFlags = getLayoutProjectOptions(project, moduleContext); if (selectedFlags != null) { reformatModule(project, moduleContext, selectedFlags); } return; } else { PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext); if (element == null) return; if (element instanceof PsiDirectoryContainer) { dir = ArrayUtil.getFirstElement(((PsiDirectoryContainer)element).getDirectories()); } else if (element instanceof PsiDirectory) { dir = (PsiDirectory)element; } else { file = element.getContainingFile(); if (file == null) return; dir = file.getContainingDirectory(); } } if (file == null && dir != null) { DirectoryFormattingOptions options = getDirectoryFormattingOptions(project, dir); if (options != null) { reformatDirectory(project, dir, options); } return; } if (file == null || editor == null) return; PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); LastRunReformatCodeOptionsProvider provider = new LastRunReformatCodeOptionsProvider(PropertiesComponent.getInstance()); ReformatCodeRunOptions currentRunOptions = provider.getLastRunOptions(file); TextRangeType processingScope = currentRunOptions.getTextRangeType(); if (hasSelection) { processingScope = TextRangeType.SELECTED_TEXT; } else if (processingScope == TextRangeType.VCS_CHANGED_TEXT) { if (VcsFacade.getInstance().isChangeNotTrackedForFile(project, file)) { processingScope = TextRangeType.WHOLE_FILE; } } else { processingScope = TextRangeType.WHOLE_FILE; } currentRunOptions.setProcessingScope(processingScope); new FileInEditorProcessor(file, editor, currentRunOptions).processCode(); }