private static void chooseEnclosingMethod(Editor editor, PsiMethod method, Consumer<PsiMethod> consumer) {
    final List<PsiMethod> validEnclosingMethods = CommonJavaRefactoringUtil.getEnclosingMethods(method);
    if (validEnclosingMethods.size() > 1 && !ApplicationManager.getApplication().isUnitTestMode()) {
      PsiElementListCellRenderer<PsiMethod> renderer = new PsiElementListCellRenderer<>() {
        @Override
        public String getElementText(PsiMethod method) {
          return PsiFormatUtil.formatMethod(
            method,
            PsiSubstitutor.EMPTY,
            PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
            PsiFormatUtilBase.SHOW_TYPE);
        }

        @Override
        protected @Nullable String getContainerText(PsiMethod method, String name) {
          return null;
        }
      };
      ScopeHighlighter highlighter = new ScopeHighlighter(editor);
      IPopupChooserBuilder<PsiMethod> builder = JBPopupFactory.getInstance()
        .createPopupChooserBuilder(validEnclosingMethods)
        .setRenderer(renderer)
        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
        .setTitle(QuickFixBundle.message("target.method.chooser.title"))
        .setItemChosenCallback(consumer)
        .setItemSelectedCallback(i -> {
          highlighter.dropHighlight();
          if (i == null) return;
          PsiIdentifier identifier = i.getNameIdentifier();
          if (identifier == null) return;
          highlighter.highlight(identifier, Collections.singletonList(identifier));
        })
        .addListener(new JBPopupListener() {
          @Override
          public void onClosed(@NotNull LightweightWindowEvent event) {
            highlighter.dropHighlight();
          }
        });
      renderer.installSpeedSearch(builder);
      builder.createPopup().showInBestPositionFor(editor);
    }
    else {
      consumer.consume(validEnclosingMethods.get(0));
    }
  }
private static void chooseEnclosingMethod(Editor editor, PsiMethod method, Consumer<PsiMethod> consumer)