Refactoring. Change type of ResolvedCall#extensionReceiver from Receiver to ReceiverValue
This commit is contained in:
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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);
|
ResolvedCall<? extends CallableDescriptor> call = CallUtilKt.getResolvedCall(expr, bindingContext);
|
||||||
if (call != null) {
|
if (call != null) {
|
||||||
lookupReceiver(call.getDispatchReceiver());
|
lookupReceiver(call.getDispatchReceiver());
|
||||||
lookupReceiver((ReceiverValue) call.getExtensionReceiver());
|
lookupReceiver(call.getExtensionReceiver());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof VariableDescriptor) {
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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();
|
callDispatchReceiver = ((SyntheticFieldDescriptor) descriptor).getDispatchReceiverForBackend();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiverValue callExtensionReceiver = (ReceiverValue) resolvedCall.getExtensionReceiver();
|
ReceiverValue callExtensionReceiver = resolvedCall.getExtensionReceiver();
|
||||||
if (callDispatchReceiver != null || callExtensionReceiver != null
|
if (callDispatchReceiver != null || callExtensionReceiver != null
|
||||||
|| isLocalFunCall(callableMethod) || isCallToMemberObjectImportedByName(resolvedCall)) {
|
|| isLocalFunCall(callableMethod) || isCallToMemberObjectImportedByName(resolvedCall)) {
|
||||||
ReceiverParameterDescriptor dispatchReceiverParameter = descriptor.getDispatchReceiverParameter();
|
ReceiverParameterDescriptor dispatchReceiverParameter = descriptor.getDispatchReceiverParameter();
|
||||||
@@ -850,7 +850,7 @@ public abstract class StackValue {
|
|||||||
v.store(firstParamIndex, type);
|
v.store(firstParamIndex, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiverValue receiverParameter = (ReceiverValue) resolvedGetCall.getExtensionReceiver();
|
ReceiverValue receiverParameter = resolvedGetCall.getExtensionReceiver();
|
||||||
int receiverIndex = -1;
|
int receiverIndex = -1;
|
||||||
if (receiverParameter != null) {
|
if (receiverParameter != null) {
|
||||||
Type type = codegen.typeMapper.mapType(receiverParameter.getType());
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
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.kotlin.types.KotlinType
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
|
|
||||||
class KClassJavaProperty : IntrinsicPropertyGetter() {
|
class KClassJavaProperty : IntrinsicPropertyGetter() {
|
||||||
override fun generate(resolvedCall: ResolvedCall<*>?, codegen: ExpressionCodegen, returnType: Type, receiver: StackValue): StackValue? {
|
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 type = extensionReceiver.type.arguments.single().type
|
||||||
val asmType = codegen.state.typeMapper.mapType(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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
//noinspection EnumSwitchStatementWhichMissesCases
|
||||||
when (kind) {
|
when (kind) {
|
||||||
ExplicitReceiverKind.DISPATCH_RECEIVER -> explicitReceiver = resolvedCall.dispatchReceiver
|
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 -> {}
|
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1413,7 +1413,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
|||||||
}
|
}
|
||||||
val callElement = resolvedCall.call.callElement
|
val callElement = resolvedCall.call.callElement
|
||||||
receiverValues = getReceiverValues(callElement, resolvedCall.dispatchReceiver, receiverValues)
|
receiverValues = getReceiverValues(callElement, resolvedCall.dispatchReceiver, receiverValues)
|
||||||
receiverValues = getReceiverValues(callElement, resolvedCall.extensionReceiver as ReceiverValue?, receiverValues)
|
receiverValues = getReceiverValues(callElement, resolvedCall.extensionReceiver, receiverValues)
|
||||||
return 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.results.ResolutionStatus
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
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.resolve.validation.SymbolUsageValidator
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
@@ -214,7 +213,7 @@ class CallCompleter(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val receiverType = (extensionReceiver as? ReceiverValue)?.type
|
val receiverType = extensionReceiver?.type
|
||||||
|
|
||||||
val errorData = InferenceErrorData.create(
|
val errorData = InferenceErrorData.create(
|
||||||
candidateDescriptor, constraintSystem!!, valueArgumentsCheckingResult.argumentTypes,
|
candidateDescriptor, constraintSystem!!, valueArgumentsCheckingResult.argumentTypes,
|
||||||
|
|||||||
@@ -452,7 +452,7 @@ class CandidateResolver(
|
|||||||
resultStatus = resultStatus.combine(context.checkReceiver(
|
resultStatus = resultStatus.combine(context.checkReceiver(
|
||||||
candidateCall,
|
candidateCall,
|
||||||
candidateCall.getResultingDescriptor().extensionReceiverParameter,
|
candidateCall.getResultingDescriptor().extensionReceiverParameter,
|
||||||
candidateCall.extensionReceiver as ReceiverValue?,
|
candidateCall.extensionReceiver,
|
||||||
candidateCall.explicitReceiverKind.isExtensionReceiver,
|
candidateCall.explicitReceiverKind.isExtensionReceiver,
|
||||||
implicitInvokeCheck = false, isDispatchReceiver = false))
|
implicitInvokeCheck = false, isDispatchReceiver = false))
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.results.ResolutionStatus.OTHER_ERROR
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
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.*
|
||||||
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
|
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
@@ -79,7 +78,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
|
|||||||
val receiverArgument = candidateCall.extensionReceiver
|
val receiverArgument = candidateCall.extensionReceiver
|
||||||
val receiverParameter = candidate.extensionReceiverParameter
|
val receiverParameter = candidate.extensionReceiverParameter
|
||||||
if (receiverArgument != null && receiverParameter != null) {
|
if (receiverArgument != null && receiverParameter != null) {
|
||||||
val receiverArgumentType = (receiverArgument as ReceiverValue).type
|
val receiverArgumentType = receiverArgument.type
|
||||||
var receiverType: KotlinType? = if (context.candidateCall.isSafeCall)
|
var receiverType: KotlinType? = if (context.candidateCall.isSafeCall)
|
||||||
TypeUtils.makeNotNullable(receiverArgumentType)
|
TypeUtils.makeNotNullable(receiverArgumentType)
|
||||||
else
|
else
|
||||||
|
|||||||
+2
-2
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
//checking that only invoke or inlinable extension called on function parameter
|
||||||
CallableDescriptor targetDescriptor = resolvedCall.getResultingDescriptor();
|
CallableDescriptor targetDescriptor = resolvedCall.getResultingDescriptor();
|
||||||
checkCallWithReceiver(context, targetDescriptor, resolvedCall.getDispatchReceiver(), expression);
|
checkCallWithReceiver(context, targetDescriptor, resolvedCall.getDispatchReceiver(), expression);
|
||||||
checkCallWithReceiver(context, targetDescriptor, (ReceiverValue) resolvedCall.getExtensionReceiver(), expression);
|
checkCallWithReceiver(context, targetDescriptor, resolvedCall.getExtensionReceiver(), expression);
|
||||||
|
|
||||||
if (inlinableParameters.contains(targetDescriptor)) {
|
if (inlinableParameters.contains(targetDescriptor)) {
|
||||||
if (!isInsideCall(expression)) {
|
if (!isInsideCall(expression)) {
|
||||||
|
|||||||
+2
-3
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.psi.ValueArgument;
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
|
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.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
|
|
||||||
@@ -65,7 +64,7 @@ public abstract class DelegatingResolvedCall<D extends CallableDescriptor> imple
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Receiver getExtensionReceiver() {
|
public ReceiverValue getExtensionReceiver() {
|
||||||
return resolvedCall.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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.psi.ValueArgument;
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
|
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.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
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 */
|
/** If the target was an extension function or property, this is the value for its receiver parameter */
|
||||||
@Nullable
|
@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 */
|
/** If the target was a member of a class, this is the object of that class to call it on */
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+2
-3
@@ -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.ExplicitReceiverKind;
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate;
|
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate;
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
|
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.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
import org.jetbrains.kotlin.types.TypeProjection;
|
import org.jetbrains.kotlin.types.TypeProjection;
|
||||||
@@ -77,7 +76,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
|
|||||||
private final D candidateDescriptor;
|
private final D candidateDescriptor;
|
||||||
private D resultingDescriptor; // Probably substituted
|
private D resultingDescriptor; // Probably substituted
|
||||||
private final ReceiverValue dispatchReceiver; // receiver object of a method
|
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 ExplicitReceiverKind explicitReceiverKind;
|
||||||
private final TypeSubstitutor knownTypeParametersSubstitutor;
|
private final TypeSubstitutor knownTypeParametersSubstitutor;
|
||||||
|
|
||||||
@@ -275,7 +274,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Receiver getExtensionReceiver() {
|
public ReceiverValue getExtensionReceiver() {
|
||||||
return extensionReceiver;
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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? {
|
fun ResolvedCall<*>.getExplicitReceiverValue(): ReceiverValue? {
|
||||||
return when (explicitReceiverKind) {
|
return when (explicitReceiverKind) {
|
||||||
ExplicitReceiverKind.DISPATCH_RECEIVER -> dispatchReceiver!!
|
ExplicitReceiverKind.DISPATCH_RECEIVER -> dispatchReceiver!!
|
||||||
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> extensionReceiver as ReceiverValue
|
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> extensionReceiver!!
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ResolvedCall<*>.getImplicitReceiverValue(): ReceiverValue? {
|
fun ResolvedCall<*>.getImplicitReceiverValue(): ReceiverValue? {
|
||||||
return when (explicitReceiverKind) {
|
return when (explicitReceiverKind) {
|
||||||
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> if (extensionReceiver != null) extensionReceiver as ReceiverValue else dispatchReceiver
|
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> extensionReceiver ?: dispatchReceiver
|
||||||
ExplicitReceiverKind.DISPATCH_RECEIVER -> extensionReceiver as ReceiverValue?
|
ExplicitReceiverKind.DISPATCH_RECEIVER -> extensionReceiver
|
||||||
ExplicitReceiverKind.EXTENSION_RECEIVER -> dispatchReceiver
|
ExplicitReceiverKind.EXTENSION_RECEIVER -> dispatchReceiver
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.model.ResolvedValueArgument
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||||
import org.jetbrains.kotlin.resolve.constants.*
|
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.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
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? {
|
private fun getReceiverExpressionType(resolvedCall: ResolvedCall<*>): KotlinType? {
|
||||||
return when (resolvedCall.explicitReceiverKind) {
|
return when (resolvedCall.explicitReceiverKind) {
|
||||||
ExplicitReceiverKind.DISPATCH_RECEIVER -> resolvedCall.dispatchReceiver!!.type
|
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.NO_EXPLICIT_RECEIVER -> null
|
||||||
ExplicitReceiverKind.BOTH_RECEIVERS -> null
|
ExplicitReceiverKind.BOTH_RECEIVERS -> null
|
||||||
else -> 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
|
||||||
|
|
||||||
class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
||||||
override val suppressionKey: String get() = "unused"
|
override val suppressionKey: String get() = "unused"
|
||||||
@@ -69,7 +68,7 @@ class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
|||||||
private fun isUsageOfReceiver(resolvedCall: ResolvedCall<*>, bindingContext: BindingContext): Boolean {
|
private fun isUsageOfReceiver(resolvedCall: ResolvedCall<*>, bindingContext: BindingContext): Boolean {
|
||||||
// As receiver of call
|
// As receiver of call
|
||||||
if (resolvedCall.dispatchReceiver.getThisReceiverOwner(bindingContext) == callable ||
|
if (resolvedCall.dispatchReceiver.getThisReceiverOwner(bindingContext) == callable ||
|
||||||
(resolvedCall.extensionReceiver as ReceiverValue?).getThisReceiverOwner(bindingContext) == callable) {
|
resolvedCall.extensionReceiver.getThisReceiverOwner(bindingContext) == callable) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// As explicit "this"
|
// 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
|
||||||
|
|
||||||
class AddTypeToLHSOfCallableReferenceFix(
|
class AddTypeToLHSOfCallableReferenceFix(
|
||||||
expression: KtCallableReferenceExpression
|
expression: KtCallableReferenceExpression
|
||||||
@@ -39,7 +38,7 @@ class AddTypeToLHSOfCallableReferenceFix(
|
|||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
val resolvedCall = element.callableReference.getResolvedCall(element.analyze(BodyResolveMode.PARTIAL)) ?: return
|
val resolvedCall = element.callableReference.getResolvedCall(element.analyze(BodyResolveMode.PARTIAL)) ?: return
|
||||||
val receiver = with(resolvedCall) {
|
val receiver = with(resolvedCall) {
|
||||||
dispatchReceiver ?: extensionReceiver as? ReceiverValue ?: return
|
dispatchReceiver ?: extensionReceiver ?: return
|
||||||
}
|
}
|
||||||
val type = KtPsiFactory(project).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(receiver.type))
|
val type = KtPsiFactory(project).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(receiver.type))
|
||||||
element.setTypeReference(type)
|
element.setTypeReference(type)
|
||||||
|
|||||||
+2
-5
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -191,11 +191,8 @@ class KotlinFunctionCallUsage(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addReceiver = descriptor !is ReceiverParameterDescriptor
|
addReceiver = descriptor !is ReceiverParameterDescriptor
|
||||||
val extensionReceiver = resolvedCall.extensionReceiver
|
|
||||||
argumentExpression =
|
argumentExpression =
|
||||||
(if (extensionReceiver is ReceiverValue)
|
getReceiverExpressionIfMatched(resolvedCall.extensionReceiver, descriptor, psiFactory)
|
||||||
getReceiverExpressionIfMatched(extensionReceiver, descriptor, psiFactory)
|
|
||||||
else null)
|
|
||||||
?: getReceiverExpressionIfMatched(resolvedCall.dispatchReceiver, descriptor, psiFactory)
|
?: getReceiverExpressionIfMatched(resolvedCall.dispatchReceiver, descriptor, psiFactory)
|
||||||
}
|
}
|
||||||
if (argumentExpression == null) continue
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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) {
|
return when (receiverKind) {
|
||||||
EXTENSION_RECEIVER -> explicitReceivers.extensionOrDispatchReceiver
|
EXTENSION_RECEIVER -> explicitReceivers.extensionOrDispatchReceiver
|
||||||
BOTH_RECEIVERS -> explicitReceivers.extensionReceiver
|
BOTH_RECEIVERS -> explicitReceivers.extensionReceiver
|
||||||
else -> this.getDispatchReceiver(receiverValue as ReceiverValue)
|
else -> this.getDispatchReceiver(receiverValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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)) {
|
return when (Pair(dispatchReceiver != null, extensionReceiver != null)) {
|
||||||
Pair(true, true) -> ExplicitReceivers(dispatchReceiverExpression, explicitReceivers.extensionOrDispatchReceiver)
|
Pair(true, true) -> ExplicitReceivers(dispatchReceiverExpression, explicitReceivers.extensionOrDispatchReceiver)
|
||||||
Pair(true, false) -> ExplicitReceivers(dispatchReceiverExpression)
|
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")
|
else -> throw AssertionError("'Invoke' resolved call without receivers: $callElement")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.psi.KtReferenceExpression;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
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.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
|
|
||||||
@@ -127,7 +126,7 @@ public final class TopLevelFIF extends CompositeFIF {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
protected ExpressionReceiver getExpressionReceiver(@NotNull ResolvedCall<?> resolvedCall) {
|
protected ExpressionReceiver getExpressionReceiver(@NotNull ResolvedCall<?> resolvedCall) {
|
||||||
Receiver result = resolvedCall.getExtensionReceiver();
|
ReceiverValue result = resolvedCall.getExtensionReceiver();
|
||||||
return result instanceof ExpressionReceiver ? (ExpressionReceiver) result : null;
|
return result instanceof ExpressionReceiver ? (ExpressionReceiver) result : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user