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 //TODO: this code should be moved into debugger which should set correct context for its code fragment
private fun JetExpression.correctContextForExpression(): JetExpression { private fun JetExpression.correctContextForExpression(): JetExpression {
when (this) { return when (this) {
is JetBlockExpression -> { is JetProperty -> this.getDelegateExpressionOrInitializer()
return this.getStatements().lastOrNull() ?: this is JetFunctionLiteral -> this.getBodyExpression()?.getStatements()?.lastOrNull()
} is JetDeclarationWithBody -> this.getBodyExpression()
is JetFunctionLiteral -> { is JetBlockExpression -> this.getStatements().lastOrNull()
return this.getBodyExpression()?.getStatements()?.lastOrNull() ?: this
}
else -> { else -> {
val previousExpression = this.siblings(forward = false, withItself = false).firstIsInstanceOrNull<JetExpression>() this.siblings(forward = false, withItself = false).firstIsInstanceOrNull<JetExpression>()
if (previousExpression is JetExpression) { ?: this.parents.firstIsInstanceOrNull<JetExpression>()
return previousExpression
}
else {
val parentExpression = this.parents.firstIsInstanceOrNull<JetExpression>()
if (parentExpression is JetExpression) {
return parentExpression
}
}
} }
} } ?: this
return this
} }
public fun JetCodeFragment.getScopeAndDataFlowForAnalyzeFragment( 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"); String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/smartCasts.kt");
doTest(fileName); 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") @TestMetadata("idea/testData/checker/codeFragments/imports")