[FE] Create separate class for context receiver value

This commit is contained in:
Anastasiya Shadrina
2021-09-27 17:33:10 +07:00
committed by TeamCityServer
parent d980136593
commit 1357f28be6
7 changed files with 54 additions and 42 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.*;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.scopes.receivers.ContextReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.Variance;
@@ -189,18 +190,19 @@ public class DescriptorFactory {
@Nullable KotlinType receiverParameterType,
@NotNull Annotations annotations
) {
return createExtensionReceiverParameterForCallable(owner, receiverParameterType, annotations, false);
return receiverParameterType == null
? null
: new ReceiverParameterDescriptorImpl(owner, new ExtensionReceiver(owner, receiverParameterType, null), annotations);
}
@Nullable
public static ReceiverParameterDescriptor createExtensionReceiverParameterForCallable(
public static ReceiverParameterDescriptor createContextReceiverParameterForCallable(
@NotNull CallableDescriptor owner,
@Nullable KotlinType receiverParameterType,
@NotNull Annotations annotations,
boolean isContextReceiver
@NotNull Annotations annotations
) {
return receiverParameterType == null
? null
: new ReceiverParameterDescriptorImpl(owner, new ExtensionReceiver(owner, receiverParameterType, null, isContextReceiver), annotations);
: new ReceiverParameterDescriptorImpl(owner, new ContextReceiver(owner, receiverParameterType, null), annotations);
}
}
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.scopes.receivers
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.types.KotlinType
class ContextReceiver(
override val declarationDescriptor: CallableDescriptor,
receiverType: KotlinType,
original: ReceiverValue?
) : AbstractReceiverValue(receiverType, original), ImplicitReceiver {
override fun replaceType(newType: KotlinType): ReceiverValue = ContextReceiver(declarationDescriptor, newType, original)
override fun toString(): String = "Cxt { $declarationDescriptor }"
}
@@ -35,25 +35,14 @@ import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker;
public class ExtensionReceiver extends AbstractReceiverValue implements ImplicitReceiver {
private final CallableDescriptor descriptor;
private final boolean isContextReceiver;
public ExtensionReceiver(
@NotNull CallableDescriptor callableDescriptor,
@NotNull KotlinType receiverType,
@Nullable ReceiverValue original
) {
this(callableDescriptor, receiverType, original, false);
}
public ExtensionReceiver(
@NotNull CallableDescriptor callableDescriptor,
@NotNull KotlinType receiverType,
@Nullable ReceiverValue original,
boolean isContextReceiver
) {
super(receiverType, original);
this.descriptor = callableDescriptor;
this.isContextReceiver = isContextReceiver;
}
@NotNull
@@ -72,8 +61,4 @@ public class ExtensionReceiver extends AbstractReceiverValue implements Implicit
public String toString() {
return getType() + ": Ext {" + descriptor + "}";
}
public boolean isContextReceiver() {
return isContextReceiver;
}
}