Smart completion works for block's result

This commit is contained in:
Valentin Kipyatkov
2014-04-30 20:45:26 +04:00
parent 45f518a907
commit 1b034c5fc3
7 changed files with 75 additions and 0 deletions
@@ -50,6 +50,7 @@ import org.jetbrains.jet.lang.resolve.calls.util.DelegatingCall
import org.jetbrains.jet.lang.resolve.calls.util.noErrorsInValueArguments
import org.jetbrains.jet.lang.resolve.calls.util.hasUnmappedParameters
import org.jetbrains.jet.lang.descriptors.Visibilities
import org.jetbrains.jet.lang.psi.JetBlockExpression
enum class Tail {
COMMA
@@ -66,6 +67,7 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo
?: calculateForEq(expressionWithType)
?: calculateForIf(expressionWithType)
?: calculateForElvis(expressionWithType)
?: calculateForBlockExpression(expressionWithType)
?: getFromBindingContext(expressionWithType)
}
@@ -208,6 +210,12 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo
return null
}
private fun calculateForBlockExpression(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
val block = expressionWithType.getParent() as? JetBlockExpression ?: return null
if (expressionWithType != block.getStatements().last()) return null
return calculate(block)?.map { ExpectedInfo(it.`type`, null) }
}
private fun getFromBindingContext(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
val expectedType = bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, expressionWithType] ?: return null
return listOf(ExpectedInfo(expectedType, null))
@@ -0,0 +1,12 @@
fun foo(s: String, i: Int){}
fun bar(b: Boolean, s: String){
foo(if (b)
"abc"
else {
println()
<caret>
})
}
// ELEMENT: s
@@ -0,0 +1,12 @@
fun foo(s: String, i: Int){}
fun bar(b: Boolean, s: String){
foo(if (b)
"abc"
else {
println()
s<caret>
})
}
// ELEMENT: s
@@ -0,0 +1,13 @@
fun foo(s: String){}
fun foo(c: Char){}
fun bar(b: Boolean, s: String, c: Char){
foo(if (b) {
println()
<caret>
})
}
// EXIST: s
// EXIST: c
// ABSENT: b
@@ -0,0 +1,15 @@
fun foo(s: String){}
fun foo(c: Char){}
fun bar(b: Boolean, s: String, c: Char){
foo(if (b)
"abc"
else {
println()
<caret>
})
}
// EXIST: s
// ABSENT: c
// ABSENT: b
@@ -216,6 +216,16 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
doTest("idea/testData/completion/smart/IfValue3.kt");
}
@TestMetadata("IfValueInBlock1.kt")
public void testIfValueInBlock1() throws Exception {
doTest("idea/testData/completion/smart/IfValueInBlock1.kt");
}
@TestMetadata("IfValueInBlock2.kt")
public void testIfValueInBlock2() throws Exception {
doTest("idea/testData/completion/smart/IfValueInBlock2.kt");
}
@TestMetadata("InElvisOperator1.kt")
public void testInElvisOperator1() throws Exception {
doTest("idea/testData/completion/smart/InElvisOperator1.kt");
@@ -226,6 +226,11 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion
doTest("idea/testData/completion/handlers/smart/IfValue3.kt");
}
@TestMetadata("IfValueInBlock.kt")
public void testIfValueInBlock() throws Exception {
doTest("idea/testData/completion/handlers/smart/IfValueInBlock.kt");
}
@TestMetadata("InElvisOperator.kt")
public void testInElvisOperator() throws Exception {
doTest("idea/testData/completion/handlers/smart/InElvisOperator.kt");