[FE] Add getContextReceivers to CallableDescriptor interface

This commit is contained in:
Anastasiya Shadrina
2020-07-15 17:57:19 +07:00
committed by TeamCityServer
parent 7de8380ddf
commit a39fbd3822
61 changed files with 194 additions and 63 deletions
@@ -42,7 +42,7 @@ sealed class LocalVariableAccessorDescriptor(
val returnType =
if (isGetter) correspondingVariable.type else correspondingVariable.builtIns.unitType
@Suppress("LeakingThis")
initialize(null, null, emptyList(), valueParameters, returnType, Modality.FINAL, DescriptorVisibilities.LOCAL)
initialize(null, null, emptyList(), emptyList(), valueParameters, returnType, Modality.FINAL, DescriptorVisibilities.LOCAL)
}
private fun createValueParameter(name: Name, type: KotlinType): ValueParameterDescriptorImpl {
@@ -52,6 +52,7 @@ object DataClassDescriptorResolver {
functionDescriptor.initialize(
null,
classDescriptor.thisAsReceiverParameter,
emptyList<ReceiverParameterDescriptor>(),
emptyList<TypeParameterDescriptor>(),
emptyList<ValueParameterDescriptor>(),
property.type,
@@ -96,6 +97,7 @@ object DataClassDescriptorResolver {
functionDescriptor.initialize(
null,
classDescriptor.thisAsReceiverParameter,
emptyList<ReceiverParameterDescriptor>(),
emptyList<TypeParameterDescriptor>(),
parameterDescriptors,
classDescriptor.defaultType,
@@ -63,6 +63,8 @@ import org.jetbrains.kotlin.types.expressions.*;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.*;
import static org.jetbrains.kotlin.diagnostics.Errors.*;
@@ -927,6 +929,7 @@ public class DescriptorResolver {
LexicalScope scopeForDeclarationResolutionWithTypeParameters;
LexicalScope scopeForInitializerResolutionWithTypeParameters;
KotlinType receiverType = null;
Stream<KotlinType> contextReceiverTypes;
{
List<KtTypeParameter> typeParameters = variableDeclaration.getTypeParameters();
@@ -965,6 +968,8 @@ public class DescriptorResolver {
for (KtTypeReference contextReceiverTypeRef: contextReceiverTypeRefs) {
typeResolver.resolveType(scopeForDeclarationResolutionWithTypeParameters, contextReceiverTypeRef, trace, true);
}
contextReceiverTypes = contextReceiverTypeRefs.stream()
.map((typeRef) -> typeResolver.resolveType(scopeForDeclarationResolutionWithTypeParameters, typeRef, trace, true));
}
ReceiverParameterDescriptor receiverDescriptor;
@@ -978,6 +983,13 @@ public class DescriptorResolver {
receiverDescriptor = null;
}
List<ReceiverParameterDescriptor> contextReceiverDescriptors = contextReceiverTypes.map((type) -> {
AnnotationSplitter splitter = new AnnotationSplitter(storageManager, type.getAnnotations(), EnumSet.of(RECEIVER));
return DescriptorFactory.createExtensionReceiverParameterForCallable(
propertyDescriptor, type, splitter.getAnnotationsForTarget(RECEIVER)
);
}).collect(Collectors.toList());
LexicalScope scopeForInitializer = ScopeUtils.makeScopeForPropertyInitializer(scopeForInitializerResolutionWithTypeParameters, propertyDescriptor);
KotlinType propertyType = propertyInfo.getVariableType();
KotlinType typeIfKnown = propertyType != null ? propertyType : variableTypeAndInitializerResolver.resolveTypeNullable(
@@ -1006,7 +1018,8 @@ public class DescriptorResolver {
propertyDescriptor, scopeForInitializer, variableDeclaration, dataFlowInfo, type, inferenceSession, trace
);
propertyDescriptor.setType(type, typeParameterDescriptors, getDispatchReceiverParameterIfNeeded(container), receiverDescriptor);
propertyDescriptor.setType(type, typeParameterDescriptors, getDispatchReceiverParameterIfNeeded(container), receiverDescriptor,
contextReceiverDescriptors);
PropertySetterDescriptor setter = resolvePropertySetterDescriptor(
scopeForDeclarationResolutionWithTypeParameters,
@@ -1304,7 +1317,8 @@ public class DescriptorResolver {
false,
false
);
propertyDescriptor.setType(type, Collections.emptyList(), getDispatchReceiverParameterIfNeeded(classDescriptor), null);
propertyDescriptor.setType(type, Collections.emptyList(), getDispatchReceiverParameterIfNeeded(classDescriptor), null,
CollectionsKt.emptyList());
Annotations setterAnnotations = annotationSplitter.getAnnotationsForTarget(PROPERTY_SETTER);
Annotations getterAnnotations = new CompositeAnnotations(CollectionsKt.listOf(
@@ -197,7 +197,7 @@ class FunctionDescriptorResolver(
if (function is KtFunctionLiteral) expectedFunctionType.getReceiverType() else null
}
function.contextReceiverTypeReferences.onEach {
val contextReceiverTypes = function.contextReceiverTypeReferences.map {
typeResolver.resolveType(headerScope, it, trace, true)
}
@@ -231,10 +231,17 @@ class FunctionDescriptorResolver(
functionDescriptor, it, splitter.getAnnotationsForTarget(AnnotationUseSiteTarget.RECEIVER)
)
}
val contextReceivers = contextReceiverTypes.map {
val splitter = AnnotationSplitter(storageManager, it.annotations, EnumSet.of(AnnotationUseSiteTarget.RECEIVER))
DescriptorFactory.createExtensionReceiverParameterForCallable(
functionDescriptor, it, splitter.getAnnotationsForTarget(AnnotationUseSiteTarget.RECEIVER)
)
}
functionDescriptor.initialize(
extensionReceiver,
getDispatchReceiverParameterIfNeeded(container),
contextReceivers,
typeParameterDescriptors,
valueParameterDescriptors,
returnType,
@@ -98,6 +98,7 @@ object FunctionsFromAny {
functionDescriptor.initialize(
null,
classDescriptor.thisAsReceiverParameter,
emptyList(),
functionFromAny.typeParameters,
functionFromAny.valueParameters.map { it.copy(functionDescriptor, it.name, it.index) },
functionFromAny.returnType,
@@ -70,6 +70,7 @@ object InlineClassDescriptorResolver {
functionDescriptor.initialize(
null,
null,
emptyList<ReceiverParameterDescriptor>(),
emptyList<TypeParameterDescriptor>(),
createValueParametersForSpecializedEquals(functionDescriptor, owner.inlineClassRepresentation!!.underlyingType),
owner.builtIns.booleanType,
@@ -93,6 +94,7 @@ object InlineClassDescriptorResolver {
functionDescriptor.initialize(
null,
if (isBoxMethod) null else owner.thisAsReceiverParameter,
emptyList<ReceiverParameterDescriptor>(),
emptyList<TypeParameterDescriptor>(),
if (isBoxMethod) listOf(createValueParameterForBoxing(functionDescriptor, underlyingType)) else emptyList(),
if (isBoxMethod) owner.defaultType else underlyingType,
@@ -186,7 +186,7 @@ class LocalVariableResolver(
)
val receiverParameter = (containingDeclaration as ScriptDescriptor).thisAsReceiverParameter
propertyDescriptor.setType(type, emptyList<TypeParameterDescriptor>(), receiverParameter, null)
propertyDescriptor.setType(type, emptyList<TypeParameterDescriptor>(), receiverParameter, null, emptyList<ReceiverParameterDescriptor>())
initializeWithDefaultGetterSetter(propertyDescriptor)
trace.record(BindingContext.VARIABLE, variable, propertyDescriptor)
result = propertyDescriptor
@@ -105,7 +105,8 @@ class DynamicCallableDescriptors(private val storageManager: StorageManager, bui
dynamicType,
createTypeParameters(propertyDescriptor, call),
createDynamicDispatchReceiverParameter(propertyDescriptor),
null
null,
emptyList()
)
val getter = DescriptorFactory.createDefaultGetter(propertyDescriptor, Annotations.EMPTY)
@@ -128,6 +129,7 @@ class DynamicCallableDescriptors(private val storageManager: StorageManager, bui
functionDescriptor.initialize(
null,
createDynamicDispatchReceiverParameter(functionDescriptor),
emptyList(),
createTypeParameters(functionDescriptor, call),
createValueParameters(functionDescriptor, call),
dynamicType,
@@ -82,6 +82,7 @@ public class ForceResolveUtil {
}
else if (object instanceof CallableDescriptor) {
CallableDescriptor callableDescriptor = (CallableDescriptor) object;
callableDescriptor.getContextReceiverParameters().forEach(p -> forceResolveAllContents(p.getType()));
ReceiverParameterDescriptor parameter = callableDescriptor.getExtensionReceiverParameter();
if (parameter != null) {
forceResolveAllContents(parameter.getType());
@@ -319,7 +319,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
CallableMemberDescriptor.Kind.SYNTHESIZED, SourceElement.NO_SOURCE
) {
{
initialize(null, null, Collections.emptyList(), Collections.emptyList(),
initialize(null, null, CollectionsKt.emptyList(), Collections.emptyList(), Collections.emptyList(),
null, Modality.FINAL, DescriptorVisibilities.PRIVATE);
}
@@ -226,6 +226,7 @@ public class ControlStructureTypingUtils {
function.initialize(
null,
null,
Collections.emptyList(),
Lists.newArrayList(typeParameter),
valueParameters,
returnType,
@@ -636,7 +636,7 @@ class DoubleColonExpressionResolver(
)
functionDescriptor.initialize(
null, null, emptyList(),
null, null, emptyList(), emptyList(),
createValueParametersForInvokeInFunctionType(functionDescriptor, type.arguments.dropLast(1)),
type.arguments.last().type,
Modality.FINAL,