mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Parameter Name Hints] allow to use *smth* (contains "smth") syntax for blacklist setup
This commit is contained in:
+15
-8
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+10
-3
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user