Files
openide/jvm/jvm-analysis-kotlin-tests-shared/testSrc/com/intellij/codeInspection/tests/kotlin/KotlinCallMatcherTest.kt
Bart van Helvert f59622a97b [jvm] Enable call matcher test
GitOrigin-RevId: 6e60b05400606840a6f5070d76284059d000b4cb
2024-09-14 15:32:51 +00:00

65 lines
2.5 KiB
Kotlin

package com.intellij.codeInspection.tests.kotlin
import com.intellij.jvm.analysis.internal.testFramework.CallMatcherTestBase
import com.intellij.jvm.analysis.testFramework.JvmLanguage
import com.intellij.testFramework.LightProjectDescriptor
import com.siyeh.ig.callMatcher.CallMatcher
import org.jetbrains.kotlin.idea.test.ExpectedPluginModeProvider
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.idea.test.setUpWithKotlinPlugin
abstract class KotlinCallMatcherTest : CallMatcherTestBase(), ExpectedPluginModeProvider {
override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.getInstance()
override fun setUp() {
setUpWithKotlinPlugin(testRootDisposable) { super.setUp() }
}
fun testInstanceMethodCall() {
checkMatchCall(JvmLanguage.KOTLIN, CallMatcher.instanceCall("Foo", "bar").parameterCount(0), """
class Foo { fun bar() { } }
fun main() { Foo().bar() }
""".trimIndent())
}
fun testMultipleArgumentsCall() {
checkMatchCall(JvmLanguage.KOTLIN, CallMatcher.instanceCall("Foo", "bar").parameterCount(3), """
class Foo { fun bar(x: Int, y: Int, z: Int) { } }
fun main() { Foo().bar(0, 0, 0) }
""".trimIndent())
}
fun testMultipleArgumentsCallDefaultArg() {
checkMatchCall(JvmLanguage.KOTLIN, CallMatcher.instanceCall("Foo", "bar").parameterCount(3), """
class Foo { fun bar(x: Int, y: Int, z: Int = 0) { } }
fun main() { Foo().bar(0, 0) }
""".trimIndent())
}
fun testMultipleArgumentTypes() {
checkMatchCall(JvmLanguage.KOTLIN, CallMatcher.instanceCall("Foo", "bar").parameterTypes("int", "long", "double"), """
class Foo { fun bar(x: Int, y: Long, z: Double) { } }
fun main() { Foo().bar(0, 0L, 0.0) }
""".trimIndent())
}
fun testInstanceMethodReference() {
checkMatchCallableReference(JvmLanguage.KOTLIN, CallMatcher.instanceCall("java.lang.String", "plus").parameterCount(1), """
class Foo { fun bar(arg: String.(String) -> String) { } }
class Main { fun main() { Foo().bar(String::plus) } }
""".trimIndent())
}
fun testMethodReferenceArgumentTypes() {
checkMatchCallableReference(JvmLanguage.KOTLIN, CallMatcher.instanceCall("java.lang.String", "plus").parameterTypes("java.lang.Object"), """
class Foo { fun bar(arg: String.(String) -> String) { } }
class Main { fun main() { Foo().bar(String::plus) } }
""".trimIndent())
}
}