Join declaration & assignment: treat assignment with this. correctly #KT-16000 Fixed
This commit is contained in:
+9
-1
@@ -104,7 +104,15 @@ class JoinDeclarationAndAssignmentIntention : SelfTargetingOffsetIndependentInte
|
||||
val assignments = mutableListOf<KtBinaryExpression>()
|
||||
fun process(binaryExpr: KtBinaryExpression) {
|
||||
if (binaryExpr.operationToken != KtTokens.EQ) return
|
||||
val leftReference = binaryExpr.left as? KtNameReferenceExpression ?: return
|
||||
val left = binaryExpr.left
|
||||
val leftReference = when (left) {
|
||||
is KtNameReferenceExpression ->
|
||||
left
|
||||
is KtDotQualifiedExpression ->
|
||||
if (left.receiverExpression is KtThisExpression) left.selectorExpression as? KtNameReferenceExpression else null
|
||||
else ->
|
||||
null
|
||||
} ?: return
|
||||
if (leftReference.getReferencedName() != property.name) return
|
||||
assignments += binaryExpr
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
class My {
|
||||
val x: Int<caret>
|
||||
|
||||
constructor(x: Int) {
|
||||
this.x = x
|
||||
}
|
||||
|
||||
constructor() {
|
||||
x = 42
|
||||
}
|
||||
}
|
||||
@@ -8916,6 +8916,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multipleConstructorsWithThis.kt")
|
||||
public void testMultipleConstructorsWithThis() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/joinDeclarationAndAssignment/multipleConstructorsWithThis.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyReassignment.kt")
|
||||
public void testPropertyReassignment() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/joinDeclarationAndAssignment/propertyReassignment.kt");
|
||||
|
||||
Reference in New Issue
Block a user