Fixed KT-5168 Smart completion includes null when comparing non-nullable value

#KT-5168 Fixed
This commit is contained in:
Valentin Kipyatkov
2014-07-22 18:24:34 +04:00
parent 81393c999b
commit 595ef9f1d4
3 changed files with 14 additions and 5 deletions
@@ -170,7 +170,7 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo
val otherOperand = if (expressionWithType == binaryExpression.getRight()) binaryExpression.getLeft() else binaryExpression.getRight()
if (otherOperand != null) {
val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, otherOperand] ?: return null
return listOf(ExpectedInfo(expressionType.makeNullable(), null))
return listOf(ExpectedInfo(expressionType, null))
}
}
}
@@ -28,6 +28,7 @@ import java.util.*
import org.jetbrains.jet.plugin.completion.*
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.plugin.util.makeNotNullable
import org.jetbrains.jet.plugin.util.makeNullable
class SmartCompletion(val expression: JetSimpleNameExpression,
val resolveSession: ResolveSessionForBodies,
@@ -73,8 +74,14 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
}
val allExpectedInfos = ExpectedInfos(bindingContext, moduleDescriptor).calculate(expressionWithType) ?: return null
val expectedInfos = allExpectedInfos.filter { !it.`type`.isError() }
if (expectedInfos.isEmpty()) return null
val filteredExpectedInfos = allExpectedInfos.filter { !it.`type`.isError() }
if (filteredExpectedInfos.isEmpty()) return null
// if we complete argument of == or !=, make types in expected info's nullable to allow nullable items too
val expectedInfos = if ((expressionWithType.getParent() as? JetBinaryExpression)?.getOperationToken() in setOf(JetTokens.EQEQ, JetTokens.EXCLEQ))
filteredExpectedInfos.map { ExpectedInfo(it.`type`.makeNullable(), it.tail) }
else
filteredExpectedInfos
val result = ArrayList<LookupElement>()
@@ -112,7 +119,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
LambdaItems.addToCollection(result, functionExpectedInfos)
KeywordValues.addToCollection(result, expectedInfos, expressionWithType)
KeywordValues.addToCollection(result, filteredExpectedInfos/* use filteredExpectedInfos to not include null after == */, expressionWithType)
}
return result
+3 -1
View File
@@ -9,6 +9,8 @@ fun f(e1: E, e2: E?, x: Any) {
// EXIST: E.A
// EXIST: E.B
// EXIST: e2
// EXIST: { itemText:"e2" }
// ABSENT: { itemText:"!! e2" }
// ABSENT: e1
// ABSENT: x
// ABSENT: null