Add method replaceType for ReceiverValue.
This method will used for capturing from expressions before call resolution.
This commit is contained in:
+8
-2
@@ -28,6 +28,8 @@ interface ExpressionReceiver : ReceiverValue {
|
|||||||
private open class ExpressionReceiverImpl(
|
private open class ExpressionReceiverImpl(
|
||||||
override val expression: KtExpression, type: KotlinType
|
override val expression: KtExpression, type: KotlinType
|
||||||
): AbstractReceiverValue(type), ExpressionReceiver {
|
): AbstractReceiverValue(type), ExpressionReceiver {
|
||||||
|
override fun replaceType(newType: KotlinType) = ExpressionReceiverImpl(expression, newType)
|
||||||
|
|
||||||
override fun toString() = "$type {$expression: ${expression.text}}"
|
override fun toString() = "$type {$expression: ${expression.text}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,13 +37,17 @@ interface ExpressionReceiver : ReceiverValue {
|
|||||||
override val classDescriptor: ClassDescriptor,
|
override val classDescriptor: ClassDescriptor,
|
||||||
expression: KtExpression,
|
expression: KtExpression,
|
||||||
type: KotlinType
|
type: KotlinType
|
||||||
) : ExpressionReceiverImpl(expression, type), ThisClassReceiver
|
) : ExpressionReceiverImpl(expression, type), ThisClassReceiver {
|
||||||
|
override fun replaceType(newType: KotlinType) = ThisExpressionClassReceiver(classDescriptor, expression, newType)
|
||||||
|
}
|
||||||
|
|
||||||
private class SuperExpressionReceiver(
|
private class SuperExpressionReceiver(
|
||||||
override val thisType: KotlinType,
|
override val thisType: KotlinType,
|
||||||
expression: KtExpression,
|
expression: KtExpression,
|
||||||
type: KotlinType
|
type: KotlinType
|
||||||
) : ExpressionReceiverImpl(expression, type), SuperCallReceiverValue
|
) : ExpressionReceiverImpl(expression, type), SuperCallReceiverValue {
|
||||||
|
override fun replaceType(newType: KotlinType) = SuperExpressionReceiver(thisType, expression, newType)
|
||||||
|
}
|
||||||
|
|
||||||
fun create(
|
fun create(
|
||||||
expression: KtExpression,
|
expression: KtExpression,
|
||||||
|
|||||||
@@ -125,4 +125,6 @@ class ClassValueReceiver(val classQualifier: ClassifierQualifier, private val ty
|
|||||||
|
|
||||||
override val expression: KtExpression
|
override val expression: KtExpression
|
||||||
get() = classQualifier.expression
|
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 {
|
private class SmartCastReceiverValue(private val type: KotlinType) : ReceiverValue {
|
||||||
override fun getType() = type
|
override fun getType() = type
|
||||||
|
override fun replaceType(newType: KotlinType) = SmartCastReceiverValue(newType)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -396,6 +396,12 @@ public class Visibilities {
|
|||||||
public KotlinType getType() {
|
public KotlinType getType() {
|
||||||
throw new IllegalStateException("This method should not be called");
|
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() {
|
public KotlinType getType() {
|
||||||
throw new IllegalStateException("This method should not be called");
|
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
|
// This constant is not intended to use somewhere else from
|
||||||
@@ -418,6 +430,12 @@ public class Visibilities {
|
|||||||
public KotlinType getType() {
|
public KotlinType getType() {
|
||||||
throw new IllegalStateException("This method should not be called");
|
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) {
|
public static boolean isPrivate(@NotNull Visibility visibility) {
|
||||||
|
|||||||
+6
@@ -35,6 +35,12 @@ public class ExtensionReceiver extends AbstractReceiverValue implements Implicit
|
|||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverValue replaceType(@NotNull KotlinType newType) {
|
||||||
|
return new ExtensionReceiver(descriptor, newType);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getType() + ": Ext {" + descriptor + "}";
|
return getType() + ": Ext {" + descriptor + "}";
|
||||||
|
|||||||
+5
@@ -17,6 +17,8 @@
|
|||||||
package org.jetbrains.kotlin.resolve.scopes.receivers
|
package org.jetbrains.kotlin.resolve.scopes.receivers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import java.lang.UnsupportedOperationException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes any "this" receiver inside a class
|
* 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 hashCode() = classDescriptor.hashCode()
|
||||||
|
|
||||||
override fun toString() = "Class{$type}"
|
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
|
@NotNull
|
||||||
KotlinType getType();
|
KotlinType getType();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
ReceiverValue replaceType(@NotNull KotlinType newType);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -32,4 +32,10 @@ public class TransientReceiver extends AbstractReceiverValue {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "{Transient} : " + getType();
|
return "{Transient} : " + getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverValue replaceType(@NotNull KotlinType newType) {
|
||||||
|
return new TransientReceiver(newType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user