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.ResolvedCallImpl;
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 ResolvedCallImpl<D> candidateCall;
036        public final TracingStrategy tracing;
037        public ReceiverValue receiverForVariableAsFunctionSecondCall = ReceiverValue.NO_RECEIVER;
038    
039        private CallCandidateResolutionContext(
040                @NotNull ResolvedCallImpl<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                boolean isAnnotationContext
054        ) {
055            super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, labelResolver,
056                  dataFlowInfoForArguments, callResolverExtension, isAnnotationContext);
057            this.candidateCall = candidateCall;
058            this.tracing = tracing;
059        }
060    
061        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
062                @NotNull ResolvedCallImpl<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
063                @NotNull TracingStrategy tracing, @NotNull Call call) {
064            candidateCall.setInitialDataFlowInfo(context.dataFlowInfo);
065            return new CallCandidateResolutionContext<D>(
066                    candidateCall, tracing, trace, context.scope, call, context.expectedType,
067                    context.dataFlowInfo, context.contextDependency, context.checkArguments,
068                    context.resolutionResultsCache, context.labelResolver, context.dataFlowInfoForArguments,
069                    context.callResolverExtension, context.isAnnotationContext);
070        }
071    
072        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
073                @NotNull ResolvedCallImpl<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
074                @NotNull TracingStrategy tracing) {
075            return create(candidateCall, context, trace, tracing, context.call);
076        }
077    
078        public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> createForCallBeingAnalyzed(
079                @NotNull ResolvedCallImpl<D> candidateCall, @NotNull BasicCallResolutionContext context, @NotNull TracingStrategy tracing
080        ) {
081            return new CallCandidateResolutionContext<D>(
082                    candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
083                    context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
084                    context.labelResolver, context.dataFlowInfoForArguments, context.callResolverExtension, context.isAnnotationContext);
085        }
086    
087        @Override
088        protected CallCandidateResolutionContext<D> create(
089                @NotNull BindingTrace trace,
090                @NotNull JetScope scope,
091                @NotNull DataFlowInfo dataFlowInfo,
092                @NotNull JetType expectedType,
093                @NotNull ContextDependency contextDependency,
094                @NotNull ResolutionResultsCache resolutionResultsCache,
095                @NotNull LabelResolver labelResolver
096        ) {
097            return new CallCandidateResolutionContext<D>(
098                    candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
099                    resolutionResultsCache, labelResolver, dataFlowInfoForArguments, callResolverExtension, isAnnotationContext);
100        }
101    }