PSI Unifier: Fix matching of this-expressions

#KT-8293 Fixed
This commit is contained in:
Alexey Sedunov
2016-01-12 17:18:53 +03:00
parent ed8674c0f9
commit 1d9bafe196
7 changed files with 51 additions and 0 deletions
@@ -365,6 +365,7 @@ class KotlinPsiUnifier(
else -> false
}
this is KtBinaryExpression -> operationReference.getReferencedNameElementType() == KtTokens.ELVIS
this is KtThisExpression -> true
else -> false
}
}
@@ -423,6 +424,12 @@ class KotlinPsiUnifier(
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 {
val entries1 = e1.entries
val entries2 = e2.entries
@@ -694,6 +701,8 @@ class KotlinPsiUnifier(
e1 is KtCallableReferenceExpression && e2 is KtCallableReferenceExpression ->
if (matchCallableReferences(e1, e2)) MATCHED else UNMATCHED
e1 is KtThisExpression && e2 is KtThisExpression -> if (matchThisExpressions(e1, e2)) MATCHED else UNMATCHED
else ->
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
@@ -379,6 +379,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
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")
public void testThisReference() throws Exception {
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");
doTest(fileName);
}
@TestMetadata("thisAsCallee.kt")
public void testThisAsCallee() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/this/thisAsCallee.kt");
doTest(fileName);
}
}
}