void (final Editor editor, @NotNull List<? extends PsiMethod> validEnclosingMethods, @NotNull PairConsumer<? super PsiMethod, ? super PsiMethod> consumer) { final boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode(); if (validEnclosingMethods.size() == 1 || unitTestMode) { final PsiMethod methodToIntroduceParameterTo = validEnclosingMethods.get(0); if (methodToIntroduceParameterTo.findDeepestSuperMethod() == null || unitTestMode) { consumer.consume(methodToIntroduceParameterTo, methodToIntroduceParameterTo); return; } } final JPanel panel = new JPanel(new BorderLayout()); final JCheckBox superMethod = new JCheckBox(JavaRefactoringBundle.message("introduce.parameter.super.method.checkbox"), true); panel.add(superMethod, BorderLayout.SOUTH); final JBList<PsiMethod> list = new JBList<>(validEnclosingMethods.toArray(PsiMethod.EMPTY_ARRAY)); list.setVisibleRowCount(5); list.setCellRenderer(new MethodCellRenderer()); list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); final List<RangeHighlighter> highlighters = new ArrayList<>(); list.addListSelectionListener(__ -> { final PsiMethod selectedMethod = list.getSelectedValue(); if (selectedMethod == null) return; dropHighlighters(highlighters); updateView(selectedMethod, editor, highlighters, superMethod); }); updateView(validEnclosingMethods.get(0), editor, highlighters, superMethod); final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(list); scrollPane.setBorder(null); panel.add(scrollPane, BorderLayout.CENTER); final List<Pair<ActionListener, KeyStroke>> keyboardActions = Collections.singletonList(Pair.create(__ -> { final PsiMethod methodToSearchIn = list.getSelectedValue(); if (myEnclosingMethodsPopup != null && myEnclosingMethodsPopup.isVisible()) { myEnclosingMethodsPopup.cancel(); } final PsiMethod methodToSearchFor = superMethod.isEnabled() && superMethod.isSelected() ? methodToSearchIn.findDeepestSuperMethod() : methodToSearchIn; consumer.consume(methodToSearchIn, methodToSearchFor); }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0))); myEnclosingMethodsPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, list) .setTitle(RefactoringBundle.message("refactoring.introduce.parameter.popup.title")) .setMovable(false) .setResizable(false) .setRequestFocus(true) .setKeyboardActions(keyboardActions).addListener(new JBPopupListener() { @Override public void onClosed(@NotNull LightweightWindowEvent event) { dropHighlighters(highlighters); } }).createPopup(); myEnclosingMethodsPopup.showInBestPositionFor(editor); }