Move static function type utilities from KotlinBuiltIns to functionTypes.kt
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.patterns.ElementPattern
|
||||
import com.intellij.patterns.StandardPatterns
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.KotlinIcons
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.CastReceiverInsertHandler
|
||||
@@ -298,7 +299,7 @@ fun breakOrContinueExpressionItems(position: KtElement, breakOrContinue: String)
|
||||
fun BasicLookupElementFactory.createLookupElementForType(type: KotlinType): LookupElement? {
|
||||
if (type.isError) return null
|
||||
|
||||
if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)) {
|
||||
if (type.isExactFunctionOrExtensionFunctionType) {
|
||||
val text = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type)
|
||||
val baseLookupElement = LookupElementBuilder.create(text).withIcon(KotlinIcons.LAMBDA)
|
||||
return BaseTypeLookupElement(type, baseLookupElement)
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.completion
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.idea.codeInsight.ReferenceVariantsHelper
|
||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
@@ -39,7 +39,7 @@ class RealContextVariablesProvider(
|
||||
) : ContextVariablesProvider {
|
||||
|
||||
val allFunctionTypeVariables by lazy {
|
||||
collectVariables().filter { KotlinBuiltIns.isFunctionOrExtensionFunctionType(it.type) }
|
||||
collectVariables().filter { it.type.isFunctionOrExtensionFunctionType }
|
||||
}
|
||||
|
||||
private fun collectVariables(): Collection<VariableDescriptor> {
|
||||
@@ -68,4 +68,4 @@ class CollectRequiredTypesContextVariablesProvider : ContextVariablesProvider {
|
||||
_requiredTypes.add(requiredType)
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ import com.intellij.codeInsight.completion.InsertionContext
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementDecorator
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.idea.util.CallType
|
||||
@@ -45,7 +45,7 @@ class ExtensionFunctionTypeValueCompletion(
|
||||
|
||||
for (variable in variablesProvider.allFunctionTypeVariables) {
|
||||
val variableType = variable.type
|
||||
if (!KotlinBuiltIns.isExtensionFunctionType(variableType)) continue
|
||||
if (!variableType.isExtensionFunctionType) continue
|
||||
|
||||
val invokes = variableType.memberScope.getContributedFunctions(OperatorNameConventions.INVOKE, NoLookupLocation.FROM_IDE)
|
||||
for (invoke in createSynthesizedInvokes(invokes)) {
|
||||
@@ -96,4 +96,4 @@ class ExtensionFunctionTypeValueCompletion(
|
||||
|
||||
return results
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -18,7 +18,9 @@ package org.jetbrains.kotlin.idea.completion
|
||||
|
||||
import com.intellij.codeInsight.completion.InsertHandler
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.getParameterTypeProjectionsFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.*
|
||||
import org.jetbrains.kotlin.idea.core.ExpectedInfo
|
||||
@@ -51,8 +53,8 @@ class InsertHandlerProvider(
|
||||
1 -> {
|
||||
if (callType != CallType.SUPER_MEMBERS) { // for super call we don't suggest to generate "super.foo { ... }" (seems to be non-typical use)
|
||||
val parameterType = parameters.single().type
|
||||
if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(parameterType)) {
|
||||
val parameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(parameterType).size
|
||||
if (parameterType.isExactFunctionOrExtensionFunctionType) {
|
||||
val parameterCount = getParameterTypeProjectionsFromFunctionType(parameterType).size
|
||||
if (parameterCount <= 1) {
|
||||
// otherwise additional item with lambda template is to be added
|
||||
return KotlinFunctionInsertHandler.Normal(needTypeArguments, inputValueArguments = false, lambdaInfo = GenerateLambdaInfo(parameterType, false))
|
||||
@@ -96,9 +98,9 @@ class InsertHandlerProvider(
|
||||
potentiallyInferred.add(descriptor)
|
||||
}
|
||||
|
||||
if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) && KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(type).size <= 1) {
|
||||
if (type.isExactFunctionOrExtensionFunctionType && getParameterTypeProjectionsFromFunctionType(type).size <= 1) {
|
||||
// do not rely on inference from input of function type with one or no arguments - use only return type of functional type
|
||||
addPotentiallyInferred(KotlinBuiltIns.getReturnTypeFromFunctionType(type))
|
||||
addPotentiallyInferred(getReturnTypeFromFunctionType(type))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -22,7 +22,8 @@ import com.intellij.codeInsight.lookup.LookupElementDecorator
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import com.intellij.codeInsight.lookup.impl.LookupCellRenderer
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.getParameterTypeProjectionsFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.GenerateLambdaInfo
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
|
||||
@@ -67,7 +68,7 @@ class LookupElementFactory(
|
||||
companion object {
|
||||
fun hasSingleFunctionTypeParameter(descriptor: FunctionDescriptor): Boolean {
|
||||
val parameter = descriptor.original.valueParameters.singleOrNull() ?: return false
|
||||
return KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(parameter.type)
|
||||
return parameter.type.isExactFunctionOrExtensionFunctionType
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,11 +108,11 @@ class LookupElementFactory(
|
||||
val lastParameter = descriptor.valueParameters.lastOrNull() ?: return
|
||||
if (!descriptor.valueParameters.all { it == lastParameter || it.hasDefaultValue() }) return
|
||||
|
||||
if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(lastParameter.original.type)) {
|
||||
if (lastParameter.original.type.isExactFunctionOrExtensionFunctionType) {
|
||||
val isSingleParameter = descriptor.valueParameters.size == 1
|
||||
|
||||
val parameterType = lastParameter.type
|
||||
val functionParameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(parameterType).size
|
||||
val functionParameterCount = getParameterTypeProjectionsFromFunctionType(parameterType).size
|
||||
// we don't need special item inserting lambda for single functional parameter that does not need multiple arguments because the default item will be special in this case
|
||||
if (!isSingleParameter || functionParameterCount > 1) {
|
||||
add(createFunctionCallElementWithLambda(descriptor, parameterType, functionParameterCount > 1, useReceiverTypes))
|
||||
|
||||
+6
-5
@@ -25,7 +25,8 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.getParameterTypeProjectionsFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.core.ExpectedInfos
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
@@ -83,12 +84,12 @@ private fun needExplicitParameterTypes(context: InsertionContext, placeholderRan
|
||||
|
||||
val functionTypes = expectedInfos
|
||||
.mapNotNull { it.fuzzyType?.type }
|
||||
.filter { KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it) }
|
||||
.filter(KotlinType::isExactFunctionOrExtensionFunctionType)
|
||||
.toSet()
|
||||
if (functionTypes.size <= 1) return false
|
||||
|
||||
val lambdaParameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(lambdaType).size
|
||||
return functionTypes.filter { KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(it).size == lambdaParameterCount }.size > 1
|
||||
val lambdaParameterCount = getParameterTypeProjectionsFromFunctionType(lambdaType).size
|
||||
return functionTypes.filter { getParameterTypeProjectionsFromFunctionType(it).size == lambdaParameterCount }.size > 1
|
||||
}
|
||||
|
||||
private fun buildTemplate(lambdaType: KotlinType, explicitParameterTypes: Boolean, project: Project): Template {
|
||||
@@ -128,4 +129,4 @@ private class ParameterNameExpression(val nameSuggestions: Array<String>) : Expr
|
||||
}
|
||||
|
||||
fun functionParameterTypes(functionType: KotlinType): List<KotlinType>
|
||||
= KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(functionType).map { it.type }
|
||||
= getParameterTypeProjectionsFromFunctionType(functionType).map { it.type }
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.completion.smart
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.getParameterTypeProjectionsFromFunctionType
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.insertLambdaTemplate
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.lambdaPresentation
|
||||
import org.jetbrains.kotlin.idea.completion.suppressAutoInsertion
|
||||
@@ -43,7 +43,7 @@ object LambdaItems {
|
||||
.toSet()
|
||||
|
||||
val singleType = if (distinctTypes.size == 1) distinctTypes.single() else null
|
||||
val singleSignatureLength = singleType?.let { KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(it).size }
|
||||
val singleSignatureLength = singleType?.let { getParameterTypeProjectionsFromFunctionType(it).size }
|
||||
val offerNoParametersLambda = singleSignatureLength == 0 || singleSignatureLength == 1
|
||||
if (offerNoParametersLambda) {
|
||||
val lookupElement = LookupElementBuilder.create(lambdaPresentation(null))
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
@@ -80,7 +81,7 @@ class TypeInstantiationItems(
|
||||
fuzzyType: FuzzyType,
|
||||
tail: Tail?
|
||||
) {
|
||||
if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(fuzzyType.type)) return // do not show "object: ..." for function types
|
||||
if (fuzzyType.type.isExactFunctionOrExtensionFunctionType) return // do not show "object: ..." for function types
|
||||
|
||||
val classifier = fuzzyType.type.constructor.declarationDescriptor
|
||||
if (classifier !is ClassDescriptor) return
|
||||
|
||||
@@ -22,8 +22,8 @@ import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementDecorator
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.WithExpressionPrefixInsertHandler
|
||||
@@ -308,8 +308,7 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion(
|
||||
}
|
||||
|
||||
fun Collection<ExpectedInfo>.filterFunctionExpected()
|
||||
= filter { it.fuzzyType != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it.fuzzyType!!.type) }
|
||||
= filter { it.fuzzyType != null && it.fuzzyType!!.type.isExactFunctionOrExtensionFunctionType }
|
||||
|
||||
fun Collection<ExpectedInfo>.filterCallableExpected()
|
||||
= filter { it.fuzzyType != null && ReflectionTypes.isCallableType(it.fuzzyType!!.type) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user