001    /*
002     * Copyright 2010-2015 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.kotlin.resolve.calls.context;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.kotlin.descriptors.CallableDescriptor;
022    import org.jetbrains.kotlin.psi.Call;
023    import org.jetbrains.kotlin.resolve.BindingTrace;
024    import org.jetbrains.kotlin.resolve.StatementFilter;
025    import org.jetbrains.kotlin.resolve.calls.checkers.AdditionalTypeChecker;
026    import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
027    import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
028    import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
029    import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
030    import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
031    import org.jetbrains.kotlin.resolve.scopes.JetScope;
032    import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
033    import org.jetbrains.kotlin.types.JetType;
034    
035    public final class CallCandidateResolutionContext<D extends CallableDescriptor> extends CallResolutionContext<CallCandidateResolutionContext<D>> {
036        @NotNull
037        public final MutableResolvedCall<D> candidateCall;
038        @NotNull
039        public final TracingStrategy tracing;
040        @NotNull
041        public final ReceiverValue explicitExtensionReceiverForInvoke;
042    
043        private CallCandidateResolutionContext(
044                @NotNull MutableResolvedCall<D> candidateCall,
045                @NotNull TracingStrategy tracing,
046                @NotNull BindingTrace trace,
047                @NotNull JetScope scope,
048                @NotNull Call call,
049                @NotNull JetType expectedType,
050                @NotNull DataFlowInfo dataFlowInfo,
051                @NotNull ContextDependency contextDependency,
052                @NotNull CheckValueArgumentsMode checkArguments,
053                @NotNull ResolutionResultsCache resolutionResultsCache,
054                @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
055                @NotNull CallChecker callChecker,
056                @NotNull AdditionalTypeChecker additionalTypeChecker,
057                @NotNull StatementFilter statementFilter,
058                @NotNull ReceiverValue explicitExtensionReceiverForInvoke,
059                boolean isAnnotationContext,
060                boolean collectAllCandidates
061        ) {
062            super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
063                  dataFlowInfoForArguments, callChecker, additionalTypeChecker, statementFilter, isAnnotationContext, collectAllCandidates);
064            this.candidateCall = candidateCall;
065            this.tracing = tracing;
066            this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke;
067        }
068    
069        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
070                @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
071                @NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke
072        ) {
073            candidateCall.getDataFlowInfoForArguments().setInitialDataFlowInfo(context.dataFlowInfo);
074            return new CallCandidateResolutionContext<D>(
075                    candidateCall, tracing, trace, context.scope, call, context.expectedType,
076                    context.dataFlowInfo, context.contextDependency, context.checkArguments,
077                    context.resolutionResultsCache, context.dataFlowInfoForArguments,
078                    context.callChecker, context.additionalTypeChecker, context.statementFilter, explicitExtensionReceiverForInvoke,
079                    context.isAnnotationContext, context.collectAllCandidates);
080        }
081    
082        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
083                @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
084                @NotNull TracingStrategy tracing, @NotNull Call call
085        ) {
086            return create(candidateCall, context, trace, tracing, call, ReceiverValue.NO_RECEIVER);
087        }
088    
089        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
090                @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
091                @NotNull TracingStrategy tracing) {
092            return create(candidateCall, context, trace, tracing, context.call);
093        }
094    
095        @NotNull
096        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> createForCallBeingAnalyzed(
097                @NotNull MutableResolvedCall<D> candidateCall, @NotNull BasicCallResolutionContext context, @NotNull TracingStrategy tracing
098        ) {
099            return new CallCandidateResolutionContext<D>(
100                    candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
101                    context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
102                    context.dataFlowInfoForArguments, context.callChecker, context.additionalTypeChecker, context.statementFilter,
103                    ReceiverValue.NO_RECEIVER, context.isAnnotationContext, context.collectAllCandidates);
104        }
105    
106        @Override
107        protected CallCandidateResolutionContext<D> create(
108                @NotNull BindingTrace trace,
109                @NotNull JetScope scope,
110                @NotNull DataFlowInfo dataFlowInfo,
111                @NotNull JetType expectedType,
112                @NotNull ContextDependency contextDependency,
113                @NotNull ResolutionResultsCache resolutionResultsCache,
114                @NotNull StatementFilter statementFilter,
115                boolean collectAllCandidates
116        ) {
117            return new CallCandidateResolutionContext<D>(
118                    candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
119                    resolutionResultsCache, dataFlowInfoForArguments, callChecker, additionalTypeChecker, statementFilter,
120                    explicitExtensionReceiverForInvoke, isAnnotationContext, collectAllCandidates);
121        }
122    }