diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hints/filtering/StringMatcherBuilder.kt b/platform/platform-impl/src/com/intellij/codeInsight/hints/filtering/StringMatcherBuilder.kt index f86a6170a224..f6e7ad47199e 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hints/filtering/StringMatcherBuilder.kt +++ b/platform/platform-impl/src/com/intellij/codeInsight/hints/filtering/StringMatcherBuilder.kt @@ -27,29 +27,36 @@ object StringMatcherBuilder { fun create(matcher: String): StringMatcher? { if (matcher.isEmpty()) return StringMatcherImpl { true } - - val asterisksCount = matcher.count { it == '*' } - if (asterisksCount > 1) return null - if (asterisksCount == 1) return createAsterisksMatcher(matcher) - - return StringMatcherImpl { it == matcher } + return createAsterisksMatcher(matcher) } private fun createAsterisksMatcher(matcher: String): StringMatcher? { + val asterisksCount = matcher.count { it == '*' } + if (asterisksCount > 2) return null + + if (asterisksCount == 0) { + return StringMatcherImpl { it == matcher } + } + if (matcher == "*") { return StringMatcherImpl { true } } - if (matcher.startsWith('*')) { + if (matcher.startsWith('*') && asterisksCount == 1) { val target = matcher.substring(1) return StringMatcherImpl { it.endsWith(target) } } - if (matcher.endsWith('*')) { + if (matcher.endsWith('*') && asterisksCount == 1) { val target = matcher.substring(0, matcher.length - 1) return StringMatcherImpl { it.startsWith(target) } } + if (matcher.startsWith('*') && matcher.endsWith('*')) { + val target = matcher.substring(1, matcher.length - 1) + return StringMatcherImpl { it.contains(target) } + } + return null } diff --git a/platform/platform-tests/testSrc/com/intellij/codeInsight/hints/filtering/StringMatchingTest.kt b/platform/platform-tests/testSrc/com/intellij/codeInsight/hints/filtering/StringMatchingTest.kt index 982e1ed5fd1a..6bb2e86eb7ae 100644 --- a/platform/platform-tests/testSrc/com/intellij/codeInsight/hints/filtering/StringMatchingTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/codeInsight/hints/filtering/StringMatchingTest.kt @@ -29,24 +29,31 @@ class StringMatchingTest : TestCase() { } fun `test simple`() { - val matcher = com.intellij.codeInsight.hints.filtering.StringMatcherBuilder.create("aaa")!! + val matcher = StringMatcherBuilder.create("aaa")!! matcher.assertMatches("aaa") matcher.assertNotMatches("aaaa", "aab", "", "*", "a", "baaa") } fun `test asterisks before`() { - val matcher = com.intellij.codeInsight.hints.filtering.StringMatcherBuilder.create("aaa*")!! + val matcher = StringMatcherBuilder.create("aaa*")!! matcher.assertMatches("aaa", "aaaa", "aaaaaa", "aaaqwe") matcher.assertNotMatches("baaa", "nnaaa", "qweaaa") } fun `test asterisks after`() { - val matcher = com.intellij.codeInsight.hints.filtering.StringMatcherBuilder.create("*aaa")!! + val matcher = StringMatcherBuilder.create("*aaa")!! matcher.assertMatches("aaa", "aaaa", "baaa", "aawweraaa") matcher.assertNotMatches("aaab", "aaabaa") } + fun `test multiple asterisks`() { + val matcher = StringMatcherBuilder.create("*aax*")!! + matcher.assertMatches("qaaxq", "qqaaxqqq") + matcher.assertNotMatches("ax", "axx") + } + + } \ No newline at end of file