From 5b7115dc38ff5d73a52945228a5005b2892f3356 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 14 Mar 2016 16:46:59 +0300 Subject: [PATCH] Minor, drop deprecated KotlinBuiltIns.getExtensionFunction --- .../kotlin/codegen/ClosureCodegen.java | 15 +++++++-------- .../kotlin/builtins/KotlinBuiltIns.java | 15 --------------- .../decompiler/navigation/MemberMatching.java | 8 +------- .../callTranslator/FunctionCallCases.kt | 17 ++++++++--------- 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index 1098da975bb..444be227076 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -27,8 +27,8 @@ import org.jetbrains.kotlin.codegen.binding.CalculatedClosure; import org.jetbrains.kotlin.codegen.context.ClosureContext; import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil; import org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension; -import org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter; import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter; +import org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter; import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; import org.jetbrains.kotlin.descriptors.*; @@ -281,7 +281,7 @@ public class ClosureCodegen extends MemberCodegen { Type[] myParameterTypes = bridge.getArgumentTypes(); - List calleeParameters = CollectionsKt.plus( + List calleeParameters = CollectionsKt.plus( org.jetbrains.kotlin.utils.CollectionsKt.singletonOrEmptyList(funDescriptor.getExtensionReceiverParameter()), funDescriptor.getValueParameters() ); @@ -450,12 +450,11 @@ public class ClosureCodegen extends MemberCodegen { } @NotNull - public static FunctionDescriptor getErasedInvokeFunction(@NotNull FunctionDescriptor elementDescriptor) { - int arity = elementDescriptor.getValueParameters().size(); - ClassDescriptor elementClass = elementDescriptor.getExtensionReceiverParameter() == null - ? DescriptorUtilsKt.getBuiltIns(elementDescriptor).getFunction(arity) - : DescriptorUtilsKt.getBuiltIns(elementDescriptor).getExtensionFunction(arity); - MemberScope scope = elementClass.getDefaultType().getMemberScope(); + public static FunctionDescriptor getErasedInvokeFunction(@NotNull FunctionDescriptor function) { + ClassDescriptor functionClass = DescriptorUtilsKt.getBuiltIns(function).getFunction( + function.getValueParameters().size() + (function.getExtensionReceiverParameter() != null ? 1 : 0) + ); + MemberScope scope = functionClass.getDefaultType().getMemberScope(); return scope.getContributedFunctions(OperatorNameConventions.INVOKE, NoLookupLocation.FROM_BACKEND).iterator().next(); } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index 36cd1eaf9ec..c06bb468d24 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -408,26 +408,11 @@ public abstract class KotlinBuiltIns { return "Function" + parameterCount; } - @NotNull - public static String getExtensionFunctionName(int parameterCount) { - return getFunctionName(parameterCount + 1); - } - @NotNull public ClassDescriptor getFunction(int parameterCount) { return getBuiltInClassByName(getFunctionName(parameterCount)); } - /** - * @return the descriptor representing the class kotlin.Function{parameterCount + 1} - * @deprecated there are no ExtensionFunction classes anymore, use {@link #getFunction(int)} instead - */ - @Deprecated - @NotNull - public ClassDescriptor getExtensionFunction(int parameterCount) { - return getBuiltInClassByName(getExtensionFunctionName((parameterCount))); - } - @NotNull public ClassDescriptor getThrowable() { return getBuiltInClassByName("Throwable"); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/MemberMatching.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/MemberMatching.java index a29b75c1323..92cb4269021 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/MemberMatching.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/MemberMatching.java @@ -74,13 +74,7 @@ public class MemberMatching { @Override public String visitFunctionType(@NotNull KtFunctionType type, Void data) { - int parameterCount = type.getParameters().size(); - if (type.getReceiverTypeReference() != null) { - return KotlinBuiltIns.getExtensionFunctionName(parameterCount); - } - else { - return KotlinBuiltIns.getFunctionName(parameterCount); - } + return KotlinBuiltIns.getFunctionName(type.getParameters().size() + (type.getReceiverTypeReference() != null ? 1 : 0)); } @Override diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt index fa5d4d8edc3..0ca4673bb4f 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt @@ -165,15 +165,14 @@ object InvokeIntrinsic : FunctionCallCase() { val callableDescriptor = callInfo.callableDescriptor if (callableDescriptor.name != OperatorNameConventions.INVOKE) return false - val parameterCount = callableDescriptor.valueParameters.size + val isExtension = callableDescriptor.extensionReceiverParameter != null + val parameterCount = callableDescriptor.valueParameters.size + (if (isExtension) 1 else 0) val funDeclaration = callableDescriptor.containingDeclaration - val reflectionTypes = callInfo.context.reflectionTypes - return if (callableDescriptor.extensionReceiverParameter == null) - funDeclaration == callableDescriptor.builtIns.getFunction(parameterCount) || - funDeclaration == reflectionTypes.getKFunction(parameterCount) - else - funDeclaration == callableDescriptor.builtIns.getExtensionFunction(parameterCount) + if (!isExtension && funDeclaration == callInfo.context.reflectionTypes.getKFunction(parameterCount)) + return true + + return funDeclaration == callableDescriptor.builtIns.getFunction(parameterCount) } override fun FunctionCallInfo.dispatchReceiver(): JsExpression { @@ -181,8 +180,8 @@ object InvokeIntrinsic : FunctionCallCase() { } /** - * A call of extension lambda in compiler looks like as call of invoke function of some ExtensionFunctionN instance. - * So that call have both receivers -- some ExtensionFunctionN instance as this and receiverObject as receiver. + * A call of extension lambda in compiler looks like as call of invoke function of some FunctionN instance. + * So that call have both receivers -- some FunctionN instance as this and receiverObject as receiver. * * in Kotlin code: * obj.extLambda(some, args)