KT-9738 Code completion of "emptyList()" after elvis operator inserts explicit type arguments
#KT-9738 Fixed
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(list: List<String>, b: Boolean) {
|
||||||
|
val v = if (b) list else emp<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: emptyList
|
||||||
+5
@@ -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
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(list: List<String>?) {
|
||||||
|
val v = list ?: emptyList()<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: emptyList
|
||||||
+12
@@ -687,6 +687,18 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
|
|||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class TypeArgsForCall extends AbstractBasicCompletionHandlerTest {
|
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 {
|
public void testAllFilesPresentInTypeArgsForCall() throws Exception {
|
||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/handlers/basic/typeArgsForCall"), Pattern.compile("^(.+)\\.kt$"), true);
|
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>? {
|
private fun calculateForIf(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||||
val ifExpression = (expressionWithType.parent as? KtContainerNode)?.parent as? KtIfExpression ?: return null
|
val ifExpression = (expressionWithType.parent as? KtContainerNode)?.parent as? KtIfExpression ?: return null
|
||||||
return when (expressionWithType) {
|
when (expressionWithType) {
|
||||||
ifExpression.condition -> listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, Tail.RPARENTH, additionalData = IfConditionAdditionalData))
|
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` -> {
|
ifExpression.`else` -> {
|
||||||
val ifExpectedInfo = calculate(ifExpression)
|
val ifExpectedInfos = calculate(ifExpression)
|
||||||
val thenType = ifExpression.then?.let { bindingContext.getType(it) }
|
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>? {
|
private fun calculateForElvis(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||||
@@ -450,7 +456,7 @@ class ExpectedInfos(
|
|||||||
val leftType = bindingContext.getType(leftExpression)
|
val leftType = bindingContext.getType(leftExpression)
|
||||||
val leftTypeNotNullable = leftType?.makeNotNullable()
|
val leftTypeNotNullable = leftType?.makeNotNullable()
|
||||||
val expectedInfos = calculate(binaryExpression)
|
val expectedInfos = calculate(binaryExpression)
|
||||||
if (expectedInfos.isNotEmpty()) {
|
if (expectedInfos.any { it.fuzzyType != null }) {
|
||||||
val filteredInfo = if (leftTypeNotNullable != null)
|
val filteredInfo = if (leftTypeNotNullable != null)
|
||||||
expectedInfos.filter { it.matchingSubstitutor(leftTypeNotNullable) != null }
|
expectedInfos.filter { it.matchingSubstitutor(leftTypeNotNullable) != null }
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user