Refactoring. Remove isSafeCall from ResolvedCall.

This commit is contained in:
Stanislav Erokhin
2016-03-31 15:32:14 +03:00
parent bf08341ee4
commit 516d4df834
8 changed files with 11 additions and 19 deletions
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
import org.jetbrains.kotlin.resolve.bindingContextUtil.getTargetFunctionDescriptor
import org.jetbrains.kotlin.resolve.calls.ValueArgumentsToParametersMapper
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getExplicitReceiverValue
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
@@ -61,7 +62,7 @@ fun getReceiverTypePredicate(resolvedCall: ResolvedCall<*>, receiverValue: Recei
resolvedCall.getDispatchReceiver() -> {
val rootCallableDescriptors = callableDescriptor.findTopMostOverriddenDescriptors()
return or(rootCallableDescriptors.mapNotNull {
it.getDispatchReceiverParameter()?.getType()?.let { TypeUtils.makeNullableIfNeeded(it, resolvedCall.isSafeCall()) }?.getSubtypesPredicate()
it.getDispatchReceiverParameter()?.getType()?.let { TypeUtils.makeNullableIfNeeded(it, resolvedCall.call.isSafeCall()) }?.getSubtypesPredicate()
})
}
}
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.callResolverUtil.*
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode.SHAPE_FUNCTION_ARGUMENTS
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
import org.jetbrains.kotlin.resolve.calls.context.CallCandidateResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency.INDEPENDENT
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
@@ -79,7 +80,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
val receiverParameter = candidate.extensionReceiverParameter
if (receiverArgument != null && receiverParameter != null) {
val receiverArgumentType = receiverArgument.type
var receiverType: KotlinType? = if (context.candidateCall.isSafeCall)
var receiverType: KotlinType? = if (context.candidateCall.call.isSafeCall())
TypeUtils.makeNotNullable(receiverArgumentType)
else
receiverArgumentType
@@ -110,11 +110,6 @@ public abstract class DelegatingResolvedCall<D extends CallableDescriptor> imple
return resolvedCall.getDataFlowInfoForArguments();
}
@Override
public boolean isSafeCall() {
return resolvedCall.isSafeCall();
}
@Nullable
@Override
public KotlinType getSmartCastDispatchReceiverType() {
@@ -79,8 +79,6 @@ public interface ResolvedCall<D extends CallableDescriptor> {
@NotNull
DataFlowInfoForArguments getDataFlowInfoForArguments();
boolean isSafeCall();
@Nullable
KotlinType getSmartCastDispatchReceiverType();
}
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.psi.Call;
import org.jetbrains.kotlin.psi.ValueArgument;
import org.jetbrains.kotlin.resolve.DelegatingBindingTrace;
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilKt;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem;
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
@@ -348,11 +347,6 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
return typeArguments;
}
@Override
public boolean isSafeCall() {
return CallUtilKt.isSafeCall(call);
}
@NotNull
@Override
public MutableDataFlowInfoForArguments getDataFlowInfoForArguments() {
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.psi.KtPsiUtil
import org.jetbrains.kotlin.psi.KtThisExpression
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
import org.jetbrains.kotlin.resolve.calls.context.CallResolutionContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
@@ -78,7 +79,7 @@ fun ResolvedCall<*>.getImplicitReceiverValue(): ReceiverValue? {
}
private fun ResolvedCall<*>.hasSafeNullableReceiver(context: CallResolutionContext<*>): Boolean {
if (!isSafeCall) return false
if (!call.isSafeCall()) return false
val receiverValue = getExplicitReceiverValue()?.let { DataFlowValueFactory.createDataFlowValue(it, context) }
?: return false
return context.dataFlowInfo.getPredictableNullability(receiverValue).canBeNull()
@@ -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.
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
@@ -262,7 +263,7 @@ class KotlinPsiUnifier(
!checkSpecialOperations() -> UNMATCHED
!matchDescriptors(rc1.candidateDescriptor, rc2.candidateDescriptor) -> UNMATCHED
!checkReceivers() -> UNMATCHED
rc1.isSafeCall != rc2.isSafeCall -> UNMATCHED
rc1.call.isSafeCall() != rc2.call.isSafeCall() -> UNMATCHED
else -> {
val s = checkTypeArguments()
if (s != MATCHED) s else checkArguments()
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.js.translate.reference.CallArgumentTranslator
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils.getReceiverParameterForReceiver
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
@@ -126,7 +127,7 @@ private fun TranslationContext.createCallInfo(resolvedCall: ResolvedCall<out Cal
var extensionReceiver = getExtensionReceiver()
var notNullConditional: JsConditional? = null
if (resolvedCall.isSafeCall) {
if (resolvedCall.call.isSafeCall()) {
when (resolvedCall.explicitReceiverKind) {
BOTH_RECEIVERS, EXTENSION_RECEIVER -> {
notNullConditional = TranslationUtils.notNullConditional(extensionReceiver!!, JsLiteral.NULL, this)