goto popups: name should be above _name

This commit is contained in:
peter
2013-07-01 17:47:16 +02:00
parent 4c19913389
commit a9b1da4f71
3 changed files with 31 additions and 17 deletions
@@ -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<Object> getPopupElements(ChooseByNameModel model, String text) {
return getPopupElements(createPopup(model), text)
}
@@ -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<String>() {
@Override
public boolean value(String s) {
return myCaseInsensitiveMatcher.isStartMatch(s);
for (String s : element.getAllLookupStrings()) {
FList<TextRange> 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
@@ -190,22 +190,13 @@ public class MinusculeMatcher implements Matcher {
Iterable<TextRange> fragments = matchingFragments(name);
if (fragments != null) {
Iterator<TextRange> 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