added 'namespacesAllowed' flag to ResolutionContext

This commit is contained in:
Svetlana Isakova
2013-01-25 17:23:06 +04:00
parent 5cc6af0f54
commit 97e1f0ba3c
7 changed files with 51 additions and 26 deletions
@@ -25,16 +25,23 @@ import org.jetbrains.jet.lang.types.JetType;
public class BasicResolutionContext extends ResolutionContext {
@NotNull
public static BasicResolutionContext create(@NotNull BindingTrace trace, @NotNull JetScope scope, @NotNull Call call, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo) {
return new BasicResolutionContext(trace, scope, call, expectedType, dataFlowInfo);
public static BasicResolutionContext create(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull Call call,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
boolean namespacesAllowed
) {
return new BasicResolutionContext(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
}
private BasicResolutionContext(BindingTrace trace, JetScope scope, Call call, JetType expectedType, DataFlowInfo dataFlowInfo) {
super(trace, scope, call, expectedType, dataFlowInfo);
private BasicResolutionContext(BindingTrace trace, JetScope scope, Call call, JetType expectedType, DataFlowInfo dataFlowInfo, boolean namespacesAllowed) {
super(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
}
@NotNull
public BasicResolutionContext replaceTrace(@NotNull BindingTrace trace) {
return create(trace, scope, call, expectedType, dataFlowInfo);
return create(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
}
}
@@ -30,29 +30,41 @@ public final class CallResolutionContext<D extends CallableDescriptor, F extends
/*package*/ final TracingStrategy tracing;
/*package*/ ReceiverValue receiverForVariableAsFunctionSecondCall = ReceiverValue.NO_RECEIVER;
private CallResolutionContext(@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing, @NotNull Call call) {
super(trace, task.scope, call, task.expectedType, task.dataFlowInfo);
private CallResolutionContext(
@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace,
@NotNull TracingStrategy tracing, @NotNull Call call, boolean namespacesAllowed
) {
super(trace, task.scope, call, task.expectedType, task.dataFlowInfo, namespacesAllowed);
this.candidateCall = candidateCall;
this.tracing = tracing;
this.candidateCall.setInitialDataFlowInfo(dataFlowInfo);
}
private CallResolutionContext(@NotNull BasicResolutionContext context, @NotNull TracingStrategy tracing, @NotNull ResolvedCallImpl<D> candidateCall) {
super(context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo);
private CallResolutionContext(
@NotNull BasicResolutionContext context, @NotNull TracingStrategy tracing,
@NotNull ResolvedCallImpl<D> candidateCall
) {
super(context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo, context.namespacesAllowed);
this.candidateCall = candidateCall;
this.tracing = tracing;
this.candidateCall.setInitialDataFlowInfo(dataFlowInfo);
}
public static <D extends CallableDescriptor, F extends D> CallResolutionContext<D, F> create(@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing, @NotNull Call call) {
return new CallResolutionContext<D, F>(candidateCall, task, trace, tracing, call);
public static <D extends CallableDescriptor, F extends D> CallResolutionContext<D, F> create(
@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace,
@NotNull TracingStrategy tracing, @NotNull Call call) {
return new CallResolutionContext<D, F>(candidateCall, task, trace, tracing, call, task.namespacesAllowed);
}
public static <D extends CallableDescriptor, F extends D> CallResolutionContext<D, F> create(@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing) {
public static <D extends CallableDescriptor, F extends D> CallResolutionContext<D, F> create(
@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace,
@NotNull TracingStrategy tracing) {
return create(candidateCall, task, trace, tracing, task.call);
}
public static <D extends CallableDescriptor> CallResolutionContext<D, D> create(@NotNull BasicResolutionContext context, @NotNull TracingStrategy tracing, @NotNull ResolvedCallImpl<D> candidateCall) {
public static <D extends CallableDescriptor> CallResolutionContext<D, D> create(
@NotNull BasicResolutionContext context, @NotNull TracingStrategy tracing,
@NotNull ResolvedCallImpl<D> candidateCall) {
return new CallResolutionContext<D, D>(context, tracing, candidateCall);
}
}
@@ -122,9 +122,9 @@ public class CallResolver {
@NotNull JetScope scope,
@NotNull Call call,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo) {
return resolveFunctionCall(BasicResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo));
@NotNull DataFlowInfo dataFlowInfo
) {
return resolveFunctionCall(BasicResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, false));
}
@NotNull
@@ -480,7 +480,7 @@ public class CallResolver {
public List<JetExpression> getFunctionLiteralArguments() {
return Collections.emptyList();
}
}, task.expectedType, task.dataFlowInfo);
}, task.expectedType, task.dataFlowInfo, task.namespacesAllowed);
OverloadResolutionResultsImpl<F> resultsWithFunctionLiteralsStripped = performResolution(newTask, callTransformer, traceForResolutionCache);
if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) {
task.tracing.danglingFunctionLiteralArgumentSuspected(task.trace, task.call.getFunctionLiteralArguments());
@@ -190,7 +190,8 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
Call functionCall = createFunctionCall(context, task, returnType);
final DelegatingBindingTrace variableCallTrace = context.candidateCall.getTrace();
BasicResolutionContext basicResolutionContext = BasicResolutionContext.create(variableCallTrace, context.scope, functionCall, context.expectedType, context.dataFlowInfo);
BasicResolutionContext basicResolutionContext = BasicResolutionContext.create(
variableCallTrace, context.scope, functionCall, context.expectedType, context.dataFlowInfo, context.namespacesAllowed);
// 'invoke' call resolve
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenName(basicResolutionContext, task.reference, Name.identifier("invoke"));
@@ -28,16 +28,18 @@ public abstract class ResolutionContext {
public final Call call;
public final JetType expectedType;
public final DataFlowInfo dataFlowInfo;
public final boolean namespacesAllowed;
protected ResolutionContext(BindingTrace trace, JetScope scope, Call call, JetType expectedType, DataFlowInfo dataFlowInfo) {
protected ResolutionContext(BindingTrace trace, JetScope scope, Call call, JetType expectedType, DataFlowInfo dataFlowInfo, boolean namespacesAllowed) {
this.trace = trace;
this.scope = scope;
this.call = call;
this.expectedType = expectedType;
this.dataFlowInfo = dataFlowInfo;
this.namespacesAllowed = namespacesAllowed;
}
public BasicResolutionContext toBasic() {
return BasicResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo);
return BasicResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
}
}
@@ -58,15 +58,16 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
public final JetReferenceExpression reference;
private DescriptorCheckStrategy checkingStrategy;
public ResolutionTask(@NotNull Collection<ResolutionCandidate<D>> candidates, @NotNull JetReferenceExpression reference,
BindingTrace trace, JetScope scope, Call call, JetType expectedType, DataFlowInfo dataFlowInfo) {
super(trace, scope, call, expectedType, dataFlowInfo);
public ResolutionTask(
@NotNull Collection<ResolutionCandidate<D>> candidates, @NotNull JetReferenceExpression reference,
BindingTrace trace, JetScope scope, Call call, JetType expectedType, DataFlowInfo dataFlowInfo, boolean namespacesAllowed) {
super(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
this.candidates = candidates;
this.reference = reference;
}
public ResolutionTask(@NotNull Collection<ResolutionCandidate<D>> candidates, @NotNull JetReferenceExpression reference, @NotNull BasicResolutionContext context) {
this(candidates, reference, context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo);
this(candidates, reference, context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo, context.namespacesAllowed);
}
@NotNull
@@ -91,7 +92,7 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
}
public ResolutionTask<D, F> withTrace(BindingTrace newTrace) {
ResolutionTask<D, F> newTask = new ResolutionTask<D, F>(candidates, reference, newTrace, scope, call, expectedType, dataFlowInfo);
ResolutionTask<D, F> newTask = new ResolutionTask<D, F>(candidates, reference, newTrace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
newTask.setCheckingStrategy(checkingStrategy);
return newTask;
}
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.psi.JetQualifiedExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
import org.jetbrains.jet.lang.resolve.BindingTrace;
@@ -34,6 +35,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.lang.types.TypeUtils;
import java.util.List;
@@ -143,7 +145,7 @@ public class ExpressionTypingContext {
////////// Call resolution utilities
private BasicResolutionContext makeResolutionContext(@NotNull Call call) {
return BasicResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo);
return BasicResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
}
@NotNull