MinusculeMatcher cleanup

This commit is contained in:
Max Medvedev
2018-06-29 12:39:35 +03:00
parent f5d2fe8f66
commit 51ddf49f94
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.codeStyle;
import com.intellij.openapi.util.TextRange;
@@ -55,7 +41,7 @@ public class MinusculeMatcher implements Matcher {
* @param options case sensitivity settings
* @param hardSeparators A string of characters (empty by default). Lowercase humps don't work for parts separated by any of these characters.
* Need either an explicit uppercase letter or the same separator character in prefix
*/
*/
MinusculeMatcher(@NotNull String pattern, @NotNull NameUtil.MatchingCaseSensitivity options, @NotNull String hardSeparators) {
myOptions = options;
myPattern = StringUtil.trimEnd(pattern, "* ").toCharArray();
@@ -116,6 +102,7 @@ public class MinusculeMatcher implements Matcher {
return false;
}
@NotNull
private static FList<TextRange> prependRange(@NotNull FList<TextRange> ranges, int from, int length) {
TextRange head = ranges.getHead();
if (head != null && head.getStartOffset() == from + length) {
@@ -181,7 +168,8 @@ public class MinusculeMatcher implements Matcher {
return (wordStart ? 1000 : 0) +
matchingCase +
(- fragments.size() - skippedHumps * 10) +
-fragments.size() +
-skippedHumps * 10 +
(afterSeparator ? 0 : 2) +
(startMatch ? 1 : 0) +
(finalMatch ? 1 : 0);
@@ -319,7 +307,7 @@ public class MinusculeMatcher implements Matcher {
boolean allowSpecialChars,
boolean isAsciiName) {
boolean wordStartsOnly = !isPatternChar(patternIndex - 1, '*') && !isWordSeparator[patternIndex];
int maxFoundLength = 0;
while (true) {
nameIndex = findNextPatternCharOccurrence(name, nameIndex, patternIndex, isAsciiName, allowSpecialChars, wordStartsOnly);
@@ -432,7 +420,7 @@ public class MinusculeMatcher implements Matcher {
private boolean isMiddleMatch(@NotNull String name, int patternIndex, int nameIndex) {
return isPatternChar(patternIndex - 1, '*') && !isWildcard(patternIndex + 1) &&
Character.isLetterOrDigit(name.charAt(nameIndex)) && !NameUtil.isWordStart(name, nameIndex);
Character.isLetterOrDigit(name.charAt(nameIndex)) && !NameUtil.isWordStart(name, nameIndex);
}
@Nullable
@@ -463,7 +451,7 @@ public class MinusculeMatcher implements Matcher {
/**
* When pattern is "CU" and the name is "CurrentUser", we already have a prefix "Cu" that matches,
* but we try to find uppercase "U" later in name for better matching degree
*/
*/
private FList<TextRange> improveCamelHumps(@NotNull String name,
int patternIndex,
int nameIndex,
@@ -532,6 +520,7 @@ public class MinusculeMatcher implements Matcher {
}
return false;
}
private boolean isPatternChar(int patternIndex, char c) {
return patternIndex >= 0 && patternIndex < myPattern.length && myPattern[patternIndex] == c;
}
@@ -575,12 +564,14 @@ public class MinusculeMatcher implements Matcher {
}
return c;
}
private static char toLowerAscii(char c) {
if (c >= 'A' && c <= 'Z') {
return (char)(c - ('A' - 'a'));
}
return c;
}
@NonNls
@Override
public String toString() {