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.autocasts.DataFlowInfo;
025 import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
026 import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl;
027 import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
028 import org.jetbrains.jet.lang.resolve.scopes.JetScope;
029 import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
030 import org.jetbrains.jet.lang.types.JetType;
031 import org.jetbrains.jet.lang.types.expressions.LabelResolver;
032
033 public final class CallCandidateResolutionContext<D extends CallableDescriptor> extends CallResolutionContext<CallCandidateResolutionContext<D>> {
034 public final ResolvedCallImpl<D> candidateCall;
035 public final TracingStrategy tracing;
036 public ReceiverValue receiverForVariableAsFunctionSecondCall = ReceiverValue.NO_RECEIVER;
037
038 private CallCandidateResolutionContext(
039 @NotNull ResolvedCallImpl<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 ExpressionPosition expressionPosition,
049 @NotNull ResolutionResultsCache resolutionResultsCache,
050 @NotNull LabelResolver labelResolver,
051 @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
052 ) {
053 super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, expressionPosition, resolutionResultsCache,
054 labelResolver, dataFlowInfoForArguments);
055 this.candidateCall = candidateCall;
056 this.tracing = tracing;
057 }
058
059 public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
060 @NotNull ResolvedCallImpl<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
061 @NotNull TracingStrategy tracing, @NotNull Call call) {
062 candidateCall.setInitialDataFlowInfo(context.dataFlowInfo);
063 return new CallCandidateResolutionContext<D>(
064 candidateCall, tracing, trace, context.scope, call, context.expectedType,
065 context.dataFlowInfo, context.contextDependency, context.checkArguments,
066 context.expressionPosition, context.resolutionResultsCache, context.labelResolver, context.dataFlowInfoForArguments);
067 }
068
069 public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
070 @NotNull ResolvedCallImpl<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
071 @NotNull TracingStrategy tracing) {
072 return create(candidateCall, context, trace, tracing, context.call);
073 }
074
075 public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> createForCallBeingAnalyzed(
076 @NotNull ResolvedCallImpl<D> candidateCall, @NotNull BasicCallResolutionContext context, @NotNull TracingStrategy tracing
077 ) {
078 return new CallCandidateResolutionContext<D>(
079 candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
080 context.dataFlowInfo, context.contextDependency, context.checkArguments, context.expressionPosition,
081 context.resolutionResultsCache, context.labelResolver, context.dataFlowInfoForArguments);
082 }
083
084 @Override
085 protected CallCandidateResolutionContext<D> create(
086 @NotNull BindingTrace trace,
087 @NotNull JetScope scope,
088 @NotNull DataFlowInfo dataFlowInfo,
089 @NotNull JetType expectedType,
090 @NotNull ExpressionPosition expressionPosition,
091 @NotNull ContextDependency contextDependency,
092 @NotNull ResolutionResultsCache resolutionResultsCache,
093 @NotNull LabelResolver labelResolver
094 ) {
095 return new CallCandidateResolutionContext<D>(
096 candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency,
097 checkArguments, expressionPosition, resolutionResultsCache, labelResolver, dataFlowInfoForArguments);
098 }
099
100 @Override
101 protected CallCandidateResolutionContext<D> self() {
102 return this;
103 }
104 }