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