Code refactoring
This commit is contained in:
@@ -128,21 +128,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
|
||||
val result = ArrayList<LookupElement>()
|
||||
val types = descriptor.fuzzyTypes(smartCastTypes)
|
||||
val classifier = { (expectedInfo: ExpectedInfo) ->
|
||||
val substitutor = types.stream().map { it.checkIsSubtypeOf(expectedInfo.type) }.firstOrNull()
|
||||
if (substitutor != null) {
|
||||
ExpectedInfoClassification.matches(substitutor)
|
||||
}
|
||||
else {
|
||||
val substitutor2 = types.stream().map { it.makeNotNullable().checkIsSubtypeOf(expectedInfo.type) }.firstOrNull()
|
||||
if (substitutor2 != null) {
|
||||
ExpectedInfoClassification.matchesIfNotNullable(substitutor2)
|
||||
}
|
||||
else {
|
||||
ExpectedInfoClassification.notMatches
|
||||
}
|
||||
}
|
||||
}
|
||||
val classifier = { (expectedInfo: ExpectedInfo) -> types.classifyExpectedInfo(expectedInfo) }
|
||||
result.addLookupElements(descriptor, expectedInfos, classifier) { descriptor ->
|
||||
lookupElementFactory.createLookupElement(descriptor, resolutionFacade, bindingContext, true)
|
||||
}
|
||||
|
||||
@@ -110,14 +110,15 @@ class ExpectedInfoClassification private(val substitutor: TypeSubstitutor?, val
|
||||
}
|
||||
}
|
||||
|
||||
fun FuzzyType.classifyExpectedInfo(expectedInfo: ExpectedInfo): ExpectedInfoClassification {
|
||||
val substitutor = checkIsSubtypeOf(expectedInfo.type)
|
||||
fun Collection<FuzzyType>.classifyExpectedInfo(expectedInfo: ExpectedInfo): ExpectedInfoClassification {
|
||||
val stream = stream()
|
||||
val substitutor = stream.map { it.checkIsSubtypeOf(expectedInfo.type) }.firstOrNull()
|
||||
if (substitutor != null) {
|
||||
return ExpectedInfoClassification.matches(substitutor)
|
||||
}
|
||||
|
||||
if (isNullable()) {
|
||||
val substitutor2 = makeNotNullable().checkIsSubtypeOf(expectedInfo.type)
|
||||
if (stream.any { it.isNullable() }) {
|
||||
val substitutor2 = stream.map { it.makeNotNullable().checkIsSubtypeOf(expectedInfo.type) }.firstOrNull()
|
||||
if (substitutor2 != null) {
|
||||
return ExpectedInfoClassification.matchesIfNotNullable(substitutor2)
|
||||
}
|
||||
@@ -126,6 +127,8 @@ fun FuzzyType.classifyExpectedInfo(expectedInfo: ExpectedInfo): ExpectedInfoClas
|
||||
return ExpectedInfoClassification.notMatches
|
||||
}
|
||||
|
||||
fun FuzzyType.classifyExpectedInfo(expectedInfo: ExpectedInfo) = listOf(this).classifyExpectedInfo(expectedInfo)
|
||||
|
||||
fun<TDescriptor: DeclarationDescriptor?> MutableCollection<LookupElement>.addLookupElements(
|
||||
descriptor: TDescriptor,
|
||||
expectedInfos: Collection<ExpectedInfo>,
|
||||
|
||||
Reference in New Issue
Block a user