void (@NotNull AnActionEvent event) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { presentation.setEnabled(false); return; } Editor editor = CommonDataKeys.EDITOR.getData(dataContext); PsiFile file = null; if (editor != null) { file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); } else { final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); if (files != null && files.length == 1 && !files[0].isDirectory()) { file = PsiManager.getInstance(project).findFile(files[0]); } } if (file == null || file.getVirtualFile() == null) { presentation.setEnabled(false); return; } if (LanguageFormatting.INSTANCE.forContext(file) != null) { presentation.setEnabled(true); } }