private static void doExecuteAction(final @NotNull Project project, final @NotNull PsiClass clazz, final Editor editor) {
        if (!FileModificationService.getInstance().preparePsiElementsForWrite(clazz)) {
            return;
        }
        LOG.debug("+++ doExecuteAction - START +++");

        if (LOG.isDebugEnabled()) {
            LOG.debug("Current project " + project.getName());
        }

        final PsiElementClassMember<?>[] dialogMembers = buildMembersToShow(clazz);

        final MemberChooserHeaderPanel header = new MemberChooserHeaderPanel(clazz);
        LOG.debug("Displaying member chooser dialog");

        final MemberChooser<PsiElementClassMember<?>> chooser =
          new MemberChooser<>(dialogMembers, true, true, project, PsiUtil.isAvailable(JavaFeature.ANNOTATIONS, clazz), header) {
            @Override
            protected @NotNull String getHelpId() {
              return "editing.altInsert.tostring";
            }

            @Override
            protected boolean isInsertOverrideAnnotationSelected() {
              return JavaCodeStyleSettings.getInstance(clazz.getContainingFile()).INSERT_OVERRIDE_ANNOTATION;
            }
          };
        //noinspection DialogTitleCapitalization
        chooser.setTitle(JavaBundle.message("generate.tostring.title"));

        chooser.setCopyJavadocVisible(false);
        chooser.selectElements(getPreselection(clazz, dialogMembers));
        header.setChooser(chooser);

        if (ApplicationManager.getApplication().isUnitTestMode()) {
          chooser.close(DialogWrapper.OK_EXIT_CODE);
        }
        else {
          chooser.show();
        }
        if (DialogWrapper.OK_EXIT_CODE == chooser.getExitCode()) {
            Collection<PsiMember> selectedMembers = GenerationUtil.convertClassMembersToPsiMembers(sortedSelection(dialogMembers, chooser));

            final TemplateResource template = header.getSelectedTemplate();
            ToStringTemplatesManager.getInstance().setDefaultTemplate(template);

            if (template.isValidTemplate()) {
                final GenerateToStringWorker worker = new GenerateToStringWorker(clazz, editor, chooser.isInsertOverrideAnnotation());
                // decide what to do if the method already exists
                ConflictResolutionPolicy resolutionPolicy = worker.exitsMethodDialog(template);
                try {
                    WriteCommandAction.runWriteCommandAction(project, JavaBundle.message("command.name.generate.tostring"), null,
                                                             () -> worker.execute(selectedMembers, template, resolutionPolicy));
                }
                catch (Exception e) {
                    GenerationUtil.handleException(project, e);
                }
            }
            else {
                HintManager.getInstance().showErrorHint(editor,
                                                        JavaBundle.message("hint.text.tostring.template.invalid", template.getFileName()));
            }
        }

        LOG.debug("+++ doExecuteAction - END +++");
    }
private static void doExecuteAction(final @NotNull Project project, final @NotNull PsiClass clazz, final Editor editor)