Added better way to construct FuzzyType
This commit is contained in:
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.idea.core.WhenEntryAdditionalData
|
||||
import org.jetbrains.kotlin.idea.core.fuzzyType
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.toFuzzyType
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
||||
@@ -98,7 +98,7 @@ object KeywordValues {
|
||||
if (qualifierType != null) {
|
||||
val kClassDescriptor = resolutionFacade.getFrontendService(ReflectionTypes::class.java).kClass
|
||||
val classLiteralType = KotlinTypeImpl.create(Annotations.EMPTY, kClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val kClassTypes = listOf(FuzzyType(classLiteralType, emptyList()))
|
||||
val kClassTypes = listOf(classLiteralType.toFuzzyType(emptyList()))
|
||||
val kClassMatcher = { info: ExpectedInfo -> kClassTypes.matchExpectedInfo(info) }
|
||||
consumer.consume("class", kClassMatcher, SmartCompletionItemPriority.CLASS_LITERAL) {
|
||||
LookupElementBuilder.create(KeywordLookupObject(), "class").bold()
|
||||
@@ -110,7 +110,7 @@ object KeywordValues {
|
||||
|
||||
if (javaLangClassDescriptor != null) {
|
||||
val javaLangClassType = KotlinTypeImpl.create(Annotations.EMPTY, javaLangClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val javaClassTypes = listOf(FuzzyType(javaLangClassType, emptyList()))
|
||||
val javaClassTypes = listOf(javaLangClassType.toFuzzyType(emptyList()))
|
||||
val javaClassMatcher = { info: ExpectedInfo -> javaClassTypes.matchExpectedInfo(info) }
|
||||
consumer.consume("class", javaClassMatcher, SmartCompletionItemPriority.CLASS_LITERAL) {
|
||||
LookupElementBuilder.create(KeywordLookupObject(), "class.java")
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.idea.completion.handlers.GenerateLambdaInfo
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.lambdaPresentation
|
||||
import org.jetbrains.kotlin.idea.util.CallType
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.toFuzzyType
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
@@ -121,7 +121,7 @@ class LookupElementFactory(
|
||||
if (isSingleParameter) {
|
||||
//TODO: also ::function? at least for local functions
|
||||
//TODO: order for them
|
||||
val fuzzyParameterType = FuzzyType(parameterType, descriptor.typeParameters)
|
||||
val fuzzyParameterType = parameterType.toFuzzyType(descriptor.typeParameters)
|
||||
for ((variable, substitutor) in contextVariablesProvider.functionTypeVariables(fuzzyParameterType)) {
|
||||
val substitutedDescriptor = descriptor.substitute(substitutor)
|
||||
add(createFunctionCallElementWithArguments(substitutedDescriptor, variable.name.render(), useReceiverTypes))
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.core.completion.PackageLookupObject
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.CallType
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.toFuzzyType
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.resolve.findOriginalTopMostOverriddenDescriptors
|
||||
|
||||
@@ -231,7 +232,7 @@ class SmartCompletionInBasicWeigher(
|
||||
descriptor.fuzzyTypesForSmartCompletion(smartCastCalculator, callType, resolutionFacade) to descriptor.name
|
||||
}
|
||||
|
||||
is ThisItemLookupObject -> smartCastCalculator.types(o.receiverParameter).map { FuzzyType(it, emptyList()) } to null
|
||||
is ThisItemLookupObject -> smartCastCalculator.types(o.receiverParameter).map { it.toFuzzyType(emptyList()) } to null
|
||||
|
||||
else -> return NO_MATCH_WEIGHT
|
||||
}
|
||||
|
||||
+2
-1
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.isAlmostEverything
|
||||
import org.jetbrains.kotlin.idea.util.toFuzzyType
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -277,7 +278,7 @@ class SmartCompletion(
|
||||
if (shouldCompleteThisItems(prefixMatcher)) {
|
||||
val items = thisExpressionItems(bindingContext, place, prefixMatcher.prefix, resolutionFacade)
|
||||
for (item in items) {
|
||||
val types = smartCastCalculator.types(item.receiverParameter).map { FuzzyType(it, emptyList()) }
|
||||
val types = smartCastCalculator.types(item.receiverParameter).map { it.toFuzzyType(emptyList()) }
|
||||
val matcher = { expectedInfo: ExpectedInfo -> types.matchExpectedInfo(expectedInfo) }
|
||||
addLookupElements(null, expectedInfos, matcher) {
|
||||
item.createLookupElement().assignSmartCompletionPriority(SmartCompletionItemPriority.THIS).singletonList()
|
||||
|
||||
+4
-7
@@ -38,10 +38,7 @@ import org.jetbrains.kotlin.idea.core.Tail
|
||||
import org.jetbrains.kotlin.idea.core.multipleFuzzyTypes
|
||||
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMembersHandler
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.makeNotNullable
|
||||
import org.jetbrains.kotlin.idea.util.presentationType
|
||||
import org.jetbrains.kotlin.idea.util.*
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
@@ -316,7 +313,7 @@ class TypeInstantiationItems(
|
||||
|
||||
private val baseHasTypeArgs = classDescriptor.declaredTypeParameters.isNotEmpty()
|
||||
private val expectedType = KotlinTypeImpl.create(Annotations.EMPTY, classDescriptor, false, typeArgs)
|
||||
private val expectedFuzzyType = FuzzyType(expectedType, freeParameters)
|
||||
private val expectedFuzzyType = expectedType.toFuzzyType(freeParameters)
|
||||
|
||||
override fun search(nameFilter: (String) -> Boolean, consumer: (LookupElement) -> Unit) {
|
||||
val parameters = ClassInheritorsSearch.SearchParameters(psiClass, inheritorSearchScope, true, true, false, nameFilter)
|
||||
@@ -327,13 +324,13 @@ class TypeInstantiationItems(
|
||||
) ?: continue
|
||||
if (!visibilityFilter(descriptor)) continue
|
||||
|
||||
var inheritorFuzzyType = FuzzyType(descriptor.defaultType, descriptor.typeConstructor.parameters)
|
||||
var inheritorFuzzyType = descriptor.defaultType.toFuzzyType(descriptor.typeConstructor.parameters)
|
||||
val hasTypeArgs = descriptor.declaredTypeParameters.isNotEmpty()
|
||||
if (hasTypeArgs || baseHasTypeArgs) {
|
||||
val substitutor = inheritorFuzzyType.checkIsSubtypeOf(expectedFuzzyType) ?: continue
|
||||
if (!substitutor.isEmpty) {
|
||||
val inheritorTypeSubstituted = substitutor.substitute(inheritorFuzzyType.type, Variance.INVARIANT)!!
|
||||
inheritorFuzzyType = FuzzyType(inheritorTypeSubstituted, freeParameters + inheritorFuzzyType.freeParameters)
|
||||
inheritorFuzzyType = inheritorTypeSubstituted.toFuzzyType(freeParameters + inheritorFuzzyType.freeParameters)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,8 +248,7 @@ private fun MutableCollection<LookupElement>.addLookupElementsForNullable(factor
|
||||
|
||||
fun CallableDescriptor.callableReferenceType(resolutionFacade: ResolutionFacade): FuzzyType? {
|
||||
if (!CallType.CALLABLE_REFERENCE.descriptorKindFilter.accepts(this)) return null // not supported by callable references
|
||||
val type = getReflectionTypeForCandidateDescriptor(this, resolutionFacade.getFrontendService(ReflectionTypes::class.java)) ?: return null
|
||||
return FuzzyType(type, emptyList())
|
||||
return getReflectionTypeForCandidateDescriptor(this, resolutionFacade.getFrontendService(ReflectionTypes::class.java))?.toFuzzyType(emptyList())
|
||||
}
|
||||
|
||||
enum class SmartCompletionItemPriority {
|
||||
@@ -294,14 +293,14 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion(
|
||||
if (returnType.type.isNothing() || returnType.isAlmostEverything()) return emptyList()
|
||||
|
||||
if (this is VariableDescriptor) { //TODO: generic properties!
|
||||
return smartCastCalculator.types(this).map { FuzzyType(it, emptyList()) }
|
||||
return smartCastCalculator.types(this).map { it.toFuzzyType(emptyList()) }
|
||||
}
|
||||
else {
|
||||
return listOf(returnType)
|
||||
}
|
||||
}
|
||||
else if (this is ClassDescriptor && kind.isSingleton) {
|
||||
return listOf(FuzzyType(defaultType, emptyList()))
|
||||
return listOf(defaultType.toFuzzyType(emptyList()))
|
||||
}
|
||||
else {
|
||||
return emptyList()
|
||||
|
||||
Reference in New Issue
Block a user