[FE] Fill DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP only with CR enabled
This commit is contained in:
committed by
TeamCityServer
parent
9e2271399e
commit
2d088196ce
@@ -263,7 +263,7 @@ public interface BindingContext {
|
||||
.setFurtherLookupSlices(DECLARATIONS_TO_DESCRIPTORS)
|
||||
.build();
|
||||
|
||||
WritableSlice<DeclarationDescriptor, Multimap<String, ReceiverParameterDescriptor>> DESCRIPTOR_TO_NAMED_RECEIVERS = Slices.createSimpleSlice();
|
||||
WritableSlice<DeclarationDescriptor, Multimap<String, ReceiverParameterDescriptor>> DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP = Slices.createSimpleSlice();
|
||||
WritableSlice<KtReferenceExpression, PsiElement> LABEL_TARGET = Slices.createSimpleSlice();
|
||||
WritableSlice<KtReferenceExpression, Collection<? extends PsiElement>> AMBIGUOUS_LABEL_TARGET = Slices.createSimpleSlice();
|
||||
WritableSlice<ValueParameterDescriptor, PropertyDescriptor> VALUE_PARAMETER_AS_PROPERTY = Slices.createSimpleSlice();
|
||||
|
||||
@@ -959,8 +959,6 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
Multimap<String, ReceiverParameterDescriptor> nameToReceiverMap = HashMultimap.create();
|
||||
|
||||
KtTypeReference receiverTypeRef = variableDeclaration.getReceiverTypeReference();
|
||||
ReceiverParameterDescriptor receiverDescriptor = null;
|
||||
if (receiverTypeRef != null) {
|
||||
@@ -969,16 +967,38 @@ public class DescriptorResolver {
|
||||
receiverDescriptor = DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||
propertyDescriptor, receiverType, splitter.getAnnotationsForTarget(RECEIVER)
|
||||
);
|
||||
String receiverName = receiverTypeRef.nameForReceiverLabel();
|
||||
if (receiverName != null) {
|
||||
nameToReceiverMap.put(receiverName, receiverDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
List<KtContextReceiver> contextReceivers = variableDeclaration.getContextReceivers();
|
||||
List<ReceiverParameterDescriptor> contextReceiverDescriptors =
|
||||
createReceiverDescriptorsForProperty(propertyDescriptor, scopeForDeclarationResolutionWithTypeParameters, trace,
|
||||
contextReceivers, nameToReceiverMap);
|
||||
List<ReceiverParameterDescriptor> contextReceiverDescriptors = contextReceivers.stream()
|
||||
.map(contextReceiver -> {
|
||||
KtTypeReference typeReference = contextReceiver.typeReference();
|
||||
if (typeReference == null) {
|
||||
return null;
|
||||
}
|
||||
KotlinType type = typeResolver.resolveType(scopeForDeclarationResolutionWithTypeParameters, typeReference, trace, true);
|
||||
AnnotationSplitter splitter = new AnnotationSplitter(storageManager, type.getAnnotations(), EnumSet.of(RECEIVER));
|
||||
return DescriptorFactory.createContextReceiverParameterForCallable(
|
||||
propertyDescriptor, type, splitter.getAnnotationsForTarget(RECEIVER)
|
||||
);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.ContextReceivers)) {
|
||||
Multimap<String, ReceiverParameterDescriptor> nameToReceiverMap = HashMultimap.create();
|
||||
if (receiverTypeRef != null) {
|
||||
String receiverName = receiverTypeRef.nameForReceiverLabel();
|
||||
if (receiverName != null) {
|
||||
nameToReceiverMap.put(receiverName, receiverDescriptor);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < contextReceivers.size(); i++) {
|
||||
String contextReceiverName = contextReceivers.get(i).name();
|
||||
if (contextReceiverName != null) {
|
||||
nameToReceiverMap.put(contextReceiverName, contextReceiverDescriptors.get(i));
|
||||
}
|
||||
}
|
||||
trace.record(DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP, propertyDescriptor, nameToReceiverMap);
|
||||
}
|
||||
|
||||
LexicalScope scopeForInitializer = ScopeUtils.makeScopeForPropertyInitializer(scopeForInitializerResolutionWithTypeParameters, propertyDescriptor);
|
||||
KotlinType propertyType = propertyInfo.getVariableType();
|
||||
@@ -1027,41 +1047,10 @@ public class DescriptorResolver {
|
||||
new FieldDescriptorImpl(annotationSplitter.getAnnotationsForTarget(FIELD), propertyDescriptor),
|
||||
new FieldDescriptorImpl(annotationSplitter.getAnnotationsForTarget(PROPERTY_DELEGATE_FIELD), propertyDescriptor)
|
||||
);
|
||||
trace.record(DESCRIPTOR_TO_NAMED_RECEIVERS, propertyDescriptor, nameToReceiverMap);
|
||||
trace.record(BindingContext.VARIABLE, variableDeclaration, propertyDescriptor);
|
||||
return propertyDescriptor;
|
||||
}
|
||||
|
||||
private List<ReceiverParameterDescriptor> createReceiverDescriptorsForProperty(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull LexicalScope scopeForResolution,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull List<KtContextReceiver> contextReceivers,
|
||||
@NotNull Multimap<String, ReceiverParameterDescriptor> labelNameToReceiverMap
|
||||
) {
|
||||
Map<KtContextReceiver, KotlinType> contextReceiversToTypes = new LinkedHashMap<>();
|
||||
for (KtContextReceiver contextReceiver: contextReceivers) {
|
||||
KtTypeReference typeReference = contextReceiver.typeReference();
|
||||
if (typeReference == null) {
|
||||
continue;
|
||||
}
|
||||
KotlinType kotlinType = typeResolver.resolveType(scopeForResolution, typeReference, trace, true);
|
||||
contextReceiversToTypes.put(contextReceiver, kotlinType);
|
||||
}
|
||||
return Lists.reverse(contextReceivers).stream().map(contextReceiver -> {
|
||||
KotlinType receiverType = contextReceiversToTypes.get(contextReceiver);
|
||||
AnnotationSplitter splitter = new AnnotationSplitter(storageManager, receiverType.getAnnotations(), EnumSet.of(RECEIVER));
|
||||
ReceiverParameterDescriptor receiverDescriptor = DescriptorFactory.createContextReceiverParameterForCallable(
|
||||
propertyDescriptor, receiverType, splitter.getAnnotationsForTarget(RECEIVER)
|
||||
);
|
||||
String contextReceiverName = contextReceiver.name();
|
||||
if (contextReceiverName != null) {
|
||||
labelNameToReceiverMap.put(contextReceiverName, receiverDescriptor);
|
||||
}
|
||||
return receiverDescriptor;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/*package*/ static KotlinType transformAnonymousTypeIfNeeded(
|
||||
@NotNull DeclarationDescriptorWithVisibility descriptor,
|
||||
|
||||
@@ -256,7 +256,7 @@ class FunctionDescriptorResolver(
|
||||
}
|
||||
}
|
||||
|
||||
trace.record(BindingContext.DESCRIPTOR_TO_NAMED_RECEIVERS, functionDescriptor, labelNameToReceiverMap)
|
||||
trace.record(BindingContext.DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP, functionDescriptor, labelNameToReceiverMap)
|
||||
}
|
||||
|
||||
functionDescriptor.initialize(
|
||||
|
||||
+1
-1
@@ -317,7 +317,7 @@ private fun findReceiverByLabelOrGetDefault(
|
||||
labelName: String
|
||||
): ReceiverParameterDescriptor {
|
||||
val labelNameToReceiverMap = bindingContext.get(
|
||||
BindingContext.DESCRIPTOR_TO_NAMED_RECEIVERS,
|
||||
BindingContext.DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP,
|
||||
if (descriptorOfThisReceiver is PropertyAccessorDescriptor) descriptorOfThisReceiver.correspondingProperty else descriptorOfThisReceiver
|
||||
)
|
||||
return labelNameToReceiverMap?.get(labelName)?.singleOrNull()
|
||||
|
||||
@@ -185,7 +185,7 @@ object LabelResolver {
|
||||
val declarationDescriptor = context.trace.bindingContext[DECLARATION_TO_DESCRIPTOR, element]
|
||||
if (declarationDescriptor is FunctionDescriptor) {
|
||||
val labelNameToReceiverMap = context.trace.bindingContext[
|
||||
DESCRIPTOR_TO_NAMED_RECEIVERS,
|
||||
DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP,
|
||||
if (declarationDescriptor is PropertyAccessorDescriptor) declarationDescriptor.correspondingProperty else declarationDescriptor
|
||||
]
|
||||
val thisReceivers = labelNameToReceiverMap?.get(labelName.identifier)
|
||||
|
||||
Reference in New Issue
Block a user