diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index 58d8c8bbd68..5c68f8f2440 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -444,7 +444,7 @@ public class BodyResolver { if (classDescriptor != null) { if (ErrorUtils.isError(classDescriptor)) continue; - if (FunctionTypesKt.isExactExtensionFunctionType(supertype)) { + if (FunctionTypesKt.isExtensionFunctionType(supertype)) { trace.report(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE.on(typeReference)); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index f94f9996bbf..30b93712402 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -612,7 +612,7 @@ public class DescriptorResolver { if (DynamicTypesKt.isDynamic(upperBoundType)) { trace.report(DYNAMIC_UPPER_BOUND.on(upperBound)); } - if (FunctionTypesKt.isExactExtensionFunctionType(upperBoundType)) { + if (FunctionTypesKt.isExtensionFunctionType(upperBoundType)) { trace.report(UPPER_BOUND_IS_EXTENSION_FUNCTION_TYPE.on(upperBound)); } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt index 3beadd72819..c49453eb414 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType import org.jetbrains.kotlin.builtins.getValueParametersFromFunctionType -import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl @@ -220,7 +220,7 @@ class FunctionDescriptorResolver( ) } - private fun KotlinType.functionTypeExpected() = !TypeUtils.noExpectedType(this) && isFunctionOrExtensionFunctionType + private fun KotlinType.functionTypeExpected() = !TypeUtils.noExpectedType(this) && isFunctionTypeOrSubtype private fun KotlinType.getReceiverType(): KotlinType? = if (functionTypeExpected()) getReceiverTypeFromFunctionType(this) else null diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/InlineParameterChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/InlineParameterChecker.kt index 2ae8c2a3c37..833f1f275bc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/InlineParameterChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/InlineParameterChecker.kt @@ -16,7 +16,7 @@ package org.jetbrains.kotlin.resolve -import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.diagnostics.DiagnosticSink import org.jetbrains.kotlin.diagnostics.Errors @@ -34,7 +34,7 @@ object InlineParameterChecker : DeclarationChecker { val inline = declaration.hasModifier(KtTokens.INLINE_KEYWORD) for (parameter in declaration.valueParameters) { val parameterDescriptor = bindingContext.get(BindingContext.VALUE_PARAMETER, parameter) - if (!inline || (parameterDescriptor != null && !parameterDescriptor.type.isFunctionOrExtensionFunctionType)) { + if (!inline || (parameterDescriptor != null && !parameterDescriptor.type.isFunctionTypeOrSubtype)) { parameter.reportIncorrectInline(KtTokens.NOINLINE_KEYWORD, diagnosticHolder) parameter.reportIncorrectInline(KtTokens.CROSSINLINE_KEYWORD, diagnosticHolder) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt index 9fb3c2d9afd..de8ad0e5629 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve.calls import com.google.common.collect.Lists import com.google.common.collect.Sets import org.jetbrains.kotlin.builtins.ReflectionTypes -import org.jetbrains.kotlin.builtins.isExactExtensionFunctionType +import org.jetbrains.kotlin.builtins.isExtensionFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors.SUPER_CANT_BE_EXTENSION_RECEIVER @@ -280,7 +280,7 @@ class CandidateResolver( candidateCall.extensionReceiver != null && candidateCall.dispatchReceiver != null ) { - if (call.dispatchReceiver == candidateCall.dispatchReceiver && !call.dispatchReceiver.type.isExactExtensionFunctionType) { + if (call.dispatchReceiver == candidateCall.dispatchReceiver && !call.dispatchReceiver.type.isExtensionFunctionType) { tracing.nonExtensionFunctionCalledAsExtension(trace) return@checkAndReport OTHER_ERROR } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt index e30f3c5dca1..86554338958 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt @@ -17,7 +17,7 @@ package org.jetbrains.kotlin.resolve.calls import org.jetbrains.kotlin.builtins.ReflectionTypes -import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor @@ -238,7 +238,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes ) = if (!TypeUtils.noExpectedType(context.expectedType) && ownerReturnType != null && TypeUtils.isTypeParameter(ownerReturnType) && - literalExpectedType.isFunctionOrExtensionFunctionType && + literalExpectedType.isFunctionTypeOrSubtype && getReturnTypeForCallable(literalExpectedType) == ownerReturnType) context.expectedType else DONT_CARE @@ -258,7 +258,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes if (expectedType == null || TypeUtils.isDontCarePlaceholder(expectedType)) { expectedType = argumentTypeResolver.getShapeTypeOfFunctionLiteral(functionLiteral, context.scope, context.trace, false) } - if (expectedType == null || !expectedType.isFunctionOrExtensionFunctionType || hasUnknownFunctionParameter(expectedType)) { + if (expectedType == null || !expectedType.isFunctionTypeOrSubtype || hasUnknownFunctionParameter(expectedType)) { return } val dataFlowInfoForArguments = context.candidateCall.dataFlowInfoForArguments @@ -328,7 +328,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes return substitutedType val shapeType = argumentTypeResolver.getShapeTypeOfCallableReference(callableReference, context, false) - if (shapeType != null && shapeType.isFunctionOrExtensionFunctionType && !hasUnknownFunctionParameter(shapeType)) + if (shapeType != null && shapeType.isFunctionTypeOrSubtype && !hasUnknownFunctionParameter(shapeType)) return shapeType return null diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.java index 18d57fc223c..3501789559b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.java @@ -235,7 +235,7 @@ class InlineChecker implements CallChecker { boolean isInvoke = descriptor.getName().equals(OperatorNameConventions.INVOKE) && containingDeclaration instanceof ClassDescriptor && - FunctionTypesKt.isExactFunctionOrExtensionFunctionType(((ClassDescriptor) containingDeclaration).getDefaultType()); + FunctionTypesKt.isFunctionType(((ClassDescriptor) containingDeclaration).getDefaultType()); return isInvoke || InlineUtil.isInline(descriptor); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InvokeConventionChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InvokeConventionChecker.kt index 9f8bc31ade5..09b2c6524b4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InvokeConventionChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InvokeConventionChecker.kt @@ -16,7 +16,7 @@ package org.jetbrains.kotlin.resolve.calls.checkers -import org.jetbrains.kotlin.builtins.isExactExtensionFunctionType +import org.jetbrains.kotlin.builtins.isExtensionFunctionType import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext @@ -30,7 +30,7 @@ class InvokeConventionChecker : CallChecker { val functionCall = resolvedCall.functionCall val variableCall = resolvedCall.variableCall if (functionCall.dispatchReceiver != null && functionCall.extensionReceiver != null && - variableCall.resultingDescriptor.type.isExactExtensionFunctionType) { + variableCall.resultingDescriptor.type.isExtensionFunctionType) { if (variableCall.dispatchReceiver is ExpressionReceiver || variableCall.extensionReceiver is ExpressionReceiver) { val callElement = variableCall.call.callElement context.trace.report(Errors.INVOKE_ON_EXTENSION_FUNCTION_WITH_EXPLICIT_DISPATCH_RECEIVER.on(callElement)) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForInvoke.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForInvoke.java index ff480f3bce1..67ec671fb3c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForInvoke.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForInvoke.java @@ -87,7 +87,7 @@ public class TracingStrategyForInvoke extends AbstractTracingStrategy { } private void functionExpectedOrNoReceiverAllowed(BindingTrace trace) { - if (FunctionTypesKt.isFunctionType(calleeType)) { + if (FunctionTypesKt.isNonExtensionFunctionType(calleeType)) { trace.report(NO_RECEIVER_ALLOWED.on(reference)); } else { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java index c73a9bb8c30..3b062077ec0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java @@ -36,7 +36,7 @@ public class InlineUtil { public static boolean isInlineLambdaParameter(@NotNull ParameterDescriptor valueParameterOrReceiver) { return !(valueParameterOrReceiver instanceof ValueParameterDescriptor && ((ValueParameterDescriptor) valueParameterOrReceiver).isNoinline()) && - FunctionTypesKt.isExactFunctionOrExtensionFunctionType(valueParameterOrReceiver.getOriginal().getType()); + FunctionTypesKt.isFunctionType(valueParameterOrReceiver.getOriginal().getType()); } public static boolean isInline(@Nullable DeclarationDescriptor descriptor) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt index 30be20599af..8cc236916f3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt @@ -21,7 +21,7 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.createFunctionType import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType -import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.annotations.Annotations @@ -140,7 +140,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre if (!expression.functionLiteral.hasBody()) return null val expectedType = context.expectedType - val functionTypeExpected = !noExpectedType(expectedType) && expectedType.isFunctionOrExtensionFunctionType + val functionTypeExpected = !noExpectedType(expectedType) && expectedType.isFunctionTypeOrSubtype val functionDescriptor = createFunctionLiteralDescriptor(expression, context) expression.valueParameters.forEach { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt index 900e88a6d2b..b775aa098bf 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt @@ -16,7 +16,7 @@ package org.jetbrains.kotlin.resolve.calls.tower -import org.jetbrains.kotlin.builtins.isExactExtensionFunctionType +import org.jetbrains.kotlin.builtins.isExtensionFunctionType import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tasks.createSynthesizedInvokes @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.util.OperatorNameConventions import java.util.* - abstract class AbstractInvokeTowerProcessor( protected val functionContext: TowerContext, private val variableProcessor: ScopeTowerProcessor @@ -141,7 +140,7 @@ private class InvokeExtensionScopeTowerProcessor( private fun ScopeTower.getExtensionInvokeCandidateDescriptor( extensionFunctionReceiver: ReceiverValue ): CandidateWithBoundDispatchReceiver? { - if (!extensionFunctionReceiver.type.isExactExtensionFunctionType) return null + if (!extensionFunctionReceiver.type.isExtensionFunctionType) return null val invokeDescriptor = extensionFunctionReceiver.type.memberScope.getContributedFunctions(OperatorNameConventions.INVOKE, location).single() val synthesizedInvoke = createSynthesizedInvokes(listOf(invokeDescriptor)).single() diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt index 16bbea497d8..c43e97626a5 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt @@ -117,7 +117,7 @@ class ReflectionTypes(private val module: ModuleDescriptor) { } fun isCallableType(type: KotlinType): Boolean = - type.isFunctionOrExtensionFunctionType || isKCallableType(type) + type.isFunctionTypeOrSubtype || isKCallableType(type) private fun isKCallableType(type: KotlinType): Boolean = isExactKCallableType(type) || diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt index b394198abd0..6690eda58ba 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt @@ -30,28 +30,22 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.types.* import java.util.* -val KotlinType.isFunctionOrExtensionFunctionType: Boolean - get() = isFunctionType || isExtensionFunctionType +val KotlinType.isFunctionTypeOrSubtype: Boolean + get() = isFunctionType || constructor.supertypes.any(KotlinType::isFunctionTypeOrSubtype) val KotlinType.isFunctionType: Boolean - get() = isExactFunctionType || constructor.supertypes.any(KotlinType::isFunctionType) - -val KotlinType.isExtensionFunctionType: Boolean - get() = isExactExtensionFunctionType || constructor.supertypes.any(KotlinType::isExtensionFunctionType) - -val KotlinType.isExactFunctionOrExtensionFunctionType: Boolean get() { val descriptor = constructor.declarationDescriptor return descriptor != null && isNumberedFunctionClassFqName(descriptor.fqNameUnsafe) } -val KotlinType.isExactFunctionType: Boolean - get() = isExactFunctionOrExtensionFunctionType && !isTypeAnnotatedWithExtension +val KotlinType.isNonExtensionFunctionType: Boolean + get() = isFunctionType && !isTypeAnnotatedWithExtensionFunctionType -val KotlinType.isExactExtensionFunctionType: Boolean - get() = isExactFunctionOrExtensionFunctionType && isTypeAnnotatedWithExtension +val KotlinType.isExtensionFunctionType: Boolean + get() = isFunctionType && isTypeAnnotatedWithExtensionFunctionType -private val KotlinType.isTypeAnnotatedWithExtension: Boolean +private val KotlinType.isTypeAnnotatedWithExtensionFunctionType: Boolean get() = annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.extensionFunctionType) != null /** @@ -69,16 +63,15 @@ fun isNumberedFunctionClassFqName(fqName: FqNameUnsafe): Boolean { } fun getReceiverTypeFromFunctionType(type: KotlinType): KotlinType? { - assert(type.isFunctionOrExtensionFunctionType) { type } + assert(type.isFunctionTypeOrSubtype) { type } if (type.isExtensionFunctionType) { - // TODO: this is incorrect when a class extends from an extension function and swaps type arguments - return type.arguments[0].type + return type.arguments.first().type } return null } fun getValueParametersFromFunctionType(functionDescriptor: FunctionDescriptor, type: KotlinType): List { - assert(type.isFunctionOrExtensionFunctionType) { type } + assert(type.isFunctionTypeOrSubtype) { type } return getParameterTypeProjectionsFromFunctionType(type).mapIndexed { i, typeProjection -> ValueParameterDescriptorImpl( functionDescriptor, null, i, Annotations.EMPTY, @@ -92,12 +85,12 @@ fun getValueParametersFromFunctionType(functionDescriptor: FunctionDescriptor, t } fun getReturnTypeFromFunctionType(type: KotlinType): KotlinType { - assert(type.isFunctionOrExtensionFunctionType) { type } + assert(type.isFunctionTypeOrSubtype) { type } return type.arguments.last().type } fun getParameterTypeProjectionsFromFunctionType(type: KotlinType): List { - assert(type.isFunctionOrExtensionFunctionType) { type } + assert(type.isFunctionTypeOrSubtype) { type } val arguments = type.arguments val first = if (type.isExtensionFunctionType) 1 else 0 val last = arguments.size - 2 diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 8e35ac80e92..7a11b493227 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -183,7 +183,7 @@ internal class DescriptorRendererImpl( } private fun shouldRenderAsPrettyFunctionType(type: KotlinType): Boolean { - return type.isExactFunctionOrExtensionFunctionType && type.arguments.none { it.isStarProjection } + return type.isFunctionType && type.arguments.none { it.isStarProjection } } private fun renderFlexibleType(type: KotlinType): String { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/FunctionsHighlightingVisitor.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/FunctionsHighlightingVisitor.java index 56a04519a92..3371cd49cea 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/FunctionsHighlightingVisitor.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/FunctionsHighlightingVisitor.java @@ -74,7 +74,7 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit DeclarationDescriptor container = calleeDescriptor.getContainingDeclaration(); boolean containedInFunctionClassOrSubclass = container instanceof ClassDescriptor && - FunctionTypesKt.isFunctionOrExtensionFunctionType(((ClassDescriptor) container).getDefaultType()); + FunctionTypesKt.isFunctionTypeOrSubtype(((ClassDescriptor) container).getDefaultType()); NameHighlighter.highlightName(holder, callee, containedInFunctionClassOrSubclass ? KotlinHighlightingColors.VARIABLE_AS_FUNCTION_CALL : KotlinHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL); diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt index eed5107d19e..26c9ade3a5e 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt @@ -24,7 +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.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.idea.KotlinIcons import org.jetbrains.kotlin.idea.completion.handlers.CastReceiverInsertHandler @@ -299,7 +299,7 @@ fun breakOrContinueExpressionItems(position: KtElement, breakOrContinue: String) fun BasicLookupElementFactory.createLookupElementForType(type: KotlinType): LookupElement? { if (type.isError) return null - if (type.isExactFunctionOrExtensionFunctionType) { + if (type.isFunctionType) { val text = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type) val baseLookupElement = LookupElementBuilder.create(text).withIcon(KotlinIcons.LAMBDA) return BaseTypeLookupElement(type, baseLookupElement) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ContextVariablesProvider.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ContextVariablesProvider.kt index 3a92ac84ca7..b4c0e4855af 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ContextVariablesProvider.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ContextVariablesProvider.kt @@ -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.isFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype 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 { it.type.isFunctionOrExtensionFunctionType } + collectVariables().filter { it.type.isFunctionTypeOrSubtype } } private fun collectVariables(): Collection { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/InsertHandlerProvider.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/InsertHandlerProvider.kt index 0ce087ee2d6..69548985be0 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/InsertHandlerProvider.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/InsertHandlerProvider.kt @@ -20,7 +20,7 @@ import com.intellij.codeInsight.completion.InsertHandler import com.intellij.codeInsight.lookup.LookupElement import org.jetbrains.kotlin.builtins.getParameterTypeProjectionsFromFunctionType import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType -import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.idea.completion.handlers.* import org.jetbrains.kotlin.idea.core.ExpectedInfo @@ -53,7 +53,7 @@ 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 (parameterType.isExactFunctionOrExtensionFunctionType) { + if (parameterType.isFunctionType) { val parameterCount = getParameterTypeProjectionsFromFunctionType(parameterType).size if (parameterCount <= 1) { // otherwise additional item with lambda template is to be added @@ -98,7 +98,7 @@ class InsertHandlerProvider( potentiallyInferred.add(descriptor) } - if (type.isExactFunctionOrExtensionFunctionType && getParameterTypeProjectionsFromFunctionType(type).size <= 1) { + if (type.isFunctionType && 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(getReturnTypeFromFunctionType(type)) return diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt index 2bc4a2df8d0..ec8807577c9 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt @@ -23,7 +23,7 @@ import com.intellij.codeInsight.lookup.LookupElementPresentation import com.intellij.codeInsight.lookup.impl.LookupCellRenderer import com.intellij.util.SmartList import org.jetbrains.kotlin.builtins.getParameterTypeProjectionsFromFunctionType -import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.idea.completion.handlers.GenerateLambdaInfo import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler @@ -68,7 +68,7 @@ class LookupElementFactory( companion object { fun hasSingleFunctionTypeParameter(descriptor: FunctionDescriptor): Boolean { val parameter = descriptor.original.valueParameters.singleOrNull() ?: return false - return parameter.type.isExactFunctionOrExtensionFunctionType + return parameter.type.isFunctionType } } @@ -108,7 +108,7 @@ class LookupElementFactory( val lastParameter = descriptor.valueParameters.lastOrNull() ?: return if (!descriptor.valueParameters.all { it == lastParameter || it.hasDefaultValue() }) return - if (lastParameter.original.type.isExactFunctionOrExtensionFunctionType) { + if (lastParameter.original.type.isFunctionType) { val isSingleParameter = descriptor.valueParameters.size == 1 val parameterType = lastParameter.type diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/GenerateLambda.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/GenerateLambda.kt index 04638ad0da7..044e99d6a3e 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/GenerateLambda.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/GenerateLambda.kt @@ -26,7 +26,7 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiDocumentManager import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.builtins.getParameterTypeProjectionsFromFunctionType -import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.core.ExpectedInfos import org.jetbrains.kotlin.idea.core.KotlinNameSuggester @@ -84,7 +84,7 @@ private fun needExplicitParameterTypes(context: InsertionContext, placeholderRan val functionTypes = expectedInfos .mapNotNull { it.fuzzyType?.type } - .filter(KotlinType::isExactFunctionOrExtensionFunctionType) + .filter(KotlinType::isFunctionType) .toSet() if (functionTypes.size <= 1) return false diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt index 4e82fe4711c..a7ce22ea273 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt @@ -26,7 +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.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor @@ -81,7 +81,7 @@ class TypeInstantiationItems( fuzzyType: FuzzyType, tail: Tail? ) { - if (fuzzyType.type.isExactFunctionOrExtensionFunctionType) return // do not show "object: ..." for function types + if (fuzzyType.type.isFunctionType) return // do not show "object: ..." for function types val classifier = fuzzyType.type.constructor.declarationDescriptor if (classifier !is ClassDescriptor) return diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt index 01cea7d1bdf..c7ebadf1ab2 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt @@ -23,7 +23,7 @@ import com.intellij.codeInsight.lookup.LookupElementDecorator import com.intellij.codeInsight.lookup.LookupElementPresentation import com.intellij.openapi.util.Key import org.jetbrains.kotlin.builtins.ReflectionTypes -import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.idea.completion.handlers.WithExpressionPrefixInsertHandler @@ -308,7 +308,7 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion( } fun Collection.filterFunctionExpected() - = filter { it.fuzzyType != null && it.fuzzyType!!.type.isExactFunctionOrExtensionFunctionType } + = filter { it.fuzzyType != null && it.fuzzyType!!.type.isFunctionType } fun Collection.filterCallableExpected() = filter { it.fuzzyType != null && ReflectionTypes.isCallableType(it.fuzzyType!!.type) } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt index 1e98cf110e1..bc249bc657c 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt @@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.core import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType -import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ideService @@ -320,7 +320,7 @@ class ExpectedInfos( if (parameter.hasDefaultValue()) return false // parameter is optional if (parameter.varargElementType != null) return false // vararg arguments list can be empty // last parameter of functional type can be placed outside parenthesis: - if (!isArrayAccess && parameter == parameters.last() && parameter.type.isExactFunctionOrExtensionFunctionType) return false + if (!isArrayAccess && parameter == parameters.last() && parameter.type.isFunctionType) return false return true } @@ -364,7 +364,7 @@ class ExpectedInfos( parameter.type if (isFunctionLiteralArgument) { - if (parameterType.isExactFunctionOrExtensionFunctionType) { + if (parameterType.isFunctionType) { add(ExpectedInfo.createForArgument(parameterType, expectedName, null, argumentPositionData)) } } @@ -483,7 +483,7 @@ class ExpectedInfos( val literalExpression = functionLiteral.parent as KtLambdaExpression return calculate(literalExpression) .mapNotNull { it.fuzzyType } - .filter { it.type.isExactFunctionOrExtensionFunctionType } + .filter { it.type.isFunctionType } .map { val returnType = getReturnTypeFromFunctionType(it.type) ExpectedInfo(FuzzyType(returnType, it.freeParameters), null, Tail.RBRACE) diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggester.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggester.kt index 545d5872ee8..5407673fc9d 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggester.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggester.kt @@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.core import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.lexer.KotlinLexer import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* @@ -216,7 +216,7 @@ object KotlinNameSuggester { } } } - else if (type.isExactFunctionOrExtensionFunctionType) { + else if (type.isFunctionType) { addName("function", validator) } else { diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/internal/FindImplicitNothingAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/internal/FindImplicitNothingAction.kt index b2e72984b4d..2418208ad7d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/internal/FindImplicitNothingAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/internal/FindImplicitNothingAction.kt @@ -35,7 +35,7 @@ import com.intellij.usages.UsageViewManager import com.intellij.usages.UsageViewPresentation import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType -import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.psi.* @@ -128,13 +128,8 @@ class FindImplicitNothingAction : AnAction() { } private fun KotlinType.isNothingOrNothingFunctionType(): Boolean { - return when { - KotlinBuiltIns.isNothing(this) -> true - - this.isExactFunctionOrExtensionFunctionType -> getReturnTypeFromFunctionType(this).isNothingOrNothingFunctionType() - - else -> false - } + return KotlinBuiltIns.isNothing(this) || + (isFunctionType && getReturnTypeFromFunctionType(this).isNothingOrNothingFunctionType()) } override fun update(e: AnActionEvent) { diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/fixers/KotlinLastLambdaParameterFixer.kt b/idea/src/org/jetbrains/kotlin/idea/editor/fixers/KotlinLastLambdaParameterFixer.kt index fce64a1124e..2aea59fff43 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/fixers/KotlinLastLambdaParameterFixer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/fixers/KotlinLastLambdaParameterFixer.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.editor.fixers import com.intellij.lang.SmartEnterProcessorWithFixers import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler import org.jetbrains.kotlin.psi.KtCallExpression @@ -38,7 +38,7 @@ class KotlinLastLambdaParameterFixer : SmartEnterProcessorWithFixers.Fixer