Take ReceiverParameterDescriptor in FunctionDescriptorImpl.initialize

Instead of just KotlinType. This will allow to pass annotations on the
receiver at call sites
This commit is contained in:
Alexander Udalov
2018-08-08 16:35:21 +02:00
parent 6fb39785ff
commit 34c033bcaf
39 changed files with 200 additions and 107 deletions
@@ -18,13 +18,11 @@ package org.jetbrains.kotlin.load.java.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
import org.jetbrains.kotlin.descriptors.SourceElement;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.DescriptorFactory;
import org.jetbrains.kotlin.types.KotlinType;
import java.util.List;
@@ -125,9 +123,13 @@ public class JavaClassConstructorDescriptor extends ClassConstructorDescriptorIm
) {
JavaClassConstructorDescriptor enhanced = createSubstitutedCopy(
getContainingDeclaration(), /* original = */ null, getKind(), null, getAnnotations(), getSource());
ReceiverParameterDescriptor enhancedReceiver =
enhancedReceiverType == null ? null : DescriptorFactory.createExtensionReceiverParameterForCallable(
enhanced, enhancedReceiverType, Annotations.Companion.getEMPTY()
);
// We do not use doSubstitute here as in JavaMethodDescriptor.enhance because type parameters of constructor belongs to class
enhanced.initialize(
enhancedReceiverType,
enhancedReceiver,
getDispatchReceiverParameter(),
getTypeParameters(),
UtilKt.copyValueParameters(enhancedValueParametersData, getValueParameters(), enhanced),
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.DescriptorFactory;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.util.OperatorChecks;
@@ -83,7 +84,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
@NotNull
@Override
public SimpleFunctionDescriptorImpl initialize(
@Nullable KotlinType receiverParameterType,
@Nullable ReceiverParameterDescriptor extensionReceiverParameter,
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
@@ -93,8 +94,9 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
@Nullable Map<? extends UserDataKey<?>, ?> userData
) {
SimpleFunctionDescriptorImpl descriptor = super.initialize(
receiverParameterType, dispatchReceiverParameter, typeParameters, unsubstitutedValueParameters,
unsubstitutedReturnType, modality, visibility, userData);
extensionReceiverParameter, dispatchReceiverParameter, typeParameters, unsubstitutedValueParameters,
unsubstitutedReturnType, modality, visibility, userData
);
setOperator(OperatorChecks.INSTANCE.check(descriptor).isSuccess());
return descriptor;
}
@@ -147,11 +149,16 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
List<ValueParameterDescriptor> enhancedValueParameters =
UtilKt.copyValueParameters(enhancedValueParametersData, getValueParameters(), this);
ReceiverParameterDescriptor enhancedReceiver =
enhancedReceiverType == null ? null : DescriptorFactory.createExtensionReceiverParameterForCallable(
this, enhancedReceiverType, Annotations.Companion.getEMPTY()
);
JavaMethodDescriptor enhancedMethod =
(JavaMethodDescriptor) newCopyBuilder()
.setValueParameters(enhancedValueParameters)
.setReturnType(enhancedReturnType)
.setExtensionReceiverType(enhancedReceiverType)
.setExtensionReceiverParameter(enhancedReceiver)
.setDropOriginalInContainingParts()
.setPreserveSourceElement()
.build();
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.incremental.components.LookupLocation
@@ -35,6 +36,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaField
import org.jetbrains.kotlin.load.java.structure.JavaMethod
import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorFactory
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.constants.StringValue
import org.jetbrains.kotlin.resolve.descriptorUtil.firstArgument
@@ -130,14 +132,16 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
val effectiveSignature = resolveMethodSignature(method, methodTypeParameters, returnType, valueParameters.descriptors)
functionDescriptorImpl.initialize(
effectiveSignature.receiverType,
getDispatchReceiverParameter(),
effectiveSignature.typeParameters,
effectiveSignature.valueParameters,
effectiveSignature.returnType,
Modality.convertFromFlags(method.isAbstract, !method.isFinal),
method.visibility,
if (effectiveSignature.receiverType != null)
effectiveSignature.receiverType?.let {
DescriptorFactory.createExtensionReceiverParameterForCallable(functionDescriptorImpl, it, Annotations.EMPTY)
},
getDispatchReceiverParameter(),
effectiveSignature.typeParameters,
effectiveSignature.valueParameters,
effectiveSignature.returnType,
Modality.convertFromFlags(method.isAbstract, !method.isFinal),
method.visibility,
if (effectiveSignature.receiverType != null)
mapOf(JavaMethodDescriptor.ORIGINAL_VALUE_PARAMETER_FOR_EXTENSION_RECEIVER to valueParameters.descriptors.first())
else
emptyMap<FunctionDescriptor.UserDataKey<ValueParameterDescriptor>, ValueParameterDescriptor>()