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.resolve.validation.SymbolUsageValidator;
034    import org.jetbrains.kotlin.types.JetType;
035    
036    public final class CallCandidateResolutionContext<D extends CallableDescriptor> extends CallResolutionContext<CallCandidateResolutionContext<D>> {
037        @NotNull
038        public final MutableResolvedCall<D> candidateCall;
039        @NotNull
040        public final TracingStrategy tracing;
041        @NotNull
042        public final ReceiverValue explicitExtensionReceiverForInvoke;
043    
044        private CallCandidateResolutionContext(
045                @NotNull MutableResolvedCall<D> candidateCall,
046                @NotNull TracingStrategy tracing,
047                @NotNull BindingTrace trace,
048                @NotNull JetScope scope,
049                @NotNull Call call,
050                @NotNull JetType expectedType,
051                @NotNull DataFlowInfo dataFlowInfo,
052                @NotNull ContextDependency contextDependency,
053                @NotNull CheckValueArgumentsMode checkArguments,
054                @NotNull ResolutionResultsCache resolutionResultsCache,
055                @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
056                @NotNull CallChecker callChecker,
057                @NotNull SymbolUsageValidator symbolUsageValidator,
058                @NotNull AdditionalTypeChecker additionalTypeChecker,
059                @NotNull StatementFilter statementFilter,
060                @NotNull ReceiverValue explicitExtensionReceiverForInvoke,
061                boolean isAnnotationContext,
062                boolean collectAllCandidates,
063                boolean insideSafeCallChain
064        ) {
065            super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
066                  dataFlowInfoForArguments, callChecker, symbolUsageValidator, additionalTypeChecker, statementFilter, isAnnotationContext, 
067                  collectAllCandidates, insideSafeCallChain);
068            this.candidateCall = candidateCall;
069            this.tracing = tracing;
070            this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke;
071        }
072    
073        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
074                @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
075                @NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke
076        ) {
077            candidateCall.getDataFlowInfoForArguments().setInitialDataFlowInfo(context.dataFlowInfo);
078            return new CallCandidateResolutionContext<D>(
079                    candidateCall, tracing, trace, context.scope, call, context.expectedType,
080                    context.dataFlowInfo, context.contextDependency, context.checkArguments,
081                    context.resolutionResultsCache, context.dataFlowInfoForArguments,
082                    context.callChecker, context.symbolUsageValidator, context.additionalTypeChecker, context.statementFilter, explicitExtensionReceiverForInvoke,
083                    context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain);
084        }
085    
086        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
087                @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
088                @NotNull TracingStrategy tracing, @NotNull Call call
089        ) {
090            return create(candidateCall, context, trace, tracing, call, ReceiverValue.NO_RECEIVER);
091        }
092    
093        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
094                @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
095                @NotNull TracingStrategy tracing) {
096            return create(candidateCall, context, trace, tracing, context.call);
097        }
098    
099        @NotNull
100        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> createForCallBeingAnalyzed(
101                @NotNull MutableResolvedCall<D> candidateCall, @NotNull BasicCallResolutionContext context, @NotNull TracingStrategy tracing
102        ) {
103            return new CallCandidateResolutionContext<D>(
104                    candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
105                    context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
106                    context.dataFlowInfoForArguments, context.callChecker, context.symbolUsageValidator, context.additionalTypeChecker, context.statementFilter,
107                    ReceiverValue.NO_RECEIVER, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain);
108        }
109    
110        @Override
111        protected CallCandidateResolutionContext<D> create(
112                @NotNull BindingTrace trace,
113                @NotNull JetScope scope,
114                @NotNull DataFlowInfo dataFlowInfo,
115                @NotNull JetType expectedType,
116                @NotNull ContextDependency contextDependency,
117                @NotNull ResolutionResultsCache resolutionResultsCache,
118                @NotNull StatementFilter statementFilter,
119                boolean collectAllCandidates,
120                boolean insideSafeCallChain
121        ) {
122            return new CallCandidateResolutionContext<D>(
123                    candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
124                    resolutionResultsCache, dataFlowInfoForArguments, callChecker, symbolUsageValidator, additionalTypeChecker, statementFilter,
125                    explicitExtensionReceiverForInvoke, isAnnotationContext, collectAllCandidates, insideSafeCallChain);
126        }
127    }