public static void chooseAndOverrideOrImplementMethods(@NotNull Project project,
                                                         @NotNull final Editor editor,
                                                         @NotNull final GrTypeDefinition aClass,
                                                         boolean toImplement) {
    LOG.assertTrue(aClass.isValid());
    ApplicationManager.getApplication().assertReadAccessAllowed();

    Collection<CandidateInfo> candidates = GroovyOverrideImplementExploreUtil.getMethodsToOverrideImplement(aClass, toImplement);
    Collection<CandidateInfo> secondary = toImplement || aClass.isInterface() ? new ArrayList<>()
                                                                              : GroovyOverrideImplementExploreUtil
                                            .getMethodsToOverrideImplement(aClass, true);

    if (toImplement) {
      for (Iterator<CandidateInfo> iterator = candidates.iterator(); iterator.hasNext(); ) {
        CandidateInfo candidate = iterator.next();
        PsiElement element = candidate.getElement();
        if (element instanceof GrMethod method) {
          if (GrTraitUtil.isTrait(method.getContainingClass()) && !GrTraitUtil.isMethodAbstract(method)) {
            iterator.remove();
            secondary.add(candidate);
          }
        }
      }
    }

    OverrideImplementUtil.showJavaOverrideImplementChooser(editor, aClass, toImplement, candidates, secondary, chooser->{
      if (chooser == null) return;
      final List<PsiMethodMember> selectedElements = chooser.getSelectedElements();
      if (selectedElements == null || selectedElements.isEmpty()) return;
      LOG.assertTrue(aClass.isValid());
      WriteCommandAction.writeCommandAction(project,
                                            aClass.getContainingFile()).run(
                                              () -> OverrideImplementUtil.overrideOrImplementMethodsInRightPlace(editor, aClass, selectedElements, chooser.isCopyJavadoc(),
                                                                                                                                                        chooser.isInsertOverrideAnnotation()));
    });
  }
public static void chooseAndOverrideOrImplementMethods(@NotNull Project project,
                                                         @NotNull final Editor editor,
                                                         @NotNull final GrTypeDefinition aClass,
                                                         boolean toImplement)