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 org.jetbrains.annotations.NotNull; 020 import org.jetbrains.annotations.Nullable; 021 import org.jetbrains.kotlin.descriptors.CallableDescriptor; 022 import org.jetbrains.kotlin.psi.Call; 023 import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver; 024 import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; 025 import org.jetbrains.kotlin.types.TypeSubstitutor; 026 027 public class ResolutionCandidate<D extends CallableDescriptor> { 028 private final Call call; 029 private final D candidateDescriptor; 030 private final TypeSubstitutor knownTypeParametersResultingSubstitutor; 031 private ReceiverValue dispatchReceiver; // receiver object of a method 032 private Receiver receiverArgument; // receiver of an extension function 033 private ExplicitReceiverKind explicitReceiverKind; 034 035 private ResolutionCandidate( 036 @NotNull Call call, @NotNull D descriptor, @Nullable ReceiverValue dispatchReceiver, 037 @Nullable Receiver receiverArgument, @NotNull ExplicitReceiverKind explicitReceiverKind, 038 @Nullable TypeSubstitutor knownTypeParametersResultingSubstitutor 039 ) { 040 this.call = call; 041 this.candidateDescriptor = descriptor; 042 this.dispatchReceiver = dispatchReceiver; 043 this.receiverArgument = receiverArgument; 044 this.explicitReceiverKind = explicitReceiverKind; 045 this.knownTypeParametersResultingSubstitutor = knownTypeParametersResultingSubstitutor; 046 } 047 048 public static <D extends CallableDescriptor> ResolutionCandidate<D> create( 049 @NotNull Call call, @NotNull D descriptor 050 ) { 051 return new ResolutionCandidate<D>(call, descriptor, null, null, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, null); 052 } 053 054 public static <D extends CallableDescriptor> ResolutionCandidate<D> create( 055 @NotNull Call call, @NotNull D descriptor, @Nullable TypeSubstitutor knownTypeParametersResultingSubstitutor 056 ) { 057 return new ResolutionCandidate<D>(call, descriptor, 058 null, null, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, 059 knownTypeParametersResultingSubstitutor); 060 } 061 062 public static <D extends CallableDescriptor> ResolutionCandidate<D> create( 063 @NotNull Call call, @NotNull D descriptor, @Nullable ReceiverValue dispatchReceiver, 064 @Nullable Receiver receiverArgument, @NotNull ExplicitReceiverKind explicitReceiverKind, 065 @Nullable TypeSubstitutor knownTypeParametersResultingSubstitutor 066 ) { 067 return new ResolutionCandidate<D>(call, descriptor, dispatchReceiver, receiverArgument, explicitReceiverKind, 068 knownTypeParametersResultingSubstitutor); 069 } 070 071 public void setDispatchReceiver(@Nullable ReceiverValue dispatchReceiver) { 072 this.dispatchReceiver = dispatchReceiver; 073 } 074 075 public void setReceiverArgument(@Nullable ReceiverValue receiverArgument) { 076 this.receiverArgument = receiverArgument; 077 } 078 079 public void setExplicitReceiverKind(@NotNull ExplicitReceiverKind explicitReceiverKind) { 080 this.explicitReceiverKind = explicitReceiverKind; 081 } 082 083 @NotNull 084 public Call getCall() { 085 return call; 086 } 087 088 @NotNull 089 public D getDescriptor() { 090 return candidateDescriptor; 091 } 092 093 @Nullable 094 public ReceiverValue getDispatchReceiver() { 095 return dispatchReceiver; 096 } 097 098 @Nullable 099 public Receiver getReceiverArgument() { 100 return receiverArgument; 101 } 102 103 @NotNull 104 public ExplicitReceiverKind getExplicitReceiverKind() { 105 return explicitReceiverKind; 106 } 107 108 @Nullable 109 public TypeSubstitutor getKnownTypeParametersResultingSubstitutor() { 110 return knownTypeParametersResultingSubstitutor; 111 } 112 113 @Override 114 public String toString() { 115 return candidateDescriptor.toString(); 116 } 117 }