mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
K2 UAST: make nullity computation compatible with K1 UAST
In particular, for flexible type due to platform type, it's unknown. ^KTIJ-30464 fixed GitOrigin-RevId: cb7327a4f6291b94d627b3929c2b10b348b060c5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b291e01c7a
commit
f87c9af24d
@@ -616,6 +616,41 @@ interface UastResolveApiFixtureTestBase {
|
||||
TestCase.assertEquals("it", resolved.name)
|
||||
}
|
||||
|
||||
fun checkNullityOfResolvedLambdaParameter(myFixture: JavaCodeInsightTestFixture) {
|
||||
myFixture.addClass(
|
||||
"""
|
||||
class MyLiveData<T> {
|
||||
public void addSource(MyLiveData<S> source, Observer<? super S> onChanged) {}
|
||||
public void setValue(T value) {}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
myFixture.configureByText(
|
||||
"main.kt", """
|
||||
fun interface Observer<T> {
|
||||
fun onChanged(value: T)
|
||||
}
|
||||
|
||||
class Test {
|
||||
val myData = MyLiveData<List<Boolean>>()
|
||||
|
||||
init {
|
||||
myData.addSource(getSources()) { data ->
|
||||
myData.value = da<caret>ta
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSources(): MyLiveData<List<Boolean>> = TODO()
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
val ref = myFixture.file.findElementAt(myFixture.caretOffset).toUElement()?.getParentOfType<UReferenceExpression>()
|
||||
.orFail("cant convert to UReferenceExpression")
|
||||
val resolved = (ref.resolve() as? PsiParameter)
|
||||
.orFail("cant resolve lambda parameter")
|
||||
TestCase.assertFalse(resolved.annotations.any { it.isNullnessAnnotation })
|
||||
}
|
||||
|
||||
fun checkResolveSyntheticMethod(myFixture: JavaCodeInsightTestFixture) {
|
||||
myFixture.configureByText(
|
||||
"MyClass.kt", """
|
||||
|
||||
@@ -367,10 +367,12 @@ context(KaSession)
|
||||
internal fun nullability(ktType: KaType?): KaTypeNullability? {
|
||||
if (ktType == null) return null
|
||||
if (ktType is KaErrorType) return null
|
||||
return if (ktType.fullyExpandedType.canBeNull)
|
||||
KaTypeNullability.NULLABLE
|
||||
else
|
||||
KaTypeNullability.NON_NULLABLE
|
||||
val expanded = ktType.fullyExpandedType
|
||||
return when {
|
||||
expanded.hasFlexibleNullability -> KaTypeNullability.UNKNOWN
|
||||
expanded.canBeNull -> KaTypeNullability.NULLABLE
|
||||
else -> KaTypeNullability.NON_NULLABLE
|
||||
}
|
||||
}
|
||||
|
||||
context(KaSession)
|
||||
|
||||
@@ -142,6 +142,10 @@ class FirUastResolveApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), Ua
|
||||
checkResolveImplicitLambdaParameter_binary(myFixture)
|
||||
}
|
||||
|
||||
fun testNullityOfResolvedLambdaParameter() {
|
||||
checkNullityOfResolvedLambdaParameter(myFixture)
|
||||
}
|
||||
|
||||
fun testResolveSyntheticMethod() {
|
||||
checkResolveSyntheticMethod(myFixture)
|
||||
}
|
||||
|
||||
@@ -98,6 +98,10 @@ class FE1UastResolveApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), Ua
|
||||
checkResolveImplicitLambdaParameter_binary(myFixture)
|
||||
}
|
||||
|
||||
fun testNullityOfResolvedLambdaParameter() {
|
||||
checkNullityOfResolvedLambdaParameter(myFixture)
|
||||
}
|
||||
|
||||
fun testResolveSyntheticMethod() {
|
||||
checkResolveSyntheticMethod(myFixture)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user