From 51ddf49f94d7f32e63fbc2f855e4e14a0a22207b Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Wed, 27 Jun 2018 15:05:38 +0300 Subject: [PATCH] MinusculeMatcher cleanup --- .../psi/codeStyle/MinusculeMatcher.java | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java b/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java index 8c2ff8c20624..d51be9a463b4 100644 --- a/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java +++ b/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java @@ -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 prependRange(@NotNull FList 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 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() {