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                boolean insideSafeCallChain
047        ) {
048            super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
049                  dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain);
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, false);
067        }
068    
069        @NotNull
070        public static BasicCallResolutionContext create(
071                @NotNull ResolutionContext context, @NotNull Call call, @NotNull CheckArgumentTypesMode checkArguments,
072                @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
073        ) {
074            return new BasicCallResolutionContext(
075                    context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, context.contextDependency, checkArguments,
076                    context.resolutionResultsCache, dataFlowInfoForArguments,
077                    context.callChecker,
078                    context.statementFilter, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain);
079        }
080    
081        @NotNull
082        public static BasicCallResolutionContext create(
083                @NotNull ResolutionContext context, @NotNull Call call, @NotNull CheckArgumentTypesMode checkArguments
084        ) {
085            return create(context, call, checkArguments, null);
086        }
087    
088        @Override
089        protected BasicCallResolutionContext create(
090                @NotNull BindingTrace trace,
091                @NotNull LexicalScope scope,
092                @NotNull DataFlowInfo dataFlowInfo,
093                @NotNull KotlinType expectedType,
094                @NotNull ContextDependency contextDependency,
095                @NotNull ResolutionResultsCache resolutionResultsCache,
096                @NotNull StatementFilter statementFilter,
097                boolean collectAllCandidates,
098                boolean insideSafeCallChain
099        ) {
100            return new BasicCallResolutionContext(
101                    trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
102                    dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain);
103        }
104    
105        @NotNull
106        public BasicCallResolutionContext replaceCall(@NotNull Call newCall) {
107            return new BasicCallResolutionContext(
108                    trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
109                    dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, insideCallChain);
110        }
111    
112        public void performContextDependentCallChecks(@NotNull ResolvedCall<?> resolvedCall) {
113            callChecker.check(resolvedCall, this);
114        }
115    }