Smart completion works for block's result
This commit is contained in:
@@ -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.noErrorsInValueArguments
|
||||||
import org.jetbrains.jet.lang.resolve.calls.util.hasUnmappedParameters
|
import org.jetbrains.jet.lang.resolve.calls.util.hasUnmappedParameters
|
||||||
import org.jetbrains.jet.lang.descriptors.Visibilities
|
import org.jetbrains.jet.lang.descriptors.Visibilities
|
||||||
|
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||||
|
|
||||||
enum class Tail {
|
enum class Tail {
|
||||||
COMMA
|
COMMA
|
||||||
@@ -66,6 +67,7 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo
|
|||||||
?: calculateForEq(expressionWithType)
|
?: calculateForEq(expressionWithType)
|
||||||
?: calculateForIf(expressionWithType)
|
?: calculateForIf(expressionWithType)
|
||||||
?: calculateForElvis(expressionWithType)
|
?: calculateForElvis(expressionWithType)
|
||||||
|
?: calculateForBlockExpression(expressionWithType)
|
||||||
?: getFromBindingContext(expressionWithType)
|
?: getFromBindingContext(expressionWithType)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +210,12 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo
|
|||||||
return null
|
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>? {
|
private fun getFromBindingContext(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||||
val expectedType = bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, expressionWithType] ?: return null
|
val expectedType = bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, expressionWithType] ?: return null
|
||||||
return listOf(ExpectedInfo(expectedType, 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");
|
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")
|
@TestMetadata("InElvisOperator1.kt")
|
||||||
public void testInElvisOperator1() throws Exception {
|
public void testInElvisOperator1() throws Exception {
|
||||||
doTest("idea/testData/completion/smart/InElvisOperator1.kt");
|
doTest("idea/testData/completion/smart/InElvisOperator1.kt");
|
||||||
|
|||||||
+5
@@ -226,6 +226,11 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion
|
|||||||
doTest("idea/testData/completion/handlers/smart/IfValue3.kt");
|
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")
|
@TestMetadata("InElvisOperator.kt")
|
||||||
public void testInElvisOperator() throws Exception {
|
public void testInElvisOperator() throws Exception {
|
||||||
doTest("idea/testData/completion/handlers/smart/InElvisOperator.kt");
|
doTest("idea/testData/completion/handlers/smart/InElvisOperator.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user