Simplify and rename function type utilities
- isFunctionType -> change the only usage in TracingStrategyForInvoke to check for exact function type - isExtensionFunctionType -> change all usages to check for exact extension function type because extension function types are uninheritable in Kotlin - isExactFunctionType -> isNonExtensionFunctionType - isExactExtensionFunctionType -> isExtensionFunctionType - isExactFunctionOrExtensionFunctionType -> isFunctionType - isFunctionOrExtensionFunctionType -> isFunctionTypeOrSubtype
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
+2
-2
@@ -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))
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
+2
-3
@@ -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<C>(
|
||||
protected val functionContext: TowerContext<C>,
|
||||
private val variableProcessor: ScopeTowerProcessor<C>
|
||||
@@ -141,7 +140,7 @@ private class InvokeExtensionScopeTowerProcessor<C>(
|
||||
private fun ScopeTower.getExtensionInvokeCandidateDescriptor(
|
||||
extensionFunctionReceiver: ReceiverValue
|
||||
): CandidateWithBoundDispatchReceiver<FunctionDescriptor>? {
|
||||
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()
|
||||
|
||||
@@ -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) ||
|
||||
|
||||
@@ -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<ValueParameterDescriptor> {
|
||||
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<TypeProjection> {
|
||||
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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
+2
-2
@@ -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<VariableDescriptor> {
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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<ExpectedInfo>.filterFunctionExpected()
|
||||
= filter { it.fuzzyType != null && it.fuzzyType!!.type.isExactFunctionOrExtensionFunctionType }
|
||||
= filter { it.fuzzyType != null && it.fuzzyType!!.type.isFunctionType }
|
||||
|
||||
fun Collection<ExpectedInfo>.filterCallableExpected()
|
||||
= filter { it.fuzzyType != null && ReflectionTypes.isCallableType(it.fuzzyType!!.type) }
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<Kotli
|
||||
|
||||
if (resolvedCall.valueArguments.size == valueParameters.size - 1) {
|
||||
val type = valueParameters.last().type
|
||||
if (type.isExactFunctionOrExtensionFunctionType) {
|
||||
if (type.isFunctionType) {
|
||||
val doc = editor.document
|
||||
|
||||
var offset = element.endOffset
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.core.moveFunctionLiteralOutsideParentheses
|
||||
@@ -48,7 +48,7 @@ class MoveLambdaOutsideParenthesesIntention : SelfTargetingIntention<KtCallExpre
|
||||
// if there are functions among candidates but none of them have last function parameter then not show the intention
|
||||
if (candidates.isNotEmpty() && candidates.none {
|
||||
val lastParameter = it.valueParameters.lastOrNull()
|
||||
lastParameter != null && lastParameter.type.isExactFunctionOrExtensionFunctionType
|
||||
lastParameter != null && lastParameter.type.isFunctionType
|
||||
}) {
|
||||
return false
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.builtins.getParameterTypeProjectionsFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||
@@ -43,7 +43,7 @@ object CreateFunctionFromCallableReferenceActionFactory : CreateCallableMemberFr
|
||||
val context = resolutionFacade.analyze(element, BodyResolveMode.PARTIAL)
|
||||
return element
|
||||
.guessTypes(context, resolutionFacade.moduleDescriptor)
|
||||
.filter(KotlinType::isExactFunctionOrExtensionFunctionType)
|
||||
.filter(KotlinType::isFunctionType)
|
||||
.mapNotNull {
|
||||
val expectedReceiverType = getReceiverTypeFromFunctionType(it)
|
||||
val actualReceiverTypeRef = element.typeReference
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.intellij.util.VisibilityUtil
|
||||
import org.jetbrains.kotlin.asJava.getRepresentativeLightMethod
|
||||
import org.jetbrains.kotlin.asJava.toLightMethods
|
||||
import org.jetbrains.kotlin.asJava.unwrapped
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isNonExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
@@ -248,7 +248,7 @@ open class KotlinChangeInfo(
|
||||
if (kind == Kind.FUNCTION) {
|
||||
receiverParameterInfo?.let {
|
||||
val typeInfo = it.currentTypeInfo
|
||||
if (typeInfo.type != null && typeInfo.type.isExactFunctionType) {
|
||||
if (typeInfo.type != null && typeInfo.type.isNonExtensionFunctionType) {
|
||||
buffer.append("(${typeInfo.render()})")
|
||||
}
|
||||
else {
|
||||
|
||||
+2
-3
@@ -22,7 +22,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import com.intellij.psi.search.LocalSearchScope
|
||||
import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor
|
||||
import org.jetbrains.kotlin.builtins.isExactFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.*
|
||||
import org.jetbrains.kotlin.idea.intentions.ConvertToExpressionBodyIntention
|
||||
@@ -86,8 +86,7 @@ private fun buildSignature(config: ExtractionGeneratorConfiguration, renderer: D
|
||||
config.descriptor.receiverParameter?.let {
|
||||
val receiverType = it.getParameterType(config.descriptor.extractionData.options.allowSpecialClassNames)
|
||||
val receiverTypeAsString = receiverType.typeAsString()
|
||||
val isFunctionType = receiverType.isExactFunctionOrExtensionFunctionType
|
||||
receiver(if (isFunctionType) "($receiverTypeAsString)" else receiverTypeAsString)
|
||||
receiver(if (receiverType.isFunctionType) "($receiverTypeAsString)" else receiverTypeAsString)
|
||||
}
|
||||
|
||||
name(config.generatorOptions.dummyName ?: config.descriptor.name)
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.google.dart.compiler.backend.js.ast.metadata.inlineStrategy
|
||||
import com.google.gwt.dev.js.ThrowExceptionOnErrorReporter
|
||||
import com.intellij.util.containers.SLRUCache
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.js.config.LibrarySourcesConfig
|
||||
import org.jetbrains.kotlin.js.inline.util.IdentitySet
|
||||
@@ -142,7 +142,7 @@ private fun JsFunction.markInlineArguments(descriptor: CallableDescriptor) {
|
||||
if (!CallExpressionTranslator.shouldBeInlined(descriptor)) continue
|
||||
|
||||
val type = param.type
|
||||
if (!type.isFunctionOrExtensionFunctionType) continue
|
||||
if (!type.isFunctionTypeOrSubtype) continue
|
||||
|
||||
val namesSet = if (type.isExtensionFunctionType) inlineExtensionFuns else inlineFuns
|
||||
namesSet.add(paramsJs[i + offset].name)
|
||||
|
||||
Reference in New Issue
Block a user