mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
constrain middle matching on uppercase constant names (IDEA-101397)
This commit is contained in:
@@ -257,6 +257,7 @@ public class NameUtilTest extends UsefulTestCase {
|
||||
assertMatches("*f", "reformatCode");
|
||||
assertDoesntMatch("*fc", "reformatCode");
|
||||
assertDoesntMatch("*sTC", "LazyClassTypeConstructor");
|
||||
assertDoesntMatch("*Icon", "LEADING_CONSTRUCTOR");
|
||||
}
|
||||
|
||||
public void testMiddleMatchingUnderscore() {
|
||||
|
||||
@@ -268,7 +268,10 @@ public class MinusculeMatcher implements Matcher {
|
||||
if (!allowSpecialChars && myHasDots && StringUtil.contains(name, nameIndex, nextOccurrence, '.')) {
|
||||
return null;
|
||||
}
|
||||
if (!isUpperCase[patternIndex] || NameUtil.isWordStart(name, nextOccurrence)) {
|
||||
// uppercase should match either uppercase or a word start
|
||||
if (!isUpperCase[patternIndex] ||
|
||||
star && Character.isUpperCase(name.charAt(nextOccurrence)) ||
|
||||
NameUtil.isWordStart(name, nextOccurrence)) {
|
||||
FList<TextRange> ranges = matchFragment(name, patternIndex, nextOccurrence, matchingState);
|
||||
if (ranges != null) {
|
||||
return ranges;
|
||||
@@ -312,8 +315,9 @@ public class MinusculeMatcher implements Matcher {
|
||||
}
|
||||
|
||||
// middle matches have to be at least of length 2, to prevent too many irrelevant matches
|
||||
int minFragment = isPatternChar(patternIndex - 1, '*') && Character.isLetterOrDigit(name.charAt(nameIndex)) && !NameUtil
|
||||
.isWordStart(name, nameIndex) ? 2 : 1;
|
||||
int minFragment = isPatternChar(patternIndex - 1, '*') && !isWildcard(patternIndex + 1) &&
|
||||
Character.isLetterOrDigit(name.charAt(nameIndex)) && !NameUtil.isWordStart(name, nameIndex)
|
||||
? 2 : 1;
|
||||
int i = 1;
|
||||
boolean ignoreCase = myOptions != NameUtil.MatchingCaseSensitivity.ALL;
|
||||
while (nameIndex + i < name.length() &&
|
||||
|
||||
@@ -328,10 +328,17 @@ public class NameUtil {
|
||||
|
||||
static boolean isWordStart(String text, int i) {
|
||||
char c = text.charAt(i);
|
||||
if (isWordStart(c)) {
|
||||
if (Character.isUpperCase(c)) {
|
||||
if (i > 0 && Character.isUpperCase(text.charAt(i - 1))) {
|
||||
// check that we're not in the middle of an all-caps word
|
||||
return i + 1 < text.length() && Character.isLowerCase(text.charAt(i + 1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!Character.isLetterOrDigit(c)) {
|
||||
if (Character.isDigit(c)) {
|
||||
return true;
|
||||
}
|
||||
if (!Character.isLetter(c)) {
|
||||
return false;
|
||||
}
|
||||
return i == 0 || !Character.isLetterOrDigit(text.charAt(i - 1));
|
||||
|
||||
Reference in New Issue
Block a user