From bb15a6425c8e52723f5a97e51c98a15bbc7f5abc Mon Sep 17 00:00:00 2001 From: Jaebaek Seo Date: Fri, 21 Oct 2022 17:58:10 +0000 Subject: [PATCH] Add KDoc for KtWhenExpression.getMissingCases() KtWhenExpression.getMissingCases() reports the same missing cases even when the KtWhenExpression has an else branch. Without a description, it is difficult to be aware of it. --- .../api/components/KtExpressionInfoProvider.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtExpressionInfoProvider.kt b/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtExpressionInfoProvider.kt index 4507dd27cd5..450b8c3edbd 100644 --- a/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtExpressionInfoProvider.kt +++ b/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtExpressionInfoProvider.kt @@ -22,6 +22,24 @@ public interface KtExpressionInfoProviderMixIn : KtAnalysisSessionMixIn { public fun KtReturnExpression.getReturnTargetSymbol(): KtCallableSymbol? = withValidityAssertion { analysisSession.expressionInfoProvider.getReturnExpressionTargetSymbol(this) } + /** + * Returns cases missing from the branches of [KtWhenExpression]. + * + * The missing cases of the when-expression in the following example are Direction.WEST and Direction.EAST: + * + * enum class Direction { + * NORTH, SOUTH, WEST, EAST + * } + * foo = when(direction) { + * Direction.NORTH -> 1 + * Direction.SOUTH -> 2 + * else -> 3 + * } + * + * Note that this function returns the same missing cases regardless of the existence of the else branch. + * If you have to assume that it does not have the missing cases when it has an else branch, + * you need a separate check whether it has an else branch or not. + */ public fun KtWhenExpression.getMissingCases(): List = withValidityAssertion { analysisSession.expressionInfoProvider.getWhenMissingCases(this) }