[FE] Create separate class for context receiver value
This commit is contained in:
committed by
TeamCityServer
parent
d980136593
commit
1357f28be6
@@ -965,8 +965,8 @@ public class DescriptorResolver {
|
||||
receiverType = typeResolver.resolveType(scopeForDeclarationResolutionWithTypeParameters, receiverTypeRef, trace, true);
|
||||
AnnotationSplitter splitter = new AnnotationSplitter(storageManager, receiverType.getAnnotations(), EnumSet.of(RECEIVER));
|
||||
receiverDescriptor = DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||
propertyDescriptor, receiverType, splitter.getAnnotationsForTarget(RECEIVER),
|
||||
false);
|
||||
propertyDescriptor, receiverType, splitter.getAnnotationsForTarget(RECEIVER)
|
||||
);
|
||||
receiverToLabelMap.put(receiverDescriptor, receiverTypeRef.nameForReceiverLabel());
|
||||
}
|
||||
|
||||
@@ -1046,9 +1046,9 @@ public class DescriptorResolver {
|
||||
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.createExtensionReceiverParameterForCallable(
|
||||
propertyDescriptor, receiverType, splitter.getAnnotationsForTarget(RECEIVER),
|
||||
true);
|
||||
ReceiverParameterDescriptor receiverDescriptor = DescriptorFactory.createContextReceiverParameterForCallable(
|
||||
propertyDescriptor, receiverType, splitter.getAnnotationsForTarget(RECEIVER)
|
||||
);
|
||||
String contextReceiverName = contextReceiver.name();
|
||||
if (contextReceiverName != null) {
|
||||
receiverToLabelMap.put(receiverDescriptor, contextReceiverName);
|
||||
|
||||
@@ -232,7 +232,7 @@ class FunctionDescriptorResolver(
|
||||
val extensionReceiver = receiverType?.let {
|
||||
val splitter = AnnotationSplitter(storageManager, receiverType.annotations, EnumSet.of(AnnotationUseSiteTarget.RECEIVER))
|
||||
DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||
functionDescriptor, it, splitter.getAnnotationsForTarget(AnnotationUseSiteTarget.RECEIVER), false
|
||||
functionDescriptor, it, splitter.getAnnotationsForTarget(AnnotationUseSiteTarget.RECEIVER)
|
||||
)
|
||||
}?.apply {
|
||||
val extensionReceiverName = receiverTypeRef?.nameForReceiverLabel()
|
||||
@@ -243,15 +243,16 @@ class FunctionDescriptorResolver(
|
||||
|
||||
val contextReceiverDescriptors = contextReceiverTypes.mapNotNull { type ->
|
||||
val splitter = AnnotationSplitter(storageManager, type.annotations, EnumSet.of(AnnotationUseSiteTarget.RECEIVER))
|
||||
DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||
functionDescriptor, type, splitter.getAnnotationsForTarget(AnnotationUseSiteTarget.RECEIVER), true
|
||||
DescriptorFactory.createContextReceiverParameterForCallable(
|
||||
functionDescriptor, type, splitter.getAnnotationsForTarget(AnnotationUseSiteTarget.RECEIVER)
|
||||
)
|
||||
}
|
||||
contextReceiverDescriptors.reversed().zip(contextReceivers.lastIndex downTo 0).forEach { (contextReceiverDescriptor, i) ->
|
||||
contextReceivers[i].name()?.let {
|
||||
receiverToLabelMap[contextReceiverDescriptor] = it
|
||||
contextReceiverDescriptors.zip(0 until contextReceivers.size).reversed()
|
||||
.forEach { (contextReceiverDescriptor, i) ->
|
||||
contextReceivers[i].name()?.let {
|
||||
receiverToLabelMap[contextReceiverDescriptor] = it
|
||||
}
|
||||
}
|
||||
}
|
||||
trace.record(BindingContext.DESCRIPTOR_TO_NAMED_RECEIVERS, functionDescriptor, receiverToLabelMap)
|
||||
functionDescriptor.initialize(
|
||||
extensionReceiver,
|
||||
|
||||
+2
-1
@@ -66,6 +66,7 @@ import org.jetbrains.kotlin.resolve.checkers.UnderscoreChecker;
|
||||
import org.jetbrains.kotlin.resolve.constants.*;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ContextReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
@@ -599,7 +600,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
else if (!receivers.isEmpty()) {
|
||||
// `this` cannot point to context receiver
|
||||
for (ReceiverParameterDescriptor receiver : receivers) {
|
||||
if (!(receiver.getValue() instanceof ExtensionReceiver) || !((ExtensionReceiver) receiver.getValue()).isContextReceiver()) {
|
||||
if (!(receiver.getValue() instanceof ContextReceiver)) {
|
||||
result = receiver;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user