prefer more recent matches

This commit is contained in:
peter
2012-06-08 14:54:34 +02:00
parent 8edc336fd2
commit e67c74c7ba
2 changed files with 6 additions and 1 deletions
@@ -390,6 +390,10 @@ public class NameUtilTest extends UsefulTestCase {
assertPreference(" Boo", "boolean", "Boolean", NameUtil.MatchingCaseSensitivity.NONE);
}
public void testPreferEarlyMatching() {
assertPreference(" path", "getAbsolutePath", "findPath");
}
public void testMeaningfulMatchingDegree() {
assertTrue(new MinusculeMatcher(" EUC-", NameUtil.MatchingCaseSensitivity.FIRST_LETTER).matchingDegree("x-EUC-TW") > Integer.MIN_VALUE);
}
@@ -276,8 +276,9 @@ public class MinusculeMatcher implements Matcher {
boolean prefixMatching = first != null && first.getStartOffset() == 0;
boolean middleWordStart = first != null && first.getStartOffset() > 0 && NameUtil.isWordStart(name, first.getStartOffset());
int startIndex = first != null ? first.getStartOffset() : 42;
return -fragmentCount + matchingCase * 10 + commonStart + (prefixMatching ? 2 : middleWordStart ? 1 : 0) * 100;
return -fragmentCount + matchingCase * 10 + commonStart - startIndex + (prefixMatching ? 2 : middleWordStart ? 1 : 0) * 100;
}
@Override