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.jet.lang.descriptors.CallableDescriptor;
021 import org.jetbrains.jet.lang.psi.Call;
022 import org.jetbrains.jet.lang.resolve.BindingTrace;
023 import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
024 import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl;
025 import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
026 import org.jetbrains.jet.lang.resolve.scopes.JetScope;
027 import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
028 import org.jetbrains.jet.lang.types.JetType;
029
030 public final class CallCandidateResolutionContext<D extends CallableDescriptor> extends CallResolutionContext<CallCandidateResolutionContext<D>> {
031 public final ResolvedCallImpl<D> candidateCall;
032 public final TracingStrategy tracing;
033 public ReceiverValue receiverForVariableAsFunctionSecondCall = ReceiverValue.NO_RECEIVER;
034
035 private CallCandidateResolutionContext(
036 @NotNull ResolvedCallImpl<D> candidateCall,
037 @NotNull TracingStrategy tracing,
038 @NotNull BindingTrace trace,
039 @NotNull JetScope scope,
040 @NotNull Call call,
041 @NotNull JetType expectedType,
042 @NotNull DataFlowInfo dataFlowInfo,
043 @NotNull ResolveMode resolveMode,
044 @NotNull CheckValueArgumentsMode checkArguments,
045 @NotNull ExpressionPosition expressionPosition,
046 @NotNull ResolutionResultsCache resolutionResultsCache
047 ) {
048 super(trace, scope, call, expectedType, dataFlowInfo, resolveMode, checkArguments, expressionPosition, resolutionResultsCache);
049 this.candidateCall = candidateCall;
050 this.tracing = tracing;
051 }
052
053 public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
054 @NotNull ResolvedCallImpl<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
055 @NotNull TracingStrategy tracing, @NotNull Call call) {
056 candidateCall.setInitialDataFlowInfo(context.dataFlowInfo);
057 return new CallCandidateResolutionContext<D>(
058 candidateCall, tracing, trace, context.scope, call, context.expectedType,
059 context.dataFlowInfo, context.resolveMode, context.checkArguments,
060 context.expressionPosition, context.resolutionResultsCache);
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) {
066 return create(candidateCall, context, trace, tracing, context.call);
067 }
068
069 public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> createForCallBeingAnalyzed(
070 @NotNull ResolvedCallImpl<D> candidateCall, @NotNull BasicCallResolutionContext context, @NotNull TracingStrategy tracing
071 ) {
072 return createForCallBeingAnalyzed(candidateCall, context, context.call, context.resolveMode,
073 context.checkArguments, tracing, context.resolutionResultsCache);
074 }
075
076 public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> createForCallBeingAnalyzed(
077 @NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionContext context, @NotNull Call call,
078 @NotNull ResolveMode resolveMode, @NotNull CheckValueArgumentsMode checkArguments, @NotNull TracingStrategy tracing,
079 @NotNull ResolutionResultsCache resolutionResultsCache
080 ) {
081 return new CallCandidateResolutionContext<D>(
082 candidateCall, tracing, context.trace, context.scope, call, context.expectedType,
083 context.dataFlowInfo, resolveMode, checkArguments, context.expressionPosition, resolutionResultsCache);
084 }
085
086 @Override
087 protected CallCandidateResolutionContext<D> create(
088 @NotNull BindingTrace trace,
089 @NotNull JetScope scope,
090 @NotNull DataFlowInfo dataFlowInfo,
091 @NotNull JetType expectedType,
092 @NotNull ExpressionPosition expressionPosition
093 ) {
094 return new CallCandidateResolutionContext<D>(
095 candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, resolveMode,
096 checkArguments, expressionPosition, resolutionResultsCache);
097 }
098
099 @Override
100 protected CallCandidateResolutionContext<D> self() {
101 return this;
102 }
103
104 @NotNull
105 public CallCandidateResolutionContext<D> replaceResolveMode(@NotNull ResolveMode newResolveMode) {
106 if (newResolveMode == resolveMode) return this;
107 return new CallCandidateResolutionContext<D>(
108 candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, newResolveMode,
109 checkArguments, expressionPosition, resolutionResultsCache);
110 }
111 }