Fix completion for codeFragments on functions with expression body

This commit is contained in:
Natalia Ukhorskaya
2015-07-20 16:37:36 +03:00
parent 86c7d11750
commit 2121f707ab
6 changed files with 29 additions and 19 deletions
@@ -30,27 +30,16 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
//TODO: this code should be moved into debugger which should set correct context for its code fragment
private fun JetExpression.correctContextForExpression(): JetExpression {
when (this) {
is JetBlockExpression -> {
return this.getStatements().lastOrNull() ?: this
}
is JetFunctionLiteral -> {
return this.getBodyExpression()?.getStatements()?.lastOrNull() ?: this
}
return when (this) {
is JetProperty -> this.getDelegateExpressionOrInitializer()
is JetFunctionLiteral -> this.getBodyExpression()?.getStatements()?.lastOrNull()
is JetDeclarationWithBody -> this.getBodyExpression()
is JetBlockExpression -> this.getStatements().lastOrNull()
else -> {
val previousExpression = this.siblings(forward = false, withItself = false).firstIsInstanceOrNull<JetExpression>()
if (previousExpression is JetExpression) {
return previousExpression
}
else {
val parentExpression = this.parents.firstIsInstanceOrNull<JetExpression>()
if (parentExpression is JetExpression) {
return parentExpression
}
}
this.siblings(forward = false, withItself = false).firstIsInstanceOrNull<JetExpression>()
?: this.parents.firstIsInstanceOrNull<JetExpression>()
}
}
return this
} ?: this
}
public fun JetCodeFragment.getScopeAndDataFlowForAnalyzeFragment(
@@ -0,0 +1 @@
<caret>fun foo(aaaB: Int) = aaaB
@@ -0,0 +1 @@
aaaB
@@ -0,0 +1,6 @@
package withoutBodyProperties
class A {
val aaaB = 1
<caret>val aaaC = 1
}
@@ -0,0 +1 @@
aaaB + aaaC
@@ -132,6 +132,18 @@ public class CodeFragmentHighlightingTestGenerated extends AbstractCodeFragmentH
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/smartCasts.kt");
doTest(fileName);
}
@TestMetadata("withoutBodyFunction.kt")
public void testWithoutBodyFunction() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/withoutBodyFunction.kt");
doTest(fileName);
}
@TestMetadata("withoutBodyProperty.kt")
public void testWithoutBodyProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/withoutBodyProperty.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/checker/codeFragments/imports")