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