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