Partial body resolve: correct handing of this qualifier

This commit is contained in:
Valentin Kipyatkov
2014-11-18 16:45:00 +03:00
parent 78e26c0cf9
commit e7ba59b209
4 changed files with 23 additions and 2 deletions
@@ -316,14 +316,15 @@ class PartialBodyResolveFilter(elementToResolve: JetElement, private val body: J
private fun PsiElement.isStatement() = this is JetExpression && getParent() is JetBlockExpression
//TODO: this.a
private fun JetExpression.smartCastedExpressionName(): String? {
return when (this) {
is JetSimpleNameExpression -> this.getReferencedName()
is JetQualifiedExpression -> {
val selectorName = getSelectorExpression().smartCastedExpressionName() ?: return null
val receiverName = getReceiverExpression().smartCastedExpressionName() ?: return null
val receiver = getReceiverExpression()
if (receiver is JetThisExpression) return selectorName
val receiverName = receiver.smartCastedExpressionName() ?: return null
return selectorName + "." + receiverName
}
@@ -0,0 +1,2 @@
Resolve target: val s: kotlin.String? smart-casted to kotlin.String
Skipped statements:
@@ -0,0 +1,12 @@
class C(val s: String?) {
fun foo(p: Boolean) {
if (p) {
print(s!!)
}
else {
print(this.s!!)
}
<caret>s.size
}
}
@@ -210,6 +210,12 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
doTest(fileName);
}
@TestMetadata("ThisQualifiedAutoCast.kt")
public void testThisQualifiedAutoCast() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/ThisQualifiedAutoCast.kt");
doTest(fileName);
}
@TestMetadata("While.kt")
public void testWhile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/While.kt");