Fix double return hint in lambda for annotated expression (KT-23238)
#KT-23238 Fixed
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.parameterInfo
|
package org.jetbrains.kotlin.idea.parameterInfo
|
||||||
|
|
||||||
import com.intellij.codeInsight.hints.InlayInfo
|
import com.intellij.codeInsight.hints.InlayInfo
|
||||||
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
@@ -18,12 +19,11 @@ fun provideLambdaReturnValueHints(expression: KtExpression): List<InlayInfo> {
|
|||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
val parent = expression.parent
|
if (!KtPsiUtil.isStatement(expression)) {
|
||||||
if (parent is KtDotQualifiedExpression ||
|
if (!allowLabelOnExpressionPart(expression)) {
|
||||||
parent is KtSafeQualifiedExpression ||
|
return emptyList()
|
||||||
parent is KtBinaryExpression ||
|
}
|
||||||
parent is KtUnaryExpression
|
} else if (forceLabelOnExpressionPart(expression)) {
|
||||||
) {
|
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,3 +53,18 @@ private fun getNameOfFunctionThatTakesLambda(expression: KtExpression): String?
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun allowLabelOnExpressionPart(expression: KtExpression): Boolean {
|
||||||
|
val parent = expression.parent
|
||||||
|
return parent is KtAnnotatedExpression && parent.baseExpression == expression && parent.lineSeparatorBeforeBase()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun forceLabelOnExpressionPart(expression: KtExpression): Boolean {
|
||||||
|
return expression is KtAnnotatedExpression && expression.lineSeparatorBeforeBase()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KtAnnotatedExpression.lineSeparatorBeforeBase(): Boolean {
|
||||||
|
val base = baseExpression ?: return false
|
||||||
|
val whiteSpace = base.node.treePrev?.psi as? PsiWhiteSpace ?: return false
|
||||||
|
return whiteSpace.text.contains("\n")
|
||||||
|
}
|
||||||
|
|||||||
@@ -136,4 +136,26 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testAnnotatedStatement() {
|
||||||
|
check(
|
||||||
|
"""
|
||||||
|
@Target(AnnotationTarget.EXPRESSION)
|
||||||
|
annotation class Some
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
run {
|
||||||
|
val files: Any? = null
|
||||||
|
@Some
|
||||||
|
<hint text="^run"/>12
|
||||||
|
}
|
||||||
|
|
||||||
|
run {
|
||||||
|
val files: Any? = null
|
||||||
|
<hint text="^run"/>@Some 12
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user