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.CallChecker;
026 import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
027 import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
028 import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
029 import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
030 import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
031 import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
032 import org.jetbrains.kotlin.types.JetType;
033
034 public final class CallCandidateResolutionContext<D extends CallableDescriptor> extends CallResolutionContext<CallCandidateResolutionContext<D>> {
035 @NotNull
036 public final MutableResolvedCall<D> candidateCall;
037 @NotNull
038 public final TracingStrategy tracing;
039 @NotNull
040 public final ReceiverValue explicitExtensionReceiverForInvoke;
041 @NotNull
042 public final CandidateResolveMode candidateResolveMode;
043
044 private CallCandidateResolutionContext(
045 @NotNull MutableResolvedCall<D> candidateCall,
046 @NotNull TracingStrategy tracing,
047 @NotNull BindingTrace trace,
048 @NotNull LexicalScope scope,
049 @NotNull Call call,
050 @NotNull JetType expectedType,
051 @NotNull DataFlowInfo dataFlowInfo,
052 @NotNull ContextDependency contextDependency,
053 @NotNull CheckArgumentTypesMode checkArguments,
054 @NotNull ResolutionResultsCache resolutionResultsCache,
055 @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
056 @NotNull CallChecker callChecker,
057 @NotNull StatementFilter statementFilter,
058 @NotNull ReceiverValue explicitExtensionReceiverForInvoke,
059 @NotNull CandidateResolveMode candidateResolveMode,
060 boolean isAnnotationContext,
061 boolean collectAllCandidates,
062 boolean insideSafeCallChain
063 ) {
064 super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
065 dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext,
066 collectAllCandidates, insideSafeCallChain);
067 this.candidateCall = candidateCall;
068 this.tracing = tracing;
069 this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke;
070 this.candidateResolveMode = candidateResolveMode;
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 @NotNull CandidateResolveMode candidateResolveMode
077 ) {
078 candidateCall.getDataFlowInfoForArguments().setInitialDataFlowInfo(context.dataFlowInfo);
079 return new CallCandidateResolutionContext<D>(
080 candidateCall, tracing, trace, context.scope, call, context.expectedType,
081 context.dataFlowInfo, context.contextDependency, context.checkArguments,
082 context.resolutionResultsCache, context.dataFlowInfoForArguments,
083 context.callChecker, context.statementFilter, explicitExtensionReceiverForInvoke,
084 candidateResolveMode, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain);
085 }
086
087 @NotNull
088 public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> createForCallBeingAnalyzed(
089 @NotNull MutableResolvedCall<D> candidateCall, @NotNull BasicCallResolutionContext context, @NotNull TracingStrategy tracing
090 ) {
091 return new CallCandidateResolutionContext<D>(
092 candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
093 context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
094 context.dataFlowInfoForArguments, context.callChecker, context.statementFilter,
095 ReceiverValue.NO_RECEIVER, CandidateResolveMode.FULLY, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain);
096 }
097
098 @Override
099 protected CallCandidateResolutionContext<D> create(
100 @NotNull BindingTrace trace,
101 @NotNull LexicalScope scope,
102 @NotNull DataFlowInfo dataFlowInfo,
103 @NotNull JetType expectedType,
104 @NotNull ContextDependency contextDependency,
105 @NotNull ResolutionResultsCache resolutionResultsCache,
106 @NotNull StatementFilter statementFilter,
107 boolean collectAllCandidates,
108 boolean insideSafeCallChain
109 ) {
110 return new CallCandidateResolutionContext<D>(
111 candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
112 resolutionResultsCache, dataFlowInfoForArguments, callChecker, statementFilter,
113 explicitExtensionReceiverForInvoke, candidateResolveMode, isAnnotationContext, collectAllCandidates, insideSafeCallChain);
114 }
115 }