Fix lambda return hint for labeled expressions (KT-24828)
#KT-24828 Fixed
This commit is contained in:
@@ -55,16 +55,29 @@ private fun getNameOfFunctionThatTakesLambda(expression: KtExpression): String?
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun allowLabelOnExpressionPart(expression: KtExpression): Boolean {
|
private fun allowLabelOnExpressionPart(expression: KtExpression): Boolean {
|
||||||
val parent = expression.parent
|
val parent = expression.parent as? KtExpression ?: return false
|
||||||
return parent is KtAnnotatedExpression && parent.baseExpression == expression && parent.lineSeparatorBeforeBase()
|
return expression == expressionStatementPart(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun forceLabelOnExpressionPart(expression: KtExpression): Boolean {
|
private fun forceLabelOnExpressionPart(expression: KtExpression): Boolean {
|
||||||
return expression is KtAnnotatedExpression && expression.lineSeparatorBeforeBase()
|
return expressionStatementPart(expression) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtAnnotatedExpression.lineSeparatorBeforeBase(): Boolean {
|
private fun expressionStatementPart(expression: KtExpression): KtExpression? {
|
||||||
val base = baseExpression ?: return false
|
val splitPart: KtExpression = when (expression) {
|
||||||
val whiteSpace = base.node.treePrev?.psi as? PsiWhiteSpace ?: return false
|
is KtAnnotatedExpression -> expression.baseExpression
|
||||||
|
is KtLabeledExpression -> expression.baseExpression
|
||||||
|
else -> null
|
||||||
|
} ?: return null
|
||||||
|
|
||||||
|
if (!isNewLineBeforeExpression(splitPart)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return splitPart
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isNewLineBeforeExpression(expression: KtExpression): Boolean {
|
||||||
|
val whiteSpace = expression.node.treePrev?.psi as? PsiWhiteSpace ?: return false
|
||||||
return whiteSpace.text.contains("\n")
|
return whiteSpace.text.contains("\n")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,4 +158,23 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testLabeledStatement() {
|
||||||
|
check(
|
||||||
|
"""
|
||||||
|
fun test() {
|
||||||
|
run {
|
||||||
|
val files: Any? = null
|
||||||
|
run@
|
||||||
|
<hint text="^run"/>12
|
||||||
|
}
|
||||||
|
|
||||||
|
run {
|
||||||
|
val files: Any? = null
|
||||||
|
<hint text="^run"/>run@12
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user