mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[parameter hints] treat absence of closing parenthesis as error
This commit is contained in:
+18
-6
@@ -56,19 +56,31 @@ object MatcherConstructor {
|
||||
val trimmedMatcher = matcher.trim()
|
||||
if (trimmedMatcher.isEmpty()) return null
|
||||
|
||||
val index = trimmedMatcher.indexOf('(')
|
||||
if (index < 0) {
|
||||
val openParenthIndex = trimmedMatcher.indexOf('(')
|
||||
if (openParenthIndex < 0) {
|
||||
return Couple(trimmedMatcher, "")
|
||||
}
|
||||
else if (index == 0) {
|
||||
return Couple("", trimmedMatcher)
|
||||
else if (openParenthIndex == 0) {
|
||||
val paramsMatcher = getParamsMatcher(trimmedMatcher) ?: return null
|
||||
return Couple("", paramsMatcher)
|
||||
}
|
||||
|
||||
val methodMatcher = trimmedMatcher.substring(0, index)
|
||||
val paramsMatcher = trimmedMatcher.substring(index)
|
||||
val methodMatcher = trimmedMatcher.substring(0, openParenthIndex)
|
||||
val paramsMatcher = getParamsMatcher(trimmedMatcher) ?: return null
|
||||
|
||||
return Couple(methodMatcher.trim(), paramsMatcher.trim())
|
||||
}
|
||||
|
||||
private fun getParamsMatcher(matcher: String): String? {
|
||||
val openBraceIndex = matcher.indexOf("(")
|
||||
val closeBraceIndex = matcher.indexOf(")")
|
||||
|
||||
if (openBraceIndex >= 0 && closeBraceIndex > 0) {
|
||||
return matcher.substring(openBraceIndex, closeBraceIndex + 1).trim()
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private fun createParametersMatcher(paramsMatcher: String): ParamMatcher? {
|
||||
if (paramsMatcher.length <= 2) return null
|
||||
|
||||
+10
@@ -31,6 +31,16 @@ class PatternExtractionTest : TestCase() {
|
||||
assertThat(nameMatcher).isEqualTo(matcher.first)
|
||||
assertThat(paramsMatcher).isEqualTo(matcher.second)
|
||||
}
|
||||
|
||||
fun String.assertError() {
|
||||
val matcher = MatcherConstructor.extract(this)
|
||||
assertThat(matcher).isNull()
|
||||
}
|
||||
|
||||
fun `test error when no closing brace`() {
|
||||
val text = "Test.foo(paramName"
|
||||
text.assertError()
|
||||
}
|
||||
|
||||
fun `test match all methods from package`() {
|
||||
val text = "java.lang.*"
|
||||
|
||||
Reference in New Issue
Block a user