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.MutableDataFlowInfoForArguments;
027    import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
028    import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
029    import org.jetbrains.kotlin.types.KotlinType;
030    
031    public class BasicCallResolutionContext extends CallResolutionContext<BasicCallResolutionContext> {
032        private BasicCallResolutionContext(
033                @NotNull BindingTrace trace,
034                @NotNull LexicalScope scope,
035                @NotNull Call call,
036                @NotNull KotlinType expectedType,
037                @NotNull DataFlowInfo dataFlowInfo,
038                @NotNull ContextDependency contextDependency,
039                @NotNull CheckArgumentTypesMode checkArguments,
040                @NotNull ResolutionResultsCache resolutionResultsCache,
041                @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
042                @NotNull StatementFilter statementFilter,
043                boolean isAnnotationContext,
044                boolean isDebuggerContext,
045                boolean collectAllCandidates,
046                @NotNull CallPosition callPosition,
047                @NotNull Function1<KtExpression, KtExpression> expressionContextProvider
048        ) {
049            super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
050                  dataFlowInfoForArguments, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates,
051                  callPosition, expressionContextProvider);
052        }
053    
054        @NotNull
055        public static BasicCallResolutionContext create(
056                @NotNull BindingTrace trace,
057                @NotNull LexicalScope scope,
058                @NotNull Call call,
059                @NotNull KotlinType expectedType,
060                @NotNull DataFlowInfo dataFlowInfo,
061                @NotNull ContextDependency contextDependency,
062                @NotNull CheckArgumentTypesMode checkArguments,
063                boolean isAnnotationContext
064        ) {
065            return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
066                                                  new ResolutionResultsCacheImpl(), null,
067                                                  StatementFilter.NONE, isAnnotationContext, false, false,
068                                                  CallPosition.Unknown.INSTANCE, DEFAULT_EXPRESSION_CONTEXT_PROVIDER);
069        }
070    
071        @NotNull
072        public static BasicCallResolutionContext create(
073                @NotNull ResolutionContext context, @NotNull Call call, @NotNull CheckArgumentTypesMode checkArguments,
074                @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
075        ) {
076            return new BasicCallResolutionContext(
077                    context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, context.contextDependency, checkArguments,
078                    context.resolutionResultsCache, dataFlowInfoForArguments,
079                    context.statementFilter, context.isAnnotationContext, context.isDebuggerContext, context.collectAllCandidates,
080                    context.callPosition, context.expressionContextProvider);
081        }
082    
083        @NotNull
084        public static BasicCallResolutionContext create(
085                @NotNull ResolutionContext context, @NotNull Call call, @NotNull CheckArgumentTypesMode checkArguments
086        ) {
087            return create(context, call, checkArguments, null);
088        }
089    
090        @Override
091        protected BasicCallResolutionContext create(
092                @NotNull BindingTrace trace,
093                @NotNull LexicalScope scope,
094                @NotNull DataFlowInfo dataFlowInfo,
095                @NotNull KotlinType expectedType,
096                @NotNull ContextDependency contextDependency,
097                @NotNull ResolutionResultsCache resolutionResultsCache,
098                @NotNull StatementFilter statementFilter,
099                boolean collectAllCandidates,
100                @NotNull CallPosition callPosition,
101                @NotNull Function1<KtExpression, KtExpression> expressionContextProvider
102        ) {
103            return new BasicCallResolutionContext(
104                    trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
105                    dataFlowInfoForArguments, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates,
106                    callPosition, expressionContextProvider);
107        }
108    
109        @NotNull
110        public BasicCallResolutionContext replaceCall(@NotNull Call newCall) {
111            return new BasicCallResolutionContext(
112                    trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
113                    dataFlowInfoForArguments, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates,
114                    callPosition, expressionContextProvider);
115        }
116    }