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 isDebuggerContext, 046 boolean collectAllCandidates, 047 @NotNull CallPosition callPosition 048 ) { 049 super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, 050 dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition); 051 } 052 053 @NotNull 054 public static BasicCallResolutionContext create( 055 @NotNull BindingTrace trace, 056 @NotNull LexicalScope scope, 057 @NotNull Call call, 058 @NotNull KotlinType expectedType, 059 @NotNull DataFlowInfo dataFlowInfo, 060 @NotNull ContextDependency contextDependency, 061 @NotNull CheckArgumentTypesMode checkArguments, 062 @NotNull CallChecker callChecker, 063 boolean isAnnotationContext 064 ) { 065 return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, 066 new ResolutionResultsCacheImpl(), null, 067 callChecker, StatementFilter.NONE, isAnnotationContext, false, false, 068 CallPosition.Unknown.INSTANCE); 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.callChecker, 080 context.statementFilter, context.isAnnotationContext, context.isDebuggerContext, context.collectAllCandidates, context.callPosition); 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 ) { 102 return new BasicCallResolutionContext( 103 trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, 104 dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition); 105 } 106 107 @NotNull 108 public BasicCallResolutionContext replaceCall(@NotNull Call newCall) { 109 return new BasicCallResolutionContext( 110 trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, 111 dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition); 112 } 113 114 public void performContextDependentCallChecks(@NotNull ResolvedCall<?> resolvedCall) { 115 callChecker.check(resolvedCall, this); 116 } 117 }