mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FIR/UAST: handle nullable receiver parameter of extension function as anchor
^KTIJ-25925 Fixed GitOrigin-RevId: 46bbe1b0ee60f25039911c16b22b85e88d9abbc3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d09828ce08
commit
2d036b92c0
+3
-1
@@ -79,7 +79,9 @@ abstract class AbstractKotlinUVariable(
|
||||
is KtNamedDeclaration -> sourcePsi.nameIdentifier
|
||||
is KtTypeReference -> sourcePsi.typeElement?.let {
|
||||
// receiver param in extension function
|
||||
(it as? KtUserType)?.referenceExpression?.getIdentifier() ?: it
|
||||
// Unwrap the type if the receiver param is nullable
|
||||
val typeElement = (it as? KtNullableType)?.innerType ?: it
|
||||
(typeElement as? KtUserType)?.referenceExpression?.getIdentifier() ?: it
|
||||
} ?: sourcePsi
|
||||
is KtNameReferenceExpression -> sourcePsi.getReferencedNameElement()
|
||||
is KtBinaryExpression, is KtCallExpression -> null // e.g. `foo("Lorem ipsum") ?: foo("dolor sit amet")`
|
||||
|
||||
+26
@@ -640,4 +640,30 @@ interface UastApiFixtureTestBase : UastPluginSelection {
|
||||
})
|
||||
}
|
||||
|
||||
fun checkIdentifierOfNullableExtensionReceiver(myFixture: JavaCodeInsightTestFixture) {
|
||||
myFixture.configureByText(
|
||||
"main.kt", """
|
||||
enum class SortOrder {
|
||||
ASCENDING, DESCENDING, UNSORTED
|
||||
}
|
||||
|
||||
fun <C> Comparator<C>?.withOrder(sortOrder: SortOrder): Comparator<C>? =
|
||||
this?.let {
|
||||
when (sortOrder) {
|
||||
SortOrder.ASCENDING -> it
|
||||
SortOrder.DESCENDING -> it.reversed()
|
||||
SortOrder.UNSORTED -> null
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
val uFile = myFixture.file.toUElement()!!
|
||||
val withOrder = uFile.findElementByTextFromPsi<UMethod>("withOrder", strict = false)
|
||||
.orFail("can't convert extension function: withOrder")
|
||||
val extensionReceiver = withOrder.uastParameters.first()
|
||||
val identifier = extensionReceiver.uastAnchor as? UIdentifier
|
||||
TestCase.assertNotNull(identifier)
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -82,4 +82,8 @@ class FirUastApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), UastApiFi
|
||||
doCheck("LambdaImplicitParameters", ::checkLambdaImplicitParameters)
|
||||
}
|
||||
|
||||
fun testIdentifierOfNullableExtensionReceiver() {
|
||||
checkIdentifierOfNullableExtensionReceiver(myFixture)
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -75,4 +75,8 @@ class FE1UastApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), UastApiFi
|
||||
checkLambdaImplicitParameters(myFixture)
|
||||
}
|
||||
|
||||
fun testIdentifierOfNullableExtensionReceiver() {
|
||||
checkIdentifierOfNullableExtensionReceiver(myFixture)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user