void (@NotNull JList list) { list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!shouldUpdateHint()) return; Object[] selectedValues = ((JList<?>)e.getSource()).getSelectedValues(); if (selectedValues.length != 1) return; PsiElement element = getPsiElementForHint(selectedValues[0]); if (element != null && element.isValid()) { updateHint(element); } } }); }