Minor. Created CandidateResolveMode in CallCandidateResolutionContext.

This commit is contained in:
Stanislav Erokhin
2015-07-15 17:02:23 +03:00
parent 3c56787514
commit b00dab0db5
4 changed files with 50 additions and 27 deletions
@@ -575,7 +575,8 @@ public class CallResolver {
public Unit invoke() { public Unit invoke() {
TemporaryBindingTrace candidateTrace = TemporaryBindingTrace.create( TemporaryBindingTrace candidateTrace = TemporaryBindingTrace.create(
task.trace, "trace to resolve candidate"); task.trace, "trace to resolve candidate");
Collection<CallCandidateResolutionContext<D>> contexts = callTransformer.createCallContexts(resolutionCandidate, task, candidateTrace); Collection<CallCandidateResolutionContext<D>> contexts =
callTransformer.createCallContexts(resolutionCandidate, task, candidateTrace, CandidateResolveMode.FULLY);
for (CallCandidateResolutionContext<D> context : contexts) { for (CallCandidateResolutionContext<D> context : contexts) {
candidateResolver.performResolutionForCandidateCall(context, task); candidateResolver.performResolutionForCandidateCall(context, task);
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.DelegatingBindingTrace;
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace; import org.jetbrains.kotlin.resolve.TemporaryBindingTrace;
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext; import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext;
import org.jetbrains.kotlin.resolve.calls.context.CallCandidateResolutionContext; import org.jetbrains.kotlin.resolve.calls.context.CallCandidateResolutionContext;
import org.jetbrains.kotlin.resolve.calls.context.CandidateResolveMode;
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency; import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall; import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl;
@@ -73,10 +74,12 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
@NotNull @NotNull
public Collection<CallCandidateResolutionContext<D>> createCallContexts(@NotNull ResolutionCandidate<D> candidate, public Collection<CallCandidateResolutionContext<D>> createCallContexts(@NotNull ResolutionCandidate<D> candidate,
@NotNull ResolutionTask<D, F> task, @NotNull ResolutionTask<D, F> task,
@NotNull TemporaryBindingTrace candidateTrace @NotNull TemporaryBindingTrace candidateTrace,
@NotNull CandidateResolveMode candidateResolveMode
) { ) {
ResolvedCallImpl<D> candidateCall = ResolvedCallImpl.create(candidate, candidateTrace, task.tracing, task.dataFlowInfoForArguments); ResolvedCallImpl<D> candidateCall = ResolvedCallImpl.create(candidate, candidateTrace, task.tracing, task.dataFlowInfoForArguments);
return Collections.singleton(CallCandidateResolutionContext.create(candidateCall, task, candidateTrace, task.tracing)); return Collections.singleton(CallCandidateResolutionContext.create(candidateCall, task, candidateTrace, task.tracing, task.call,
ReceiverValue.NO_RECEIVER, candidateResolveMode));
} }
/** /**
@@ -100,10 +103,12 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
@NotNull @NotNull
@Override @Override
public Collection<CallCandidateResolutionContext<CallableDescriptor>> createCallContexts(@NotNull ResolutionCandidate<CallableDescriptor> candidate, public Collection<CallCandidateResolutionContext<CallableDescriptor>> createCallContexts(@NotNull ResolutionCandidate<CallableDescriptor> candidate,
@NotNull ResolutionTask<CallableDescriptor, FunctionDescriptor> task, @NotNull TemporaryBindingTrace candidateTrace) { @NotNull ResolutionTask<CallableDescriptor, FunctionDescriptor> task, @NotNull TemporaryBindingTrace candidateTrace,
@NotNull CandidateResolveMode candidateResolveMode
) {
if (candidate.getDescriptor() instanceof FunctionDescriptor) { if (candidate.getDescriptor() instanceof FunctionDescriptor) {
return super.createCallContexts(candidate, task, candidateTrace); return super.createCallContexts(candidate, task, candidateTrace, candidateResolveMode);
} }
assert candidate.getDescriptor() instanceof VariableDescriptor; assert candidate.getDescriptor() instanceof VariableDescriptor;
@@ -120,11 +125,11 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
if (!hasReceiver) { if (!hasReceiver) {
CallCandidateResolutionContext<CallableDescriptor> context = CallCandidateResolutionContext.create( CallCandidateResolutionContext<CallableDescriptor> context = CallCandidateResolutionContext.create(
ResolvedCallImpl.create(variableCandidate, candidateTrace, task.tracing, task.dataFlowInfoForArguments), ResolvedCallImpl.create(variableCandidate, candidateTrace, task.tracing, task.dataFlowInfoForArguments),
task, candidateTrace, task.tracing, variableCall); task, candidateTrace, task.tracing, variableCall, ReceiverValue.NO_RECEIVER, candidateResolveMode);
return Collections.singleton(context); return Collections.singleton(context);
} }
CallCandidateResolutionContext<CallableDescriptor> contextWithReceiver = createContextWithChainedTrace( CallCandidateResolutionContext<CallableDescriptor> contextWithReceiver = createContextWithChainedTrace(
variableCandidate, variableCall, candidateTrace, task, ReceiverValue.NO_RECEIVER); variableCandidate, variableCall, candidateTrace, task, ReceiverValue.NO_RECEIVER, candidateResolveMode);
Call variableCallWithoutReceiver = stripReceiver(variableCall); Call variableCallWithoutReceiver = stripReceiver(variableCall);
ResolutionCandidate<CallableDescriptor> candidateWithoutReceiver = ResolutionCandidate.create( ResolutionCandidate<CallableDescriptor> candidateWithoutReceiver = ResolutionCandidate.create(
@@ -135,18 +140,21 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, null); ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, null);
CallCandidateResolutionContext<CallableDescriptor> contextWithoutReceiver = createContextWithChainedTrace( CallCandidateResolutionContext<CallableDescriptor> contextWithoutReceiver = createContextWithChainedTrace(
candidateWithoutReceiver, variableCallWithoutReceiver, candidateTrace, task, variableCall.getExplicitReceiver()); candidateWithoutReceiver, variableCallWithoutReceiver, candidateTrace, task, variableCall.getExplicitReceiver(),
candidateResolveMode);
return Lists.newArrayList(contextWithReceiver, contextWithoutReceiver); return Lists.newArrayList(contextWithReceiver, contextWithoutReceiver);
} }
private CallCandidateResolutionContext<CallableDescriptor> createContextWithChainedTrace( private CallCandidateResolutionContext<CallableDescriptor> createContextWithChainedTrace(
@NotNull ResolutionCandidate<CallableDescriptor> candidate, @NotNull Call call, @NotNull TemporaryBindingTrace temporaryTrace, @NotNull ResolutionCandidate<CallableDescriptor> candidate, @NotNull Call call, @NotNull TemporaryBindingTrace temporaryTrace,
@NotNull ResolutionTask<CallableDescriptor, FunctionDescriptor> task, @NotNull ReceiverValue receiverValue @NotNull ResolutionTask<CallableDescriptor, FunctionDescriptor> task, @NotNull ReceiverValue receiverValue,
@NotNull CandidateResolveMode candidateResolveMode
) { ) {
ChainedTemporaryBindingTrace chainedTrace = ChainedTemporaryBindingTrace.create(temporaryTrace, "chained trace to resolve candidate", candidate); ChainedTemporaryBindingTrace chainedTrace = ChainedTemporaryBindingTrace.create(temporaryTrace, "chained trace to resolve candidate", candidate);
ResolvedCallImpl<CallableDescriptor> resolvedCall = ResolvedCallImpl.create(candidate, chainedTrace, task.tracing, task.dataFlowInfoForArguments); ResolvedCallImpl<CallableDescriptor> resolvedCall = ResolvedCallImpl.create(candidate, chainedTrace, task.tracing, task.dataFlowInfoForArguments);
return CallCandidateResolutionContext.create(resolvedCall, task, chainedTrace, task.tracing, call, receiverValue); return CallCandidateResolutionContext.create(resolvedCall, task, chainedTrace, task.tracing, call, receiverValue,
candidateResolveMode);
} }
private Call stripCallArguments(@NotNull Call call) { private Call stripCallArguments(@NotNull Call call) {
@@ -40,6 +40,8 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
public final TracingStrategy tracing; public final TracingStrategy tracing;
@NotNull @NotNull
public final ReceiverValue explicitExtensionReceiverForInvoke; public final ReceiverValue explicitExtensionReceiverForInvoke;
@NotNull
public final CandidateResolveMode candidateResolveMode;
private CallCandidateResolutionContext( private CallCandidateResolutionContext(
@NotNull MutableResolvedCall<D> candidateCall, @NotNull MutableResolvedCall<D> candidateCall,
@@ -58,6 +60,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@NotNull AdditionalTypeChecker additionalTypeChecker, @NotNull AdditionalTypeChecker additionalTypeChecker,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
@NotNull ReceiverValue explicitExtensionReceiverForInvoke, @NotNull ReceiverValue explicitExtensionReceiverForInvoke,
@NotNull CandidateResolveMode candidateResolveMode,
boolean isAnnotationContext, boolean isAnnotationContext,
boolean collectAllCandidates, boolean collectAllCandidates,
boolean insideSafeCallChain boolean insideSafeCallChain
@@ -68,11 +71,13 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
this.candidateCall = candidateCall; this.candidateCall = candidateCall;
this.tracing = tracing; this.tracing = tracing;
this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke; this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke;
this.candidateResolveMode = candidateResolveMode;
} }
public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create( public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
@NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace, @NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
@NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke @NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke,
@NotNull CandidateResolveMode candidateResolveMode
) { ) {
candidateCall.getDataFlowInfoForArguments().setInitialDataFlowInfo(context.dataFlowInfo); candidateCall.getDataFlowInfoForArguments().setInitialDataFlowInfo(context.dataFlowInfo);
return new CallCandidateResolutionContext<D>( return new CallCandidateResolutionContext<D>(
@@ -80,20 +85,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
context.dataFlowInfo, context.contextDependency, context.checkArguments, context.dataFlowInfo, context.contextDependency, context.checkArguments,
context.resolutionResultsCache, context.dataFlowInfoForArguments, context.resolutionResultsCache, context.dataFlowInfoForArguments,
context.callChecker, context.symbolUsageValidator, context.additionalTypeChecker, context.statementFilter, explicitExtensionReceiverForInvoke, context.callChecker, context.symbolUsageValidator, context.additionalTypeChecker, context.statementFilter, explicitExtensionReceiverForInvoke,
context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); candidateResolveMode, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain);
}
public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
@NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
@NotNull TracingStrategy tracing, @NotNull Call call
) {
return create(candidateCall, context, trace, tracing, call, ReceiverValue.NO_RECEIVER);
}
public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
@NotNull MutableResolvedCall<D> candidateCall, @NotNull CallResolutionContext<?> context, @NotNull BindingTrace trace,
@NotNull TracingStrategy tracing) {
return create(candidateCall, context, trace, tracing, context.call);
} }
@NotNull @NotNull
@@ -104,7 +96,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType, candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache, context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
context.dataFlowInfoForArguments, context.callChecker, context.symbolUsageValidator, context.additionalTypeChecker, context.statementFilter, context.dataFlowInfoForArguments, context.callChecker, context.symbolUsageValidator, context.additionalTypeChecker, context.statementFilter,
ReceiverValue.NO_RECEIVER, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); ReceiverValue.NO_RECEIVER, CandidateResolveMode.FULLY, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain);
} }
@Override @Override
@@ -122,6 +114,6 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
return new CallCandidateResolutionContext<D>( return new CallCandidateResolutionContext<D>(
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
resolutionResultsCache, dataFlowInfoForArguments, callChecker, symbolUsageValidator, additionalTypeChecker, statementFilter, resolutionResultsCache, dataFlowInfoForArguments, callChecker, symbolUsageValidator, additionalTypeChecker, statementFilter,
explicitExtensionReceiverForInvoke, isAnnotationContext, collectAllCandidates, insideSafeCallChain); explicitExtensionReceiverForInvoke, candidateResolveMode, isAnnotationContext, collectAllCandidates, insideSafeCallChain);
} }
} }
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.calls.context;
public enum CandidateResolveMode {
FULLY,
EXIT_ON_FIRST_ERROR
}