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.tasks; 018 019 import com.intellij.util.SmartList; 020 import kotlin.jvm.functions.Function0; 021 import org.jetbrains.annotations.NotNull; 022 import org.jetbrains.annotations.Nullable; 023 import org.jetbrains.kotlin.descriptors.CallableDescriptor; 024 import org.jetbrains.kotlin.psi.Call; 025 import org.jetbrains.kotlin.resolve.BindingTrace; 026 import org.jetbrains.kotlin.resolve.StatementFilter; 027 import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker; 028 import org.jetbrains.kotlin.resolve.calls.context.*; 029 import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments; 030 import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall; 031 import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo; 032 import org.jetbrains.kotlin.resolve.scopes.LexicalScope; 033 import org.jetbrains.kotlin.types.KotlinType; 034 035 import java.util.Collection; 036 037 /** 038 * Stores candidates for call resolution. 039 */ 040 public class ResolutionTask<D extends CallableDescriptor, F extends D> extends CallResolutionContext<ResolutionTask<D, F>> { 041 private final Function0<Collection<ResolutionCandidate<D>>> lazyCandidates; 042 private final Collection<MutableResolvedCall<F>> resolvedCalls; 043 public final TracingStrategy tracing; 044 045 private ResolutionTask( 046 @NotNull Function0<Collection<ResolutionCandidate<D>>> lazyCandidates, 047 @NotNull TracingStrategy tracing, 048 @NotNull BindingTrace trace, 049 @NotNull LexicalScope scope, 050 @NotNull Call call, 051 @NotNull KotlinType expectedType, 052 @NotNull DataFlowInfo dataFlowInfo, 053 @NotNull ContextDependency contextDependency, 054 @NotNull CheckArgumentTypesMode checkArguments, 055 @NotNull ResolutionResultsCache resolutionResultsCache, 056 @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments, 057 @NotNull CallChecker callChecker, 058 @NotNull StatementFilter statementFilter, 059 @NotNull Collection<MutableResolvedCall<F>> resolvedCalls, 060 boolean isAnnotationContext, 061 boolean isDebuggerContext, 062 boolean collectAllCandidates, 063 @NotNull CallPosition callPosition 064 ) { 065 super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, 066 dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition); 067 this.lazyCandidates = lazyCandidates; 068 this.resolvedCalls = resolvedCalls; 069 this.tracing = tracing; 070 } 071 072 public ResolutionTask( 073 @NotNull BasicCallResolutionContext context, 074 @NotNull TracingStrategy tracing, 075 @NotNull Function0<Collection<ResolutionCandidate<D>>> lazyCandidates 076 ) { 077 this(lazyCandidates, tracing, 078 context.trace, context.scope, context.call, 079 context.expectedType, context.dataFlowInfo, context.contextDependency, context.checkArguments, 080 context.resolutionResultsCache, context.dataFlowInfoForArguments, 081 context.callChecker, 082 context.statementFilter, new SmartList<MutableResolvedCall<F>>(), 083 context.isAnnotationContext, context.isDebuggerContext, context.collectAllCandidates, context.callPosition); 084 } 085 086 @NotNull 087 public Collection<ResolutionCandidate<D>> getCandidates() { 088 return lazyCandidates.invoke(); 089 } 090 091 public void addResolvedCall(@NotNull MutableResolvedCall<F> resolvedCall) { 092 resolvedCalls.add(resolvedCall); 093 } 094 095 @NotNull 096 public Collection<MutableResolvedCall<F>> getResolvedCalls() { 097 return resolvedCalls; 098 } 099 100 @Override 101 protected ResolutionTask<D, F> create( 102 @NotNull BindingTrace trace, 103 @NotNull LexicalScope scope, 104 @NotNull DataFlowInfo dataFlowInfo, 105 @NotNull KotlinType expectedType, 106 @NotNull ContextDependency contextDependency, 107 @NotNull ResolutionResultsCache resolutionResultsCache, 108 @NotNull StatementFilter statementFilter, 109 boolean collectAllCandidates, 110 @NotNull CallPosition callPosition 111 ) { 112 return new ResolutionTask<D, F>( 113 lazyCandidates, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, 114 resolutionResultsCache, dataFlowInfoForArguments, 115 callChecker, 116 statementFilter, resolvedCalls, 117 isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition); 118 } 119 120 @Override 121 public String toString() { 122 return lazyCandidates.toString(); 123 } 124 }