Added 'call' reference to ResolvedCall

This commit is contained in:
Svetlana Isakova
2014-03-17 12:05:37 +04:00
parent a829da185d
commit f9ebf217a4
10 changed files with 84 additions and 36 deletions
@@ -253,7 +253,8 @@ public class CallResolver {
return checkArgumentTypesAndFail(context);
}
Collection<ResolutionCandidate<CallableDescriptor>> candidates =
TaskPrioritizer.<CallableDescriptor>convertWithImpliedThisAndNoReceiver(context.scope, constructors);
TaskPrioritizer.<CallableDescriptor>convertWithImpliedThisAndNoReceiver(
context.scope, constructors, context.call);
prioritizedTasks = TaskPrioritizer.<CallableDescriptor, FunctionDescriptor>computePrioritizedTasksFromCandidates(
context, candidates, TracingStrategyImpl.create(functionReference, context.call));
}
@@ -276,7 +277,8 @@ public class CallResolver {
context.trace.report(NO_CONSTRUCTOR.on(reportAbsenceOn));
return checkArgumentTypesAndFail(context);
}
List<ResolutionCandidate<CallableDescriptor>> candidates = ResolutionCandidate.<CallableDescriptor>convertCollection(constructors, JetPsiUtil.isSafeCall(context.call));
List<ResolutionCandidate<CallableDescriptor>> candidates = ResolutionCandidate.<CallableDescriptor>convertCollection(
context.call, constructors, JetPsiUtil.isSafeCall(context.call));
prioritizedTasks = Collections.singletonList(new ResolutionTask<CallableDescriptor, FunctionDescriptor>(candidates, functionReference, context)); // !! DataFlowInfo.EMPTY
}
else if (calleeExpression != null) {
@@ -114,7 +114,8 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
candidate, variableCall, candidateTrace, task);
ResolutionCandidate<CallableDescriptor> candidateWithoutReceiver = ResolutionCandidate.create(
candidate.getDescriptor(), candidate.getThisObject(), ReceiverValue.NO_RECEIVER, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, false);
candidate.getCall(), candidate.getDescriptor(), candidate.getThisObject(), ReceiverValue.NO_RECEIVER,
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, false);
CallCandidateResolutionContext<CallableDescriptor> contextWithoutReceiver = createContextWithChainedTrace(
candidateWithoutReceiver, variableCallWithoutReceiver, candidateTrace, task);
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.jet.lang.types.JetType;
@@ -35,6 +36,12 @@ public abstract class DelegatingResolvedCall<D extends CallableDescriptor> imple
this.resolvedCall = resolvedCall;
}
@NotNull
@Override
public Call getCall() {
return resolvedCall.getCall();
}
@NotNull
@Override
public D getCandidateDescriptor() {
@@ -21,8 +21,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.ValueArgument;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.jet.lang.types.JetType;
@@ -31,6 +30,10 @@ import java.util.List;
import java.util.Map;
public interface ResolvedCall<D extends CallableDescriptor> {
/** The call that was resolved to this ResolvedCall */
@NotNull
Call getCall();
/** A target callable descriptor as it was accessible in the corresponding scope, i.e. with type arguments not substituted */
@NotNull
D getCandidateDescriptor();
@@ -63,6 +66,7 @@ public interface ResolvedCall<D extends CallableDescriptor> {
@NotNull
Map<TypeParameterDescriptor, JetType> getTypeArguments();
/** Data flow info for each argument and the result data flow info */
@NotNull
DataFlowInfoForArguments getDataFlowInfoForArguments();
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.psi.ValueArgument;
import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil;
@@ -69,6 +70,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
return new ResolvedCallImpl<D>(candidate, trace, tracing, dataFlowInfoForArguments);
}
private final Call call;
private final D candidateDescriptor;
private D resultingDescriptor; // Probably substituted
private final ReceiverValue thisObject; // receiver object of a method
@@ -96,6 +98,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
@NotNull TracingStrategy tracing,
@NotNull MutableDataFlowInfoForArguments dataFlowInfoForArguments
) {
this.call = candidate.getCall();
this.candidateDescriptor = candidate.getDescriptor();
this.thisObject = candidate.getThisObject();
this.receiverArgument = candidate.getReceiverArgument();
@@ -143,6 +146,12 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
return tracing;
}
@NotNull
@Override
public Call getCall() {
return call;
}
@Override
@NotNull
public D getCandidateDescriptor() {
@@ -22,6 +22,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
@@ -51,6 +52,12 @@ public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<Fun
return variableCall;
}
@NotNull
@Override
public Call getCall() {
return variableCall.getCall();
}
@NotNull
@Override
public FunctionDescriptor getCandidateDescriptor() {
@@ -20,6 +20,7 @@ import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
import java.util.Collection;
@@ -28,14 +29,18 @@ import java.util.List;
import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER;
public class ResolutionCandidate<D extends CallableDescriptor> {
private final Call call;
private final D candidateDescriptor;
private ReceiverValue thisObject; // receiver object of a method
private ReceiverValue receiverArgument; // receiver of an extension function
private ExplicitReceiverKind explicitReceiverKind;
private Boolean isSafeCall;
private ResolutionCandidate(@NotNull D descriptor, @NotNull ReceiverValue thisObject, @NotNull ReceiverValue receiverArgument,
@NotNull ExplicitReceiverKind explicitReceiverKind, @Nullable Boolean isSafeCall) {
private ResolutionCandidate(
@NotNull Call call, @NotNull D descriptor, @NotNull ReceiverValue thisObject,
@NotNull ReceiverValue receiverArgument, @NotNull ExplicitReceiverKind explicitReceiverKind, @Nullable Boolean isSafeCall
) {
this.call = call;
this.candidateDescriptor = descriptor;
this.thisObject = thisObject;
this.receiverArgument = receiverArgument;
@@ -43,18 +48,22 @@ public class ResolutionCandidate<D extends CallableDescriptor> {
this.isSafeCall = isSafeCall;
}
/*package*/ static <D extends CallableDescriptor> ResolutionCandidate<D> create(@NotNull D descriptor) {
return new ResolutionCandidate<D>(descriptor, NO_RECEIVER, NO_RECEIVER, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, null);
/*package*/ static <D extends CallableDescriptor> ResolutionCandidate<D> create(@NotNull Call call, @NotNull D descriptor) {
return new ResolutionCandidate<D>(call, descriptor, NO_RECEIVER, NO_RECEIVER, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, null);
}
/* 'null' for isSafeCall parameter if it should be set later (with 'setSafeCall') */
public static <D extends CallableDescriptor> ResolutionCandidate<D> create(@NotNull D descriptor, @Nullable Boolean isSafeCall) {
return new ResolutionCandidate<D>(descriptor, NO_RECEIVER, NO_RECEIVER, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, isSafeCall);
public static <D extends CallableDescriptor> ResolutionCandidate<D> create(
@NotNull Call call, @NotNull D descriptor, @Nullable Boolean isSafeCall
) {
return new ResolutionCandidate<D>(call, descriptor, NO_RECEIVER, NO_RECEIVER, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, isSafeCall);
}
public static <D extends CallableDescriptor> ResolutionCandidate<D> create(@NotNull D descriptor, @NotNull ReceiverValue thisObject,
@NotNull ReceiverValue receiverArgument, @NotNull ExplicitReceiverKind explicitReceiverKind, boolean isSafeCall) {
return new ResolutionCandidate<D>(descriptor, thisObject, receiverArgument, explicitReceiverKind, isSafeCall);
public static <D extends CallableDescriptor> ResolutionCandidate<D> create(
@NotNull Call call, @NotNull D descriptor, @NotNull ReceiverValue thisObject,
@NotNull ReceiverValue receiverArgument, @NotNull ExplicitReceiverKind explicitReceiverKind, boolean isSafeCall
) {
return new ResolutionCandidate<D>(call, descriptor, thisObject, receiverArgument, explicitReceiverKind, isSafeCall);
}
public void setThisObject(@NotNull ReceiverValue thisObject) {
@@ -69,6 +78,11 @@ public class ResolutionCandidate<D extends CallableDescriptor> {
this.explicitReceiverKind = explicitReceiverKind;
}
@NotNull
public Call getCall() {
return call;
}
@NotNull
public D getDescriptor() {
return candidateDescriptor;
@@ -90,10 +104,12 @@ public class ResolutionCandidate<D extends CallableDescriptor> {
}
@NotNull
public static <D extends CallableDescriptor> List<ResolutionCandidate<D>> convertCollection(@NotNull Collection<? extends D> descriptors, boolean isSafeCall) {
public static <D extends CallableDescriptor> List<ResolutionCandidate<D>> convertCollection(
@NotNull Call call, @NotNull Collection<? extends D> descriptors, boolean isSafeCall
) {
List<ResolutionCandidate<D>> result = Lists.newArrayList();
for (D descriptor : descriptors) {
result.add(create(descriptor, isSafeCall));
result.add(create(call, descriptor, isSafeCall));
}
return result;
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.psi.JetSuperExpression;
@@ -141,7 +142,7 @@ public class TaskPrioritizer {
Collection<? extends D> membersForThisVariant =
callableDescriptorCollector.getMembersByName(type, c.name, c.context.trace);
convertWithReceivers(membersForThisVariant, explicitReceiver,
NO_RECEIVER, members, createKind(THIS_OBJECT, isExplicit));
NO_RECEIVER, members, createKind(THIS_OBJECT, isExplicit), c.context.call);
}
c.result.addCandidates(members);
}
@@ -155,7 +156,7 @@ public class TaskPrioritizer {
//extensions
Collection<ResolutionCandidate<D>> extensions = convertWithImpliedThis(
c.scope, explicitReceiver, callableDescriptorCollector.getNonMembersByName(c.scope, c.name, c.context.trace),
createKind(RECEIVER_ARGUMENT, isExplicit));
createKind(RECEIVER_ARGUMENT, isExplicit), c.context.call);
c.result.addCandidates(extensions);
}
}
@@ -174,7 +175,7 @@ public class TaskPrioritizer {
Collection<? extends D> memberExtensions = callableDescriptorCollector.getNonMembersByName(
thisObject.getType().getMemberScope(), c.name, c.context.trace);
c.result.addCandidates(convertWithReceivers(
memberExtensions, thisObject, receiverParameter, receiverKind));
memberExtensions, thisObject, receiverParameter, receiverKind, c.context.call));
}
private static <D extends CallableDescriptor, F extends D> void addCandidatesForNoReceiver(
@@ -186,7 +187,7 @@ public class TaskPrioritizer {
for (CallableDescriptorCollector<? extends D> callableDescriptorCollector : c.callableDescriptorCollectors) {
Collection<ResolutionCandidate<D>> members = convertWithImpliedThisAndNoReceiver(
c.scope, callableDescriptorCollector.getNonExtensionsByName(c.scope, c.name, c.context.trace));
c.scope, callableDescriptorCollector.getNonExtensionsByName(c.scope, c.name, c.context.trace), c.context.call);
List<ResolutionCandidate<D>> nonlocals = Lists.newArrayList();
List<ResolutionCandidate<D>> locals = Lists.newArrayList();
@@ -261,10 +262,11 @@ public class TaskPrioritizer {
@NotNull Collection<? extends D> descriptors,
@NotNull ReceiverValue thisObject,
@NotNull ReceiverValue receiverParameter,
@NotNull ExplicitReceiverKind explicitReceiverKind
@NotNull ExplicitReceiverKind explicitReceiverKind,
@NotNull Call call
) {
Collection<ResolutionCandidate<D>> result = Lists.newArrayList();
convertWithReceivers(descriptors, thisObject, receiverParameter, result, explicitReceiverKind);
convertWithReceivers(descriptors, thisObject, receiverParameter, result, explicitReceiverKind, call);
return result;
}
@@ -273,14 +275,15 @@ public class TaskPrioritizer {
@NotNull ReceiverValue thisObject,
@NotNull ReceiverValue receiverParameter,
@NotNull Collection<ResolutionCandidate<D>> result,
@NotNull ExplicitReceiverKind explicitReceiverKind
@NotNull ExplicitReceiverKind explicitReceiverKind,
@NotNull Call call
) {
for (D extension : descriptors) {
if (DescriptorUtils.isConstructorOfStaticNestedClass(extension)) {
// We don't want static nested classes' constructors to be resolved with expectedThisObject
continue;
}
ResolutionCandidate<D> candidate = ResolutionCandidate.create(extension);
ResolutionCandidate<D> candidate = ResolutionCandidate.create(call, extension);
candidate.setThisObject(thisObject);
candidate.setReceiverArgument(receiverParameter);
candidate.setExplicitReceiverKind(explicitReceiverKind);
@@ -290,20 +293,22 @@ public class TaskPrioritizer {
public static <D extends CallableDescriptor> Collection<ResolutionCandidate<D>> convertWithImpliedThisAndNoReceiver(
@NotNull JetScope scope,
@NotNull Collection<? extends D> descriptors
@NotNull Collection<? extends D> descriptors,
@NotNull Call call
) {
return convertWithImpliedThis(scope, NO_RECEIVER, descriptors, NO_EXPLICIT_RECEIVER);
return convertWithImpliedThis(scope, NO_RECEIVER, descriptors, NO_EXPLICIT_RECEIVER, call);
}
public static <D extends CallableDescriptor> Collection<ResolutionCandidate<D>> convertWithImpliedThis(
@NotNull JetScope scope,
@NotNull ReceiverValue receiverParameter,
@NotNull Collection<? extends D> descriptors,
ExplicitReceiverKind receiverKind
@NotNull ExplicitReceiverKind receiverKind,
@NotNull Call call
) {
Collection<ResolutionCandidate<D>> result = Lists.newArrayList();
for (D descriptor : descriptors) {
ResolutionCandidate<D> candidate = ResolutionCandidate.create(descriptor);
ResolutionCandidate<D> candidate = ResolutionCandidate.create(call, descriptor);
candidate.setReceiverArgument(receiverParameter);
candidate.setExplicitReceiverKind(receiverKind);
if (setImpliedThis(scope, candidate)) {
@@ -411,14 +411,11 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetExpression expression
) {
BindingTrace trace = context.trace;
ResolutionCandidate<ReceiverParameterDescriptor> resolutionCandidate =
ResolutionCandidate.create(descriptor,
NO_RECEIVER,
NO_RECEIVER,
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER,
false);
Call call = CallMaker.makeCall(expression, NO_RECEIVER, null, expression, Collections.<ValueArgument>emptyList());
ResolutionCandidate<ReceiverParameterDescriptor> resolutionCandidate =
ResolutionCandidate.create(
call, descriptor, NO_RECEIVER, NO_RECEIVER, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, false);
ResolvedCallImpl<ReceiverParameterDescriptor> resolvedCall =
ResolvedCallImpl.create(resolutionCandidate,
TemporaryBindingTrace.create(trace, "Fake trace for fake 'this' or 'super' resolved call"),
@@ -73,7 +73,7 @@ public class ControlStructureTypingUtils {
SimpleFunctionDescriptorImpl function = createFunctionDescriptorForSpecialConstruction(
constructionName.toUpperCase(), argumentNames, isArgumentNullable);
TracingStrategy tracing = createTracingForSpecialConstruction(call, constructionName);
ResolutionCandidate<CallableDescriptor> resolutionCandidate = ResolutionCandidate.<CallableDescriptor>create(function, null);
ResolutionCandidate<CallableDescriptor> resolutionCandidate = ResolutionCandidate.<CallableDescriptor>create(call, function, null);
CallResolver callResolver = expressionTypingServices.getCallResolver();
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithKnownCandidate(
call, tracing, context, resolutionCandidate, dataFlowInfoForArguments);