[extract method] infer nullability for simple cases

GitOrigin-RevId: 4ff749ebc59b26de55bfe5bb24787e88352c01ca
This commit is contained in:
Alexandr Suhinin
2024-07-24 15:58:39 +03:00
committed by intellij-monorepo-bot
parent 32ae65de50
commit 5ecb68030b

View File

@@ -221,9 +221,12 @@ class CodeFragmentAnalyzer(val elements: List<PsiElement>) {
companion object {
fun inferNullability(expressionGroup: List<PsiExpression>): Nullability {
val expressionSet = expressionGroup.toHashSet()
if (expressionSet.any { it.type == PsiTypes.nullType() }) return Nullability.NULLABLE
if (expressionSet.isEmpty()) return Nullability.UNKNOWN
val types = expressionSet.map { expression -> expression.type }
if (types.any { type -> type == PsiTypes.nullType() }) return Nullability.NULLABLE
if (types.all { type -> type is PsiPrimitiveType }) return Nullability.NOT_NULL
if (expressionSet.all { expression -> expression is PsiLiteralExpression }) return Nullability.NOT_NULL
val fragmentToAnalyze = ControlFlowUtil.findCodeFragment(expressionSet.first())
val dfaRunner = StandardDataFlowRunner(fragmentToAnalyze.project)