Search in sources :

Example 11 with ExpressionReceiver

use of org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver in project kotlin by JetBrains.

the class RangeCodegenUtil method isPrimitiveRangeToExtension.

public static boolean isPrimitiveRangeToExtension(@NotNull KtSimpleNameExpression operationReference, @NotNull BindingContext bindingContext) {
    ResolvedCall<? extends CallableDescriptor> resolvedCall = CallUtilKt.getResolvedCallWithAssert(operationReference, bindingContext);
    ReceiverValue receiver = resolvedCall.getDispatchReceiver();
    /*
         * Range is optimizable if
         * 'in' receiver is expression 'rangeTo' from stdlib package
         * and its argument has same primitive type as generic range parameter.
         * For non-matching primitive types (e.g. int in double range)
         * dispatch receiver will be null, because extension method will be called.
         */
    if (!(receiver instanceof ExpressionReceiver))
        return false;
    ExpressionReceiver e = (ExpressionReceiver) receiver;
    ResolvedCall<? extends CallableDescriptor> resolvedReceiver = CallUtilKt.getResolvedCall(e.getExpression(), bindingContext);
    if (resolvedReceiver == null)
        return false;
    return isPrimitiveRangeToExtension(resolvedReceiver.getResultingDescriptor());
}
Also used : ExpressionReceiver(org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver) ReceiverValue(org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue)

Aggregations

ExpressionReceiver (org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver)11 NotNull (org.jetbrains.annotations.NotNull)5 Name (org.jetbrains.kotlin.name.Name)3 ResolvedCall (org.jetbrains.kotlin.resolve.calls.model.ResolvedCall)3 KotlinType (org.jetbrains.kotlin.types.KotlinType)3 IElementType (com.intellij.psi.tree.IElementType)2 DataFlowInfo (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo)2 Nullable (org.jetbrains.annotations.Nullable)1 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 ModifiersChecker (org.jetbrains.kotlin.resolve.ModifiersChecker)1 TemporaryBindingTrace (org.jetbrains.kotlin.resolve.TemporaryBindingTrace)1 CallPosition (org.jetbrains.kotlin.resolve.calls.context.CallPosition)1 TemporaryTraceAndCache (org.jetbrains.kotlin.resolve.calls.context.TemporaryTraceAndCache)1 OverloadResolutionResults (org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults)1 DataFlowValue (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue)1 DataFlowValueFactory.createDataFlowValue (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory.createDataFlowValue)1 LexicalWritableScope (org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope)1 ReceiverValue (org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue)1 TransientReceiver (org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver)1