Refactoring. Change type of ResolvedCall#extensionReceiver from Receiver to ReceiverValue

This commit is contained in:
Stanislav Erokhin
2016-03-29 21:27:31 +03:00
parent 63a2d8a416
commit bf08341ee4
19 changed files with 40 additions and 53 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1219,7 +1219,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ResolvedCall<? extends CallableDescriptor> call = CallUtilKt.getResolvedCall(expr, bindingContext);
if (call != null) {
lookupReceiver(call.getDispatchReceiver());
lookupReceiver((ReceiverValue) call.getExtensionReceiver());
lookupReceiver(call.getExtensionReceiver());
}
}
else if (descriptor instanceof VariableDescriptor) {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -504,7 +504,7 @@ public abstract class StackValue {
callDispatchReceiver = ((SyntheticFieldDescriptor) descriptor).getDispatchReceiverForBackend();
}
ReceiverValue callExtensionReceiver = (ReceiverValue) resolvedCall.getExtensionReceiver();
ReceiverValue callExtensionReceiver = resolvedCall.getExtensionReceiver();
if (callDispatchReceiver != null || callExtensionReceiver != null
|| isLocalFunCall(callableMethod) || isCallToMemberObjectImportedByName(resolvedCall)) {
ReceiverParameterDescriptor dispatchReceiverParameter = descriptor.getDispatchReceiverParameter();
@@ -850,7 +850,7 @@ public abstract class StackValue {
v.store(firstParamIndex, type);
}
ReceiverValue receiverParameter = (ReceiverValue) resolvedGetCall.getExtensionReceiver();
ReceiverValue receiverParameter = resolvedGetCall.getExtensionReceiver();
int receiverIndex = -1;
if (receiverParameter != null) {
Type type = codegen.typeMapper.mapType(receiverParameter.getType());
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,14 +25,13 @@ import org.jetbrains.kotlin.psi.KtClassLiteralExpression
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
class KClassJavaProperty : IntrinsicPropertyGetter() {
override fun generate(resolvedCall: ResolvedCall<*>?, codegen: ExpressionCodegen, returnType: Type, receiver: StackValue): StackValue? {
val extensionReceiver = resolvedCall!!.extensionReceiver as ReceiverValue
val extensionReceiver = resolvedCall!!.extensionReceiver!!
val type = extensionReceiver.type.arguments.single().type
val asmType = codegen.state.typeMapper.mapType(type)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1402,7 +1402,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
//noinspection EnumSwitchStatementWhichMissesCases
when (kind) {
ExplicitReceiverKind.DISPATCH_RECEIVER -> explicitReceiver = resolvedCall.dispatchReceiver
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> explicitReceiver = resolvedCall.extensionReceiver as ReceiverValue?
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> explicitReceiver = resolvedCall.extensionReceiver
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> {}
}
}
@@ -1413,7 +1413,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
}
val callElement = resolvedCall.call.callElement
receiverValues = getReceiverValues(callElement, resolvedCall.dispatchReceiver, receiverValues)
receiverValues = getReceiverValues(callElement, resolvedCall.extensionReceiver as ReceiverValue?, receiverValues)
receiverValues = getReceiverValues(callElement, resolvedCall.extensionReceiver, receiverValues)
return receiverValues
}
@@ -40,7 +40,6 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsImpl
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
@@ -214,7 +213,7 @@ class CallCompleter(
return
}
val receiverType = (extensionReceiver as? ReceiverValue)?.type
val receiverType = extensionReceiver?.type
val errorData = InferenceErrorData.create(
candidateDescriptor, constraintSystem!!, valueArgumentsCheckingResult.argumentTypes,
@@ -452,7 +452,7 @@ class CandidateResolver(
resultStatus = resultStatus.combine(context.checkReceiver(
candidateCall,
candidateCall.getResultingDescriptor().extensionReceiverParameter,
candidateCall.extensionReceiver as ReceiverValue?,
candidateCall.extensionReceiver,
candidateCall.explicitReceiverKind.isExtensionReceiver,
implicitInvokeCheck = false, isDispatchReceiver = false))
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,6 @@ import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus.INCOMPLETE_TY
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus.OTHER_ERROR
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
@@ -79,7 +78,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
val receiverArgument = candidateCall.extensionReceiver
val receiverParameter = candidate.extensionReceiverParameter
if (receiverArgument != null && receiverParameter != null) {
val receiverArgumentType = (receiverArgument as ReceiverValue).type
val receiverArgumentType = receiverArgument.type
var receiverType: KotlinType? = if (context.candidateCall.isSafeCall)
TypeUtils.makeNotNullable(receiverArgumentType)
else
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ class InlineChecker implements CallChecker {
//checking that only invoke or inlinable extension called on function parameter
CallableDescriptor targetDescriptor = resolvedCall.getResultingDescriptor();
checkCallWithReceiver(context, targetDescriptor, resolvedCall.getDispatchReceiver(), expression);
checkCallWithReceiver(context, targetDescriptor, (ReceiverValue) resolvedCall.getExtensionReceiver(), expression);
checkCallWithReceiver(context, targetDescriptor, resolvedCall.getExtensionReceiver(), expression);
if (inlinableParameters.contains(targetDescriptor)) {
if (!isInsideCall(expression)) {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.psi.Call;
import org.jetbrains.kotlin.psi.ValueArgument;
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.KotlinType;
@@ -65,7 +64,7 @@ public abstract class DelegatingResolvedCall<D extends CallableDescriptor> imple
@Nullable
@Override
public Receiver getExtensionReceiver() {
public ReceiverValue getExtensionReceiver() {
return resolvedCall.getExtensionReceiver();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.psi.Call;
import org.jetbrains.kotlin.psi.ValueArgument;
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.KotlinType;
@@ -50,7 +49,7 @@ public interface ResolvedCall<D extends CallableDescriptor> {
/** If the target was an extension function or property, this is the value for its receiver parameter */
@Nullable
Receiver getExtensionReceiver();
ReceiverValue getExtensionReceiver();
/** If the target was a member of a class, this is the object of that class to call it on */
@Nullable
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate;
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.TypeProjection;
@@ -77,7 +76,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
private final D candidateDescriptor;
private D resultingDescriptor; // Probably substituted
private final ReceiverValue dispatchReceiver; // receiver object of a method
private final Receiver extensionReceiver; // receiver of an extension function
private final ReceiverValue extensionReceiver; // receiver of an extension function
private final ExplicitReceiverKind explicitReceiverKind;
private final TypeSubstitutor knownTypeParametersSubstitutor;
@@ -275,7 +274,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
@Override
@Nullable
public Receiver getExtensionReceiver() {
public ReceiverValue getExtensionReceiver() {
return extensionReceiver;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,15 +63,15 @@ fun ResolvedCall<*>.hasThisOrNoDispatchReceiver(
fun ResolvedCall<*>.getExplicitReceiverValue(): ReceiverValue? {
return when (explicitReceiverKind) {
ExplicitReceiverKind.DISPATCH_RECEIVER -> dispatchReceiver!!
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> extensionReceiver as ReceiverValue
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> extensionReceiver!!
else -> null
}
}
fun ResolvedCall<*>.getImplicitReceiverValue(): ReceiverValue? {
return when (explicitReceiverKind) {
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> if (extensionReceiver != null) extensionReceiver as ReceiverValue else dispatchReceiver
ExplicitReceiverKind.DISPATCH_RECEIVER -> extensionReceiver as ReceiverValue?
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> extensionReceiver ?: dispatchReceiver
ExplicitReceiverKind.DISPATCH_RECEIVER -> extensionReceiver
ExplicitReceiverKind.EXTENSION_RECEIVER -> dispatchReceiver
else -> null
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.constants.*
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
@@ -860,7 +859,7 @@ fun isIntegerType(value: Any?) = value is Byte || value is Short || value is Int
private fun getReceiverExpressionType(resolvedCall: ResolvedCall<*>): KotlinType? {
return when (resolvedCall.explicitReceiverKind) {
ExplicitReceiverKind.DISPATCH_RECEIVER -> resolvedCall.dispatchReceiver!!.type
ExplicitReceiverKind.EXTENSION_RECEIVER -> (resolvedCall.extensionReceiver as ReceiverValue).type
ExplicitReceiverKind.EXTENSION_RECEIVER -> resolvedCall.extensionReceiver!!.type
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> null
ExplicitReceiverKind.BOTH_RECEIVERS -> null
else -> null
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
override val suppressionKey: String get() = "unused"
@@ -69,7 +68,7 @@ class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
private fun isUsageOfReceiver(resolvedCall: ResolvedCall<*>, bindingContext: BindingContext): Boolean {
// As receiver of call
if (resolvedCall.dispatchReceiver.getThisReceiverOwner(bindingContext) == callable ||
(resolvedCall.extensionReceiver as ReceiverValue?).getThisReceiverOwner(bindingContext) == callable) {
resolvedCall.extensionReceiver.getThisReceiverOwner(bindingContext) == callable) {
return true
}
// As explicit "this"
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
class AddTypeToLHSOfCallableReferenceFix(
expression: KtCallableReferenceExpression
@@ -39,7 +38,7 @@ class AddTypeToLHSOfCallableReferenceFix(
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
val resolvedCall = element.callableReference.getResolvedCall(element.analyze(BodyResolveMode.PARTIAL)) ?: return
val receiver = with(resolvedCall) {
dispatchReceiver ?: extensionReceiver as? ReceiverValue ?: return
dispatchReceiver ?: extensionReceiver ?: return
}
val type = KtPsiFactory(project).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(receiver.type))
element.setTypeReference(type)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -191,11 +191,8 @@ class KotlinFunctionCallUsage(
}
else {
addReceiver = descriptor !is ReceiverParameterDescriptor
val extensionReceiver = resolvedCall.extensionReceiver
argumentExpression =
(if (extensionReceiver is ReceiverValue)
getReceiverExpressionIfMatched(extensionReceiver, descriptor, psiFactory)
else null)
getReceiverExpressionIfMatched(resolvedCall.extensionReceiver, descriptor, psiFactory)
?: getReceiverExpressionIfMatched(resolvedCall.dispatchReceiver, descriptor, psiFactory)
}
if (argumentExpression == null) continue
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -118,7 +118,7 @@ private fun TranslationContext.createCallInfo(resolvedCall: ResolvedCall<out Cal
return when (receiverKind) {
EXTENSION_RECEIVER -> explicitReceivers.extensionOrDispatchReceiver
BOTH_RECEIVERS -> explicitReceivers.extensionReceiver
else -> this.getDispatchReceiver(receiverValue as ReceiverValue)
else -> this.getDispatchReceiver(receiverValue)
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -148,7 +148,7 @@ fun computeExplicitReceiversForInvoke(
return when (Pair(dispatchReceiver != null, extensionReceiver != null)) {
Pair(true, true) -> ExplicitReceivers(dispatchReceiverExpression, explicitReceivers.extensionOrDispatchReceiver)
Pair(true, false) -> ExplicitReceivers(dispatchReceiverExpression)
Pair(false, true) -> ExplicitReceivers(translateReceiverAsExpression(extensionReceiver as ReceiverValue))
Pair(false, true) -> ExplicitReceivers(translateReceiverAsExpression(extensionReceiver))
else -> throw AssertionError("'Invoke' resolved call without receivers: $callElement")
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.psi.KtQualifiedExpression;
import org.jetbrains.kotlin.psi.KtReferenceExpression;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.KotlinType;
@@ -127,7 +126,7 @@ public final class TopLevelFIF extends CompositeFIF {
@Nullable
@Override
protected ExpressionReceiver getExpressionReceiver(@NotNull ResolvedCall<?> resolvedCall) {
Receiver result = resolvedCall.getExtensionReceiver();
ReceiverValue result = resolvedCall.getExtensionReceiver();
return result instanceof ExpressionReceiver ? (ExpressionReceiver) result : null;
}