Add method replaceType for ReceiverValue.

This method will used for capturing from expressions before call resolution.
This commit is contained in:
Stanislav Erokhin
2017-04-06 12:32:46 +03:00
parent 1dcdb72a49
commit e8501c7d54
8 changed files with 49 additions and 2 deletions
@@ -28,6 +28,8 @@ interface ExpressionReceiver : ReceiverValue {
private open class ExpressionReceiverImpl(
override val expression: KtExpression, type: KotlinType
): AbstractReceiverValue(type), ExpressionReceiver {
override fun replaceType(newType: KotlinType) = ExpressionReceiverImpl(expression, newType)
override fun toString() = "$type {$expression: ${expression.text}}"
}
@@ -35,13 +37,17 @@ interface ExpressionReceiver : ReceiverValue {
override val classDescriptor: ClassDescriptor,
expression: KtExpression,
type: KotlinType
) : ExpressionReceiverImpl(expression, type), ThisClassReceiver
) : ExpressionReceiverImpl(expression, type), ThisClassReceiver {
override fun replaceType(newType: KotlinType) = ThisExpressionClassReceiver(classDescriptor, expression, newType)
}
private class SuperExpressionReceiver(
override val thisType: KotlinType,
expression: KtExpression,
type: KotlinType
) : ExpressionReceiverImpl(expression, type), SuperCallReceiverValue
) : ExpressionReceiverImpl(expression, type), SuperCallReceiverValue {
override fun replaceType(newType: KotlinType) = SuperExpressionReceiver(thisType, expression, newType)
}
fun create(
expression: KtExpression,
@@ -125,4 +125,6 @@ class ClassValueReceiver(val classQualifier: ClassifierQualifier, private val ty
override val expression: KtExpression
get() = classQualifier.expression
override fun replaceType(newType: KotlinType) = ClassValueReceiver(classQualifier, newType)
}
@@ -26,4 +26,5 @@ fun getReceiverValueWithSmartCast(
private class SmartCastReceiverValue(private val type: KotlinType) : ReceiverValue {
override fun getType() = type
override fun replaceType(newType: KotlinType) = SmartCastReceiverValue(newType)
}
@@ -396,6 +396,12 @@ public class Visibilities {
public KotlinType getType() {
throw new IllegalStateException("This method should not be called");
}
@NotNull
@Override
public ReceiverValue replaceType(@NotNull KotlinType newType) {
throw new IllegalStateException("This method should not be called");
}
};
/**
@@ -408,6 +414,12 @@ public class Visibilities {
public KotlinType getType() {
throw new IllegalStateException("This method should not be called");
}
@NotNull
@Override
public ReceiverValue replaceType(@NotNull KotlinType newType) {
throw new IllegalStateException("This method should not be called");
}
};
// This constant is not intended to use somewhere else from
@@ -418,6 +430,12 @@ public class Visibilities {
public KotlinType getType() {
throw new IllegalStateException("This method should not be called");
}
@NotNull
@Override
public ReceiverValue replaceType(@NotNull KotlinType newType) {
throw new IllegalStateException("This method should not be called");
}
};
public static boolean isPrivate(@NotNull Visibility visibility) {
@@ -35,6 +35,12 @@ public class ExtensionReceiver extends AbstractReceiverValue implements Implicit
return descriptor;
}
@NotNull
@Override
public ReceiverValue replaceType(@NotNull KotlinType newType) {
return new ExtensionReceiver(descriptor, newType);
}
@Override
public String toString() {
return getType() + ": Ext {" + descriptor + "}";
@@ -17,6 +17,8 @@
package org.jetbrains.kotlin.resolve.scopes.receivers
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.types.KotlinType
import java.lang.UnsupportedOperationException
/**
* Describes any "this" receiver inside a class
@@ -39,4 +41,7 @@ open class ImplicitClassReceiver(final override val classDescriptor: ClassDescri
override fun hashCode() = classDescriptor.hashCode()
override fun toString() = "Class{$type}"
override fun replaceType(newType: KotlinType) =
throw UnsupportedOperationException("Replace type should not be called for this receiver")
}
@@ -23,4 +23,7 @@ public interface ReceiverValue extends Receiver {
@NotNull
KotlinType getType();
@NotNull
ReceiverValue replaceType(@NotNull KotlinType newType);
}
@@ -32,4 +32,10 @@ public class TransientReceiver extends AbstractReceiverValue {
public String toString() {
return "{Transient} : " + getType();
}
@NotNull
@Override
public ReceiverValue replaceType(@NotNull KotlinType newType) {
return new TransientReceiver(newType);
}
}