mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
MinusculeMatcher: consider trailing variant even if the same sequence in the middle has failed
regression discovered while fixing IDEA-188351
This commit is contained in:
@@ -412,6 +412,7 @@ public class NameUtilMatchingTest extends TestCase {
|
||||
assertDoesntMatch("Foo ", "Foox");
|
||||
assertDoesntMatch("Collections ", "CollectionSplitter");
|
||||
assertMatches("CollectionS ", "CollectionSplitter");
|
||||
assertMatches("*run ", "in Runnable.run");
|
||||
|
||||
assertDoesntMatch("*l ", "AppDelegate");
|
||||
assertDoesntMatch("*le ", "AppDelegate");
|
||||
|
||||
@@ -281,9 +281,8 @@ public class MinusculeMatcher implements Matcher {
|
||||
} while (isWildcard(patternIndex));
|
||||
|
||||
if (patternIndex == myPattern.length) {
|
||||
boolean space = isPatternChar(patternIndex - 1, ' ');
|
||||
// the trailing space should match if the pattern ends with the last word part, or only its first hump character
|
||||
if (space && nameIndex != name.length() && (patternIndex < 2 || !isUpperCaseOrDigit(myPattern[patternIndex - 2]))) {
|
||||
if (isTrailingSpacePattern() && nameIndex != name.length() && (patternIndex < 2 || !isUpperCaseOrDigit(myPattern[patternIndex - 2]))) {
|
||||
int spaceIndex = name.indexOf(' ', nameIndex);
|
||||
if (spaceIndex >= 0) {
|
||||
return FList.<TextRange>emptyList().prepend(TextRange.from(spaceIndex, 1));
|
||||
@@ -301,6 +300,10 @@ public class MinusculeMatcher implements Matcher {
|
||||
return matchSkippingWords(name, patternIndex, nameIndex, true, isAsciiName);
|
||||
}
|
||||
|
||||
private boolean isTrailingSpacePattern() {
|
||||
return isPatternChar(myPattern.length - 1, ' ');
|
||||
}
|
||||
|
||||
private static boolean isUpperCaseOrDigit(char p) {
|
||||
return Character.isUpperCase(p) || Character.isDigit(p);
|
||||
}
|
||||
@@ -328,7 +331,7 @@ public class MinusculeMatcher implements Matcher {
|
||||
// match the remaining pattern only if we haven't already seen fragment of the same (or bigger) length
|
||||
// because otherwise it means that we already tried to match remaining pattern letters after it with the remaining name and failed
|
||||
// but now we have the same remaining pattern letters and even less remaining name letters, and so will fail as well
|
||||
if (fragmentLength > maxFoundLength) {
|
||||
if (fragmentLength > maxFoundLength || nameIndex + fragmentLength == name.length() && isTrailingSpacePattern()) {
|
||||
if (!isMiddleMatch(name, patternIndex, nameIndex)) {
|
||||
maxFoundLength = fragmentLength;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user