001    /*
002     * Copyright 2010-2013 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.jet.lang.resolve.calls.context;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
022    import org.jetbrains.jet.lang.psi.Call;
023    import org.jetbrains.jet.lang.resolve.BindingTrace;
024    import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
025    import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
026    import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
027    import org.jetbrains.jet.lang.resolve.calls.model.MutableResolvedCall;
028    import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
029    import org.jetbrains.jet.lang.resolve.scopes.JetScope;
030    import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
031    import org.jetbrains.jet.lang.types.JetType;
032    import org.jetbrains.jet.lang.types.expressions.LabelResolver;
033    
034    public final class CallCandidateResolutionContext<D extends CallableDescriptor> extends CallResolutionContext<CallCandidateResolutionContext<D>> {
035        public final MutableResolvedCall<D> candidateCall;
036        public final TracingStrategy tracing;
037        public final ReceiverValue explicitExtensionReceiverForInvoke;
038    
039        private CallCandidateResolutionContext(
040                @NotNull MutableResolvedCall<D> candidateCall,
041                @NotNull TracingStrategy tracing,
042                @NotNull BindingTrace trace,
043                @NotNull JetScope scope,
044                @NotNull Call call,
045                @NotNull JetType expectedType,
046                @NotNull DataFlowInfo dataFlowInfo,
047                @NotNull ContextDependency contextDependency,
048                @NotNull CheckValueArgumentsMode checkArguments,
049                @NotNull ResolutionResultsCache resolutionResultsCache,
050                @NotNull LabelResolver labelResolver,
051                @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
052                @NotNull CallResolverExtension callResolverExtension,
053                @NotNull ReceiverValue explicitExtensionReceiverForInvoke,
054                boolean isAnnotationContext,
055                boolean collectAllCandidates
056        ) {
057            super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, labelResolver,
058                  dataFlowInfoForArguments, callResolverExtension, isAnnotationContext, collectAllCandidates);
059            this.candidateCall = candidateCall;
060            this.tracing = tracing;
061            this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke;
062        }
063    
064        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
065                @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
066                @NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke
067        ) {
068            candidateCall.setInitialDataFlowInfo(context.dataFlowInfo);
069            return new CallCandidateResolutionContext<D>(
070                    candidateCall, tracing, trace, context.scope, call, context.expectedType,
071                    context.dataFlowInfo, context.contextDependency, context.checkArguments,
072                    context.resolutionResultsCache, context.labelResolver, context.dataFlowInfoForArguments,
073                    context.callResolverExtension, explicitExtensionReceiverForInvoke, context.isAnnotationContext, context.collectAllCandidates);
074        }
075    
076        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
077                @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
078                @NotNull TracingStrategy tracing, @NotNull Call call
079        ) {
080            return create(candidateCall, context, trace, tracing, call, ReceiverValue.NO_RECEIVER);
081        }
082    
083        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
084                @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
085                @NotNull TracingStrategy tracing) {
086            return create(candidateCall, context, trace, tracing, context.call);
087        }
088    
089        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> createForCallBeingAnalyzed(
090                @NotNull MutableResolvedCall<D> candidateCall, @NotNull BasicCallResolutionContext context, @NotNull TracingStrategy tracing
091        ) {
092            return new CallCandidateResolutionContext<D>(
093                    candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
094                    context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
095                    context.labelResolver, context.dataFlowInfoForArguments, context.callResolverExtension, ReceiverValue.NO_RECEIVER,
096                    context.isAnnotationContext, context.collectAllCandidates);
097        }
098    
099        @Override
100        protected CallCandidateResolutionContext<D> create(
101                @NotNull BindingTrace trace,
102                @NotNull JetScope scope,
103                @NotNull DataFlowInfo dataFlowInfo,
104                @NotNull JetType expectedType,
105                @NotNull ContextDependency contextDependency,
106                @NotNull ResolutionResultsCache resolutionResultsCache,
107                @NotNull LabelResolver labelResolver,
108                boolean collectAllCandidates
109        ) {
110            return new CallCandidateResolutionContext<D>(
111                    candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
112                    resolutionResultsCache, labelResolver, dataFlowInfoForArguments, callResolverExtension, explicitExtensionReceiverForInvoke,
113                    isAnnotationContext, collectAllCandidates);
114        }
115    }