RefactoringActionHandler (@NotNull DataContext dataContext) { return new RefactoringActionHandler() { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) { final PsiDirectory pyPackage = getPackageDir(file); if (pyPackage != null) { createModuleFromPackage(pyPackage); } } @Override public void invoke(@NotNull Project project, PsiElement @NotNull [] elements, DataContext dataContext) { if (elements.length == 1) { final PsiDirectory pyPackage = getPackageDir(elements[0]); if (pyPackage != null) { createModuleFromPackage(pyPackage); } } } }; }