KT-9738 Code completion of "emptyList()" after elvis operator inserts explicit type arguments

#KT-9738 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-02-09 22:27:13 +03:00
parent 8da01e7952
commit c9bb020d6e
6 changed files with 50 additions and 12 deletions
@@ -0,0 +1,5 @@
fun foo(list: List<String>, b: Boolean) {
val v = if (b) list else emp<caret>
}
// ELEMENT: emptyList
@@ -0,0 +1,5 @@
fun foo(list: List<String>, b: Boolean) {
val v = if (b) list else emptyList()<caret>
}
// ELEMENT: emptyList
@@ -0,0 +1,5 @@
fun foo(list: List<String>?) {
val v = list ?: emp<caret>
}
// ELEMENT: emptyList
@@ -0,0 +1,5 @@
fun foo(list: List<String>?) {
val v = list ?: emptyList()<caret>
}
// ELEMENT: emptyList
@@ -687,6 +687,18 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class TypeArgsForCall extends AbstractBasicCompletionHandlerTest {
@TestMetadata("AfterElse.kt")
public void testAfterElse() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/typeArgsForCall/AfterElse.kt");
doTest(fileName);
}
@TestMetadata("AfterElvis.kt")
public void testAfterElvis() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/typeArgsForCall/AfterElvis.kt");
doTest(fileName);
}
public void testAllFilesPresentInTypeArgsForCall() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/handlers/basic/typeArgsForCall"), Pattern.compile("^(.+)\\.kt$"), true);
}
@@ -422,23 +422,29 @@ class ExpectedInfos(
private fun calculateForIf(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
val ifExpression = (expressionWithType.parent as? KtContainerNode)?.parent as? KtIfExpression ?: return null
return when (expressionWithType) {
ifExpression.condition -> listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, Tail.RPARENTH, additionalData = IfConditionAdditionalData))
when (expressionWithType) {
ifExpression.condition -> return listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, Tail.RPARENTH, additionalData = IfConditionAdditionalData))
ifExpression.then -> calculate(ifExpression).map { ExpectedInfo(it.filter, it.expectedName, Tail.ELSE) }
ifExpression.then -> return calculate(ifExpression).map { ExpectedInfo(it.filter, it.expectedName, Tail.ELSE) }
ifExpression.`else` -> {
val ifExpectedInfo = calculate(ifExpression)
val ifExpectedInfos = calculate(ifExpression)
val thenType = ifExpression.then?.let { bindingContext.getType(it) }
val filteredInfo = if (thenType != null && !thenType.isError)
ifExpectedInfo.filter { it.matchingSubstitutor(thenType) != null }
else
ifExpectedInfo
return filteredInfo.copyWithNoAdditionalData()
}
else -> return null
if (ifExpectedInfos.any { it.fuzzyType != null }) {
val filteredInfo = if (thenType != null && !thenType.isError)
ifExpectedInfos.filter { it.matchingSubstitutor(thenType) != null }
else
ifExpectedInfos
return filteredInfo.copyWithNoAdditionalData()
}
else if (thenType != null) {
return listOf(ExpectedInfo(thenType, null, null))
}
}
}
return null
}
private fun calculateForElvis(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
@@ -450,7 +456,7 @@ class ExpectedInfos(
val leftType = bindingContext.getType(leftExpression)
val leftTypeNotNullable = leftType?.makeNotNullable()
val expectedInfos = calculate(binaryExpression)
if (expectedInfos.isNotEmpty()) {
if (expectedInfos.any { it.fuzzyType != null }) {
val filteredInfo = if (leftTypeNotNullable != null)
expectedInfos.filter { it.matchingSubstitutor(leftTypeNotNullable) != null }
else