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