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