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.MutableDataFlowInfoForArguments;
026    import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
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 CallChecker callChecker,
043                @NotNull StatementFilter statementFilter,
044                boolean isAnnotationContext,
045                boolean collectAllCandidates,
046                @NotNull CallPosition callPosition
047        ) {
048            super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
049                  dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, callPosition);
050        }
051    
052        @NotNull
053        public static BasicCallResolutionContext create(
054                @NotNull BindingTrace trace,
055                @NotNull LexicalScope scope,
056                @NotNull Call call,
057                @NotNull KotlinType expectedType,
058                @NotNull DataFlowInfo dataFlowInfo,
059                @NotNull ContextDependency contextDependency,
060                @NotNull CheckArgumentTypesMode checkArguments,
061                @NotNull CallChecker callChecker,
062                boolean isAnnotationContext
063        ) {
064            return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
065                                                  new ResolutionResultsCacheImpl(), null,
066                                                  callChecker, StatementFilter.NONE, isAnnotationContext, false,
067                                                  CallPosition.Unknown.INSTANCE);
068        }
069    
070        @NotNull
071        public static BasicCallResolutionContext create(
072                @NotNull ResolutionContext context, @NotNull Call call, @NotNull CheckArgumentTypesMode checkArguments,
073                @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
074        ) {
075            return new BasicCallResolutionContext(
076                    context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, context.contextDependency, checkArguments,
077                    context.resolutionResultsCache, dataFlowInfoForArguments,
078                    context.callChecker,
079                    context.statementFilter, context.isAnnotationContext, context.collectAllCandidates, context.callPosition);
080        }
081    
082        @NotNull
083        public static BasicCallResolutionContext create(
084                @NotNull ResolutionContext context, @NotNull Call call, @NotNull CheckArgumentTypesMode checkArguments
085        ) {
086            return create(context, call, checkArguments, null);
087        }
088    
089        @Override
090        protected BasicCallResolutionContext create(
091                @NotNull BindingTrace trace,
092                @NotNull LexicalScope scope,
093                @NotNull DataFlowInfo dataFlowInfo,
094                @NotNull KotlinType expectedType,
095                @NotNull ContextDependency contextDependency,
096                @NotNull ResolutionResultsCache resolutionResultsCache,
097                @NotNull StatementFilter statementFilter,
098                boolean collectAllCandidates,
099                @NotNull CallPosition callPosition
100        ) {
101            return new BasicCallResolutionContext(
102                    trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
103                    dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, callPosition);
104        }
105    
106        @NotNull
107        public BasicCallResolutionContext replaceCall(@NotNull Call newCall) {
108            return new BasicCallResolutionContext(
109                    trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
110                    dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, callPosition);
111        }
112    
113        public void performContextDependentCallChecks(@NotNull ResolvedCall<?> resolvedCall) {
114            callChecker.check(resolvedCall, this);
115        }
116    }