start matches are better than middle hump matches which are better that middle non-hump matches

This commit is contained in:
peter
2012-04-20 20:47:09 +02:00
parent a47fc0241a
commit 86b315e0c5
2 changed files with 19 additions and 2 deletions
@@ -118,6 +118,7 @@ public class NameUtilTest extends UsefulTestCase {
assertMatches("foo bar", "fooBar");
assertMatches("foo bar", "fooGooBar");
assertMatches("foo bar", "fooGoo bar");
assertDoesntMatch(" b", "fbi");
}
public void testIDEADEV15503() throws Exception {
@@ -352,6 +353,13 @@ public class NameUtilTest extends UsefulTestCase {
assertPreference("cL", "class", "classLoader");
}
public void testPreferStartMatchToMiddleMatch() {
assertPreference("*foo", "barFoo", "foobar");
assertPreference("*f", "barfoo", "barFoo");
assertPreference("*f", "barfoo", "foo");
assertPreference("*f", "asdf", "Foo", NameUtil.MatchingCaseSensitivity.NONE);
}
private static void assertPreference(@NonNls String pattern,
@NonNls String less,
@NonNls String more) {
@@ -363,7 +371,9 @@ public class NameUtilTest extends UsefulTestCase {
@NonNls String more,
NameUtil.MatchingCaseSensitivity sensitivity) {
NameUtil.MinusculeMatcher matcher = new NameUtil.MinusculeMatcher(pattern, sensitivity);
assertTrue(less + ">=" + more, matcher.matchingDegree(less) < matcher.matchingDegree(more));
int iLess = matcher.matchingDegree(less);
int iMore = matcher.matchingDegree(more);
assertTrue(iLess + ">=" + iMore + "; " + less + ">=" + more, iLess < iMore);
}
public void testPerformance() {
@@ -631,7 +631,11 @@ public class NameUtil {
int matchingCaps = 0;
CharArrayCharSequence seq = new CharArrayCharSequence(myPattern);
int p = -1;
TextRange first = null;
for (TextRange range : iterable) {
if (first == null) {
first = range;
}
for (int i = range.getStartOffset(); i < range.getEndOffset(); i++) {
char c = name.charAt(i);
p = StringUtil.indexOf(seq, c, p + 1, myPattern.length, false);
@@ -650,7 +654,10 @@ public class NameUtil {
commonStart++;
}
return -fragmentCount + matchingCaps * 10 + commonStart;
boolean prefixMatching = first != null && first.getStartOffset() == 0;
boolean middleWordStart = first != null && first.getStartOffset() > 0 && isWordStart(name, first.getStartOffset());
return -fragmentCount + matchingCaps * 10 + commonStart * 2 + (prefixMatching ? 2 : middleWordStart ? 1 : 0);
}
@Override