001 /*
002 * Copyright 2010-2015 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.kotlin.resolve.calls.context;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.kotlin.psi.Call;
022 import org.jetbrains.kotlin.resolve.BindingTrace;
023 import org.jetbrains.kotlin.resolve.StatementFilter;
024 import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
025 import org.jetbrains.kotlin.resolve.calls.model.DataFlowInfoForArgumentsImpl;
026 import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
027 import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
028 import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
029 import org.jetbrains.kotlin.types.JetType;
030
031 public abstract class CallResolutionContext<Context extends CallResolutionContext<Context>> extends ResolutionContext<Context> {
032 @NotNull
033 public final Call call;
034 @NotNull
035 public final CheckArgumentTypesMode checkArguments;
036 @NotNull
037 public final MutableDataFlowInfoForArguments dataFlowInfoForArguments;
038
039 protected CallResolutionContext(
040 @NotNull BindingTrace trace,
041 @NotNull LexicalScope scope,
042 @NotNull Call call,
043 @NotNull JetType expectedType,
044 @NotNull DataFlowInfo dataFlowInfo,
045 @NotNull ContextDependency contextDependency,
046 @NotNull CheckArgumentTypesMode checkArguments,
047 @NotNull ResolutionResultsCache resolutionResultsCache,
048 @SuppressWarnings("NullableProblems")
049 @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
050 @NotNull CallChecker callChecker,
051 @NotNull StatementFilter statementFilter,
052 boolean isAnnotationContext,
053 boolean collectAllCandidates,
054 boolean insideSafeCallChain
055 ) {
056 super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker,
057 statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain);
058 this.call = call;
059 this.checkArguments = checkArguments;
060 if (dataFlowInfoForArguments != null) {
061 this.dataFlowInfoForArguments = dataFlowInfoForArguments;
062 }
063 else if (checkArguments == CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS) {
064 this.dataFlowInfoForArguments = new DataFlowInfoForArgumentsImpl(call);
065 }
066 else {
067 this.dataFlowInfoForArguments = new MutableDataFlowInfoForArguments.WithoutArgumentsCheck();
068 }
069 }
070
071 @NotNull
072 public BasicCallResolutionContext toBasic() {
073 return BasicCallResolutionContext.create(this, call, checkArguments);
074 }
075 }