PSI Unifier: Fix matching of this-expressions
#KT-8293 Fixed
This commit is contained in:
+9
@@ -365,6 +365,7 @@ class KotlinPsiUnifier(
|
|||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
this is KtBinaryExpression -> operationReference.getReferencedNameElementType() == KtTokens.ELVIS
|
this is KtBinaryExpression -> operationReference.getReferencedNameElementType() == KtTokens.ELVIS
|
||||||
|
this is KtThisExpression -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,6 +424,12 @@ class KotlinPsiUnifier(
|
|||||||
return matchDescriptors(d1, d2)
|
return matchDescriptors(d1, d2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun matchThisExpressions(e1: KtThisExpression, e2: KtThisExpression): Boolean {
|
||||||
|
val d1 = e1.bindingContext[BindingContext.REFERENCE_TARGET, e1.instanceReference]
|
||||||
|
val d2 = e2.bindingContext[BindingContext.REFERENCE_TARGET, e2.instanceReference]
|
||||||
|
return matchDescriptors(d1, d2)
|
||||||
|
}
|
||||||
|
|
||||||
private fun matchDestructuringDeclarations(e1: KtDestructuringDeclaration, e2: KtDestructuringDeclaration): Boolean {
|
private fun matchDestructuringDeclarations(e1: KtDestructuringDeclaration, e2: KtDestructuringDeclaration): Boolean {
|
||||||
val entries1 = e1.entries
|
val entries1 = e1.entries
|
||||||
val entries2 = e2.entries
|
val entries2 = e2.entries
|
||||||
@@ -694,6 +701,8 @@ class KotlinPsiUnifier(
|
|||||||
e1 is KtCallableReferenceExpression && e2 is KtCallableReferenceExpression ->
|
e1 is KtCallableReferenceExpression && e2 is KtCallableReferenceExpression ->
|
||||||
if (matchCallableReferences(e1, e2)) MATCHED else UNMATCHED
|
if (matchCallableReferences(e1, e2)) MATCHED else UNMATCHED
|
||||||
|
|
||||||
|
e1 is KtThisExpression && e2 is KtThisExpression -> if (matchThisExpressions(e1, e2)) MATCHED else UNMATCHED
|
||||||
|
|
||||||
else ->
|
else ->
|
||||||
matchCalls(e1, e2)
|
matchCalls(e1, e2)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun (String.() -> String).foo(x : String) {
|
||||||
|
x.<selection>this</selection>()
|
||||||
|
x.this@foo()
|
||||||
|
val t = this
|
||||||
|
val tt = this@foo
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun (String.() -> String).foo(x : String) {
|
||||||
|
val function = this
|
||||||
|
x.function()
|
||||||
|
x.function()
|
||||||
|
val t = function
|
||||||
|
val tt = function
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// DISABLE-ERRORS
|
||||||
|
fun (String.() -> String).foo(x : String) {
|
||||||
|
x.<selection>this</selection>()
|
||||||
|
x.this()
|
||||||
|
x.this(1)
|
||||||
|
x.this@foo()
|
||||||
|
x.this@foo(2)
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
this
|
||||||
|
|
||||||
|
this
|
||||||
|
|
||||||
|
this
|
||||||
|
|
||||||
|
this@foo
|
||||||
|
|
||||||
|
this@foo
|
||||||
+6
@@ -379,6 +379,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
|||||||
doIntroduceVariableTest(fileName);
|
doIntroduceVariableTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("thisAsCallee.kt")
|
||||||
|
public void testThisAsCallee() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/thisAsCallee.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ThisReference.kt")
|
@TestMetadata("ThisReference.kt")
|
||||||
public void testThisReference() throws Exception {
|
public void testThisReference() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/ThisReference.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/ThisReference.kt");
|
||||||
|
|||||||
@@ -715,6 +715,12 @@ public class PsiUnifierTestGenerated extends AbstractPsiUnifierTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/this/simpleThis2Runtime.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/this/simpleThis2Runtime.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("thisAsCallee.kt")
|
||||||
|
public void testThisAsCallee() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/this/thisAsCallee.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user