@Override
  public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    List<PsiElement> elements =
      CommonRefactoringUtil.findElementsFromCaretsAndSelections(editor, file, null,
                                                                e -> e instanceof PsiField field && field.getContainingClass() != null ||
                                                                     e instanceof PsiClass);
    if (elements.isEmpty()) {
      String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.class"));
      CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HelpID.ENCAPSULATE_FIELDS);
      return;
    }

    invoke(project, elements.toArray(PsiElement.EMPTY_ARRAY), dataContext);
  }
@Override
  public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext)