From a9b1da4f7196db6e071429a34729a8b2d7d7d227 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 1 Jul 2013 15:18:27 +0200 Subject: [PATCH] goto popups: name should be above _name --- .../navigation/ChooseByNameTest.groovy | 11 ++++++++ .../completion/impl/CamelHumpMatcher.java | 26 ++++++++++++++----- .../psi/codeStyle/MinusculeMatcher.java | 11 +------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy index 89a61bc565ab..413f3e3974dc 100644 --- a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy +++ b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy @@ -65,6 +65,17 @@ class Impl extends Intf { assert !(impl.findMethodsByName('xxx1', false)[0] in elements) } + public void "test disprefer underscore"() { + def intf = myFixture.addClass(""" +class Intf { + void _xxx1() {} + void xxx2() {} +}""") + + def elements = getPopupElements(new GotoSymbolModel2(project), "xxx") + assert elements == [intf.findMethodsByName('xxx2', false), ChooseByNameBase.NON_PREFIX_SEPARATOR, intf.findMethodsByName('_xxx1', false)] + } + private List getPopupElements(ChooseByNameModel model, String text) { return getPopupElements(createPopup(model), text) } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java index e88506016808..fe37cd1564d8 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java @@ -5,13 +5,13 @@ import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.codeInsight.completion.PrefixMatcher; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.openapi.Disposable; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.codeStyle.MinusculeMatcher; import com.intellij.psi.codeStyle.NameUtil; -import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.FList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -43,12 +43,24 @@ public class CamelHumpMatcher extends PrefixMatcher { @Override public boolean isStartMatch(LookupElement element) { - return ContainerUtil.or(element.getAllLookupStrings(), new Condition() { - @Override - public boolean value(String s) { - return myCaseInsensitiveMatcher.isStartMatch(s); + for (String s : element.getAllLookupStrings()) { + FList ranges = myCaseInsensitiveMatcher.matchingFragments(s); + if (ranges == null) continue; + if (ranges.isEmpty() || isStartMatchModuloUnderscores(s, ranges.get(0).getStartOffset())) { + return true; } - }); + } + + return false; + } + + private static boolean isStartMatchModuloUnderscores(@NotNull String name, int startIndex) { + for (int i = 0; i < startIndex; i++) { + if (name.charAt(i) != '_') { + return false; + } + } + return true; } @Override diff --git a/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java b/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java index 8473281d94c7..7048b914183c 100644 --- a/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java +++ b/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java @@ -190,22 +190,13 @@ public class MinusculeMatcher implements Matcher { Iterable fragments = matchingFragments(name); if (fragments != null) { Iterator iterator = fragments.iterator(); - if (!iterator.hasNext() || isStartMatch(name, iterator.next().getStartOffset())) { + if (!iterator.hasNext() || iterator.next().getStartOffset() == 0) { return true; } } return false; } - private static boolean isStartMatch(@NotNull String name, int startIndex) { - for (int i = 0; i < startIndex; i++) { - if (!isWordSeparator(name.charAt(i))) { - return false; - } - } - return true; - } - @Override public boolean matches(@NotNull String name) { // optimisation: name too short for this pattern