From 0094a5dbfee81154387e9428138b772ef72ddf69 Mon Sep 17 00:00:00 2001 From: Piotr Tomiak Date: Thu, 20 Dec 2018 18:24:44 +0100 Subject: [PATCH] IDEA-204424 Add "Other" group if needed and ensure no duplicated entries on the list --- .../navigation/NavigationUtil.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/NavigationUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/NavigationUtil.java index 016f6cf8c01d..9670ee1a3112 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/NavigationUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/NavigationUtil.java @@ -264,15 +264,19 @@ public final class NavigationUtil { */ @NotNull public static JBPopup getRelatedItemsPopup(final List items, String title, boolean showContainingModules) { - Object[] elements = new Object[items.size()]; + List elements = new ArrayList<>(items.size()); //todo[nik] move presentation logic to GotoRelatedItem class final Map itemsMap = new HashMap<>(); - for (int i = 0; i < items.size(); i++) { - GotoRelatedItem item = items.get(i); - elements[i] = item.getElement() != null ? item.getElement() : item; - itemsMap.put(item.getElement(), item); + for (GotoRelatedItem item : items) { + if (item.getElement() != null) { + if (itemsMap.putIfAbsent(item.getElement(), item) == null) { + elements.add(item.getElement()); + } + } + else { + elements.add(item); + } } - return getPsiElementPopup(elements, itemsMap, title, showContainingModules, element -> { if (element instanceof PsiElement) { itemsMap.get(element).navigate(); @@ -285,7 +289,7 @@ public final class NavigationUtil { ); } - private static JBPopup getPsiElementPopup(final Object[] elements, final Map itemsMap, + private static JBPopup getPsiElementPopup(final List elements, final Map itemsMap, final String title, final boolean showContainingModules, final Processor processor) { final Ref hasMnemonic = Ref.create(false); @@ -366,7 +370,7 @@ public final class NavigationUtil { return component; } }; - final ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep(title, Arrays.asList(elements)) { + final ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep(title, elements) { @Override public boolean isSpeedSearchEnabled() { return true; @@ -390,7 +394,7 @@ public final class NavigationUtil { }) { }; popup.getList().setCellRenderer(new PopupListElementRenderer(popup) { - Map separators = new HashMap<>(); + final Map separators = new HashMap<>(); { final ListModel model = popup.getList().getModel(); String current = null; @@ -400,7 +404,7 @@ public final class NavigationUtil { final GotoRelatedItem item = itemsMap.get(element); if (item != null && !StringUtil.equals(current, item.getGroup())) { current = item.getGroup(); - separators.put(element, current); + separators.put(element, hasTitle && StringUtil.isEmpty(current) ? "Other" : current); if (!hasTitle && !StringUtil.isEmpty(current)) { hasTitle = true; }