From dfa6ae7f6f1ae551880f61bc49ab70388e7eefb3 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 27 Feb 2017 14:37:08 +0100 Subject: [PATCH] be prepared to some crazy ChooseByName models that put "non-prefix matches:" as the first item (EA-92486 - assert: ContributorsBasedGotoByModel.getElementName) --- .../ide/util/gotoByName/ChooseByNameBase.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 3448735c524a..8ff97411eaa0 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -1029,22 +1029,24 @@ public abstract class ChooseByNameBase { reversed(); int bestPosition = 0; + while (bestPosition < modelElements.length - 1 && isSpecialElement(modelElements[bestPosition])) bestPosition++; + for (int i = 1; i < modelElements.length; i++) { final Object modelElement = modelElements[i]; - if (EXTRA_ELEM.equals(modelElement) || NON_PREFIX_SEPARATOR.equals(modelElement)) continue; + if (isSpecialElement(modelElement)) continue; if (itemComparator.compare(modelElement, modelElements[bestPosition]) < 0) { bestPosition = i; } } - if (bestPosition < modelElements.length - 1 && modelElements[bestPosition] == NON_PREFIX_SEPARATOR) { - bestPosition++; - } - return bestPosition; } + private static boolean isSpecialElement(Object modelElement) { + return EXTRA_ELEM.equals(modelElement) || NON_PREFIX_SEPARATOR.equals(modelElement); + } + private int getUseCount(String statContext, Object modelElement) { String text = myModel.getFullName(modelElement); return text == null ? Integer.MIN_VALUE : StatisticsManager.getInstance().getUseCount(new StatisticsInfo(statContext, text));