mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
MinusculeMatcher: pay less attention to case mismatches in non-completion contexts (IDEA-119877)
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
import java.io.*;
|
||||
|
||||
class Foo {
|
||||
{
|
||||
pim<caret>
|
||||
}
|
||||
}
|
||||
|
||||
class PNGImageDecoder {}
|
||||
class PImageDecoder {}
|
||||
class posIdMap {}
|
||||
+5
@@ -641,6 +641,11 @@ interface TxANotAnno {}
|
||||
checkPreferredItems 0, 'FileNotFoundException', 'File'
|
||||
}
|
||||
|
||||
public void testHonorFirstLetterCase() {
|
||||
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE;
|
||||
checkPreferredItems 0, 'posIdMap', 'PImageDecoder', 'PNGImageDecoder'
|
||||
}
|
||||
|
||||
public void testGlobalStaticMemberStats() {
|
||||
configureNoCompletion(getTestName(false) + ".java")
|
||||
myFixture.complete(CompletionType.BASIC, 2)
|
||||
|
||||
+2
-2
@@ -143,10 +143,10 @@ public class CamelHumpMatcher extends PrefixMatcher {
|
||||
int matchStart = ranges.get(0).getStartOffset();
|
||||
int underscoreEnd = skipUnderscores(string);
|
||||
if (matchStart > 0 && matchStart <= underscoreEnd) {
|
||||
return myCaseInsensitiveMatcher.matchingDegree(string.substring(matchStart)) - 1;
|
||||
return myCaseInsensitiveMatcher.matchingDegree(string.substring(matchStart), true) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return myMatcher.matchingDegree(string);
|
||||
return myMatcher.matchingDegree(string, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,12 +522,6 @@ public class NameUtilMatchingTest extends UsefulTestCase {
|
||||
assertPreference("*e", "fileIndex", "file", NameUtil.MatchingCaseSensitivity.NONE);
|
||||
}
|
||||
|
||||
public void "test first letter case match is important"() {
|
||||
assertPreference("*pim", "PNGImageDecoder", "posIdMap", NameUtil.MatchingCaseSensitivity.NONE)
|
||||
assertPreference("*pim", "PImageDecoder", "posIdMap", NameUtil.MatchingCaseSensitivity.NONE)
|
||||
assertPreference("*er", "Error", "exchangeRequest", NameUtil.MatchingCaseSensitivity.NONE)
|
||||
}
|
||||
|
||||
public void testPreferences() {
|
||||
assertPreference(" fb", "FooBar", "_fooBar", NameUtil.MatchingCaseSensitivity.NONE);
|
||||
assertPreference("*foo", "barFoo", "foobar");
|
||||
@@ -571,6 +565,14 @@ public class NameUtilMatchingTest extends UsefulTestCase {
|
||||
assertNoPreference(" path", "getAbsolutePath", "findPath", NameUtil.MatchingCaseSensitivity.FIRST_LETTER);
|
||||
}
|
||||
|
||||
public void testPreferStartMatching() {
|
||||
assertPreference("*tree", "FooTree", "Tree", NameUtil.MatchingCaseSensitivity.NONE);
|
||||
}
|
||||
|
||||
public void testPreferContiguousMatching() {
|
||||
assertPreference("*mappablejs", "mappable-js.scope.js", "MappableJs.js", NameUtil.MatchingCaseSensitivity.NONE);
|
||||
}
|
||||
|
||||
public void testMeaningfulMatchingDegree() {
|
||||
assertTrue(caseInsensitiveMatcher(" EUC-").matchingDegree("x-EUC-TW") > Integer.MIN_VALUE);
|
||||
}
|
||||
|
||||
@@ -139,6 +139,10 @@ public class MinusculeMatcher implements Matcher {
|
||||
}
|
||||
|
||||
public int matchingDegree(@NotNull String name) {
|
||||
return matchingDegree(name, false);
|
||||
}
|
||||
|
||||
public int matchingDegree(@NotNull String name, boolean valueStartCaseMatch) {
|
||||
FList<TextRange> iterable = matchingFragments(name);
|
||||
if (iterable == null) return Integer.MIN_VALUE;
|
||||
if (iterable.isEmpty()) return 0;
|
||||
@@ -178,7 +182,7 @@ public class MinusculeMatcher implements Matcher {
|
||||
else if (isHumpStart) matchingCase += 1; // if a lowercase matches lowercase hump start, that also means something
|
||||
} else if (isHumpStart) {
|
||||
// disfavor hump starts where pattern letter case doesn't match name case
|
||||
matchingCase -= 20;
|
||||
matchingCase -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,8 +194,9 @@ public class MinusculeMatcher implements Matcher {
|
||||
|
||||
return (wordStart ? 1000 : 0) +
|
||||
integral * 10 +
|
||||
matchingCase * (startMatch ? 10 : 1) + // in start matches, case is more important; in middle matches - fragment length (integral)
|
||||
matchingCase * (startMatch && valueStartCaseMatch ? 10 : 1) +
|
||||
(afterSeparator ? 0 : 2) +
|
||||
(startMatch ? 1 : 0) +
|
||||
(finalMatch ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user