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