ThisReceiver converted to Kotlin
This commit is contained in:
@@ -55,7 +55,7 @@ private fun ResolvedCall<*>.hasThisOrNoDispatchReceiver(
|
||||
var dispatchReceiverDescriptor: DeclarationDescriptor? = null
|
||||
if (dispatchReceiverValue is ThisReceiver) {
|
||||
// foo() -- implicit receiver
|
||||
dispatchReceiverDescriptor = dispatchReceiverValue.getDeclarationDescriptor()
|
||||
dispatchReceiverDescriptor = dispatchReceiverValue.declarationDescriptor
|
||||
}
|
||||
else if (dispatchReceiverValue is ExpressionReceiver && considerExplicitReceivers) {
|
||||
val expression = KtPsiUtil.deparenthesize(dispatchReceiverValue.expression)
|
||||
|
||||
@@ -78,7 +78,7 @@ public abstract class AbstractResolvedCallsTest : KotlinLiteFixture() {
|
||||
private fun ReceiverValue.getText() = when (this) {
|
||||
is ExpressionReceiver -> "${expression.getText()} {${getType()}}"
|
||||
is ClassReceiver -> "Class{${getType()}}"
|
||||
is ExtensionReceiver -> "${getType()}Ext{${getDeclarationDescriptor().getText()}}"
|
||||
is ExtensionReceiver -> "${getType()}Ext{${declarationDescriptor.getText()}}"
|
||||
else -> toString()
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ open class ClassReceiver(override val classDescriptor: ClassDescriptor) : Expres
|
||||
|
||||
override fun getType() = classDescriptor.defaultType
|
||||
|
||||
override fun getDeclarationDescriptor() = classDescriptor
|
||||
override val declarationDescriptor = classDescriptor
|
||||
|
||||
override fun equals(other: Any?) = classDescriptor == (other as? ClassReceiver)?.classDescriptor
|
||||
|
||||
|
||||
+5
-8
@@ -14,16 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.scopes.receivers;
|
||||
package org.jetbrains.kotlin.resolve.scopes.receivers
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
|
||||
/**
|
||||
* Describes a "this" receiver
|
||||
* Describes an implicit "this" receiver
|
||||
*/
|
||||
public interface ThisReceiver extends ReceiverValue {
|
||||
@NotNull
|
||||
DeclarationDescriptor getDeclarationDescriptor();
|
||||
interface ThisReceiver : ReceiverValue {
|
||||
val declarationDescriptor: DeclarationDescriptor
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public fun ReceiverValue.getThisReceiverOwner(bindingContext: BindingContext): D
|
||||
bindingContext[BindingContext.REFERENCE_TARGET, thisRef]
|
||||
}
|
||||
|
||||
is ThisReceiver -> this.getDeclarationDescriptor()
|
||||
is ThisReceiver -> this.declarationDescriptor
|
||||
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ public class ShortenReferences(val options: (KtElement) -> Options = { Options.D
|
||||
} as? ThisReceiver ?: return false
|
||||
|
||||
val thisTarget = receiver.getInstanceReference().targets(bindingContext).singleOrNull()
|
||||
if (newReceiver.getDeclarationDescriptor().asString() != thisTarget?.asString()) return false
|
||||
if (newReceiver.declarationDescriptor.asString() != thisTarget?.asString()) return false
|
||||
}
|
||||
|
||||
if (!targetsMatch && targetsWhenShort.any { it !is ClassDescriptor && it !is PackageViewDescriptor }) {
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ fun renderDataFlowValue(value: DataFlowValue): String? {
|
||||
fun renderId(id: Any?): String? {
|
||||
return when (id) {
|
||||
is KtExpression -> id.getText()
|
||||
is ThisReceiver -> "this@${id.getDeclarationDescriptor().getName()}"
|
||||
is ThisReceiver -> "this@${id.declarationDescriptor.getName()}"
|
||||
is VariableDescriptor -> id.getName().asString()
|
||||
is PackageViewDescriptor -> id.fqName.asString()
|
||||
is com.intellij.openapi.util.Pair<*, *> -> renderId(id.first) + "." + renderId(id.second)
|
||||
|
||||
@@ -91,7 +91,7 @@ public fun Call.mapArgumentsToParameters(targetDescriptor: CallableDescriptor):
|
||||
public fun ThisReceiver.asExpression(resolutionScope: LexicalScope, psiFactory: KtPsiFactory): KtExpression? {
|
||||
val expressionFactory = resolutionScope.getImplicitReceiversWithInstanceToExpression()
|
||||
.entrySet()
|
||||
.firstOrNull { it.key.getContainingDeclaration() == this.getDeclarationDescriptor() }
|
||||
.firstOrNull { it.key.getContainingDeclaration() == this.declarationDescriptor }
|
||||
?.value ?: return null
|
||||
return expressionFactory.createExpression(psiFactory)
|
||||
}
|
||||
|
||||
+2
-2
@@ -163,8 +163,8 @@ public class KotlinFindClassUsagesHandler(
|
||||
|
||||
val bindingContext = element.analyze()
|
||||
val resolvedCall = bindingContext[BindingContext.CALL, element]?.getResolvedCall(bindingContext) ?: return
|
||||
if ((resolvedCall.getDispatchReceiver() as? ClassReceiver)?.getDeclarationDescriptor() == companionObjectDescriptor
|
||||
|| (resolvedCall.getExtensionReceiver() as? ClassReceiver)?.getDeclarationDescriptor() == companionObjectDescriptor) {
|
||||
if ((resolvedCall.getDispatchReceiver() as? ClassReceiver)?.declarationDescriptor == companionObjectDescriptor
|
||||
|| (resolvedCall.getExtensionReceiver() as? ClassReceiver)?.declarationDescriptor == companionObjectDescriptor) {
|
||||
element.getReferences().forEach {
|
||||
if (!stop && !processor.process(it)) {
|
||||
stop = true
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ public class KotlinParameterInfo @JvmOverloads constructor (
|
||||
}
|
||||
|
||||
private fun selfReceiverOrNull(receiver: ThisReceiver?): DeclarationDescriptor? {
|
||||
return selfReceiverOrNull(receiver?.getDeclarationDescriptor())
|
||||
return selfReceiverOrNull(receiver?.declarationDescriptor)
|
||||
}
|
||||
|
||||
private fun getRelevantDescriptor(
|
||||
|
||||
+1
-1
@@ -210,7 +210,7 @@ data class ExtractionData(
|
||||
smartCast = originalContext[BindingContext.SMARTCAST, smartCastTarget]
|
||||
possibleTypes = getPossibleTypes(smartCastTarget, originalResolveResult.resolvedCall, originalContext)
|
||||
val receiverDescriptor =
|
||||
(originalResolveResult.resolvedCall?.getDispatchReceiver() as? ThisReceiver)?.getDeclarationDescriptor()
|
||||
(originalResolveResult.resolvedCall?.getDispatchReceiver() as? ThisReceiver)?.declarationDescriptor
|
||||
if (smartCast == null
|
||||
&& !DescriptorUtils.isCompanionObject(receiverDescriptor)
|
||||
&& qualifiedExpression.getReceiverExpression() !is KtSuperExpression) continue
|
||||
|
||||
+2
-2
@@ -394,8 +394,8 @@ private fun findInternalUsagesOfParametersAndReceiver(
|
||||
val bindingContext = element.analyze()
|
||||
val resolvedCall = element.getResolvedCall(bindingContext) ?: return
|
||||
|
||||
if ((resolvedCall.getExtensionReceiver() as? ThisReceiver)?.getDeclarationDescriptor() == targetDescriptor ||
|
||||
(resolvedCall.getDispatchReceiver() as? ThisReceiver)?.getDeclarationDescriptor() == targetDescriptor) {
|
||||
if ((resolvedCall.getExtensionReceiver() as? ThisReceiver)?.declarationDescriptor == targetDescriptor ||
|
||||
(resolvedCall.getDispatchReceiver() as? ThisReceiver)?.declarationDescriptor == targetDescriptor) {
|
||||
usages.putValue(receiverTypeRef, resolvedCall.getCall().getCallElement())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class KotlinPsiUnifier(
|
||||
doUnify(rv1.expression, rv2.expression) == MATCHED
|
||||
|
||||
rv1 is ThisReceiver && rv2 is ThisReceiver ->
|
||||
matchDescriptors(rv1.getDeclarationDescriptor(), rv2.getDeclarationDescriptor())
|
||||
matchDescriptors(rv1.declarationDescriptor, rv2.declarationDescriptor)
|
||||
|
||||
else ->
|
||||
rv1 == rv2
|
||||
@@ -215,7 +215,7 @@ public class KotlinPsiUnifier(
|
||||
if (implicitReceiver == null || thisExpression == null) return false
|
||||
|
||||
return matchDescriptors(
|
||||
implicitReceiver.getDeclarationDescriptor(),
|
||||
implicitReceiver.declarationDescriptor,
|
||||
thisExpression.getAdjustedResolvedCall()?.getCandidateDescriptor()?.getContainingDeclaration()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user