diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hints/filtering/MethodMatcher.kt b/platform/platform-impl/src/com/intellij/codeInsight/hints/filtering/MethodMatcher.kt index 32cfbfdcca76..4ffa22a429a7 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hints/filtering/MethodMatcher.kt +++ b/platform/platform-impl/src/com/intellij/codeInsight/hints/filtering/MethodMatcher.kt @@ -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 diff --git a/platform/platform-tests/testSrc/com/intellij/codeInsight/hints/filtering/PatternExtractionTest.kt b/platform/platform-tests/testSrc/com/intellij/codeInsight/hints/filtering/PatternExtractionTest.kt index a72a87ee8533..cd95d132fecb 100644 --- a/platform/platform-tests/testSrc/com/intellij/codeInsight/hints/filtering/PatternExtractionTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/codeInsight/hints/filtering/PatternExtractionTest.kt @@ -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.*"