[kotlin] False negative "Join declaration and assignment" with a qualified reference

^KTIJ-26630 Fixed

GitOrigin-RevId: 9a4ce1330396b57249cd2eeb1f49c456f081690b
This commit is contained in:
Alexey Belkov
2023-08-14 19:22:04 +00:00
committed by intellij-monorepo-bot
parent b63199a336
commit 40cd2a16b1
6 changed files with 45 additions and 6 deletions
@@ -126,19 +126,18 @@ class JoinDeclarationAndAssignmentIntention : SelfTargetingRangeIntention<KtProp
if (property.typeReference == null) return null
val assignments = mutableListOf<KtBinaryExpression>()
fun process(binaryExpr: KtBinaryExpression) {
if (binaryExpr.operationToken != KtTokens.EQ) return
val leftReference = when (val left = binaryExpr.left) {
is KtNameReferenceExpression ->
left
is KtDotQualifiedExpression ->
if (left.receiverExpression is KtThisExpression) left.selectorExpression as? KtNameReferenceExpression else null
else ->
null
is KtNameReferenceExpression -> left
is KtDotQualifiedExpression -> left.selectorExpression as? KtNameReferenceExpression
else -> null
} ?: return
if (leftReference.getReferencedName() != property.name) return
assignments += binaryExpr
}
propertyContainer.forEachDescendantOfType<KtBinaryExpression>(::process)
fun PsiElement?.isInvalidParent(): Boolean {
@@ -12501,6 +12501,16 @@ public abstract class K1IntentionTestGenerated extends AbstractK1IntentionTest {
runTest("testData/intentions/joinDeclarationAndAssignment/propertyReassignment.kt");
}
@TestMetadata("qualifiedName.kt")
public void testQualifiedName() throws Exception {
runTest("testData/intentions/joinDeclarationAndAssignment/qualifiedName.kt");
}
@TestMetadata("qualifiedName2.kt")
public void testQualifiedName2() throws Exception {
runTest("testData/intentions/joinDeclarationAndAssignment/qualifiedName2.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("testData/intentions/joinDeclarationAndAssignment/simple.kt");
@@ -0,0 +1,8 @@
// IS_APPLICABLE: true
object Foo {
val <caret>prop: Boolean
init {
Foo.prop = true
}
}
@@ -0,0 +1,5 @@
// IS_APPLICABLE: true
object Foo {
val prop: Boolean = true
}
@@ -0,0 +1,10 @@
// IS_APPLICABLE: true
package pack
object Foo {
val <caret>prop: Boolean
init {
pack.Foo.prop = true
}
}
@@ -0,0 +1,7 @@
// IS_APPLICABLE: true
package pack
object Foo {
val prop: Boolean = true
}