FIR/UAST: regression test for parent of param of catch clause

^KTIJ-18510 Fixed

GitOrigin-RevId: 4865086a92f0677bdfb47ca571a54b9ff76d8461
This commit is contained in:
Jinseong Jeon
2023-04-28 11:14:27 +00:00
committed by intellij-monorepo-bot
parent 9b51e60a0c
commit ac2f4b9d82
3 changed files with 36 additions and 2 deletions
@@ -1383,7 +1383,6 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
myFixture.checkIsMethodNameCanBeOneOf(listOf("invoke"))
}
fun checkIsMethodCallCanBeOneOfRegularMethod(myFixture: JavaCodeInsightTestFixture) {
@Language("kotlin")
val mainCode = """
@@ -1424,7 +1423,7 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
private fun JavaCodeInsightTestFixture.checkIsMethodNameCanBeOneOf(names: Collection<String>) {
var call: UCallExpression? = null
val uFile = file.toUElement() as KotlinUFile
val uFile = file.toUElement() as KotlinUFile
uFile.accept(
object : AbstractUastVisitor() {
override fun visitCallExpression(node: UCallExpression): Boolean {
@@ -1444,4 +1443,31 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
TestCase.assertTrue("expected method name to be one of ${names}", ktCall.methodNameCanBeOneOf(names))
}
fun checkParentOfParameterOfCatchClause(myFixture: JavaCodeInsightTestFixture) {
myFixture.configureByText(
"main.kt", """
try {
} catch (exception : Exception) {
println(exception)
}
""".trimIndent()
)
myFixture.file.toUElement()!!.accept(object : AbstractUastVisitor() {
private var catchClause: UCatchClause? = null
override fun visitCatchClause(node: UCatchClause): Boolean {
catchClause = node
return super.visitCatchClause(node)
}
override fun visitSimpleNameReferenceExpression(node: USimpleNameReferenceExpression): Boolean {
val resolved = node.resolve()?.toUElement()
TestCase.assertTrue(resolved?.uastParent is UCatchClause)
TestCase.assertEquals(catchClause, resolved)
return super.visitSimpleNameReferenceExpression(node)
}
})
}
}
@@ -215,4 +215,8 @@ class FirUastResolveApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), Ua
fun testIsMethodCallCanBeOneOfImportAliased() {
checkIsMethodCallCanBeOneOfImportAliased(myFixture)
}
fun testParentOfParameterOfCatchClause() {
checkParentOfParameterOfCatchClause(myFixture)
}
}
@@ -170,4 +170,8 @@ class FE1UastResolveApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), Ua
fun testIsMethodCallCanBeOneOfImportAliased() {
checkIsMethodCallCanBeOneOfImportAliased(myFixture)
}
fun testParentOfParameterOfCatchClause() {
checkParentOfParameterOfCatchClause(myFixture)
}
}