introduced common supertype for contexts (ResolutionContext)
This commit is contained in:
+17
-1
@@ -23,7 +23,7 @@ import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class BasicResolutionContext extends CallResolutionContext {
|
||||
public class BasicResolutionContext extends CallResolutionContext<BasicResolutionContext> {
|
||||
@NotNull
|
||||
public static BasicResolutionContext create(
|
||||
@NotNull BindingTrace trace,
|
||||
@@ -44,4 +44,20 @@ public class BasicResolutionContext extends CallResolutionContext {
|
||||
public BasicResolutionContext replaceTrace(@NotNull BindingTrace trace) {
|
||||
return create(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BasicResolutionContext replace(
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
) {
|
||||
return create(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BasicResolutionContext self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
+36
-20
@@ -20,31 +20,31 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionTask;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public final class CallCandidateResolutionContext<D extends CallableDescriptor, F extends D> extends CallResolutionContext {
|
||||
/*package*/ final ResolvedCallImpl<D> candidateCall;
|
||||
/*package*/ final TracingStrategy tracing;
|
||||
/*package*/ ReceiverValue receiverForVariableAsFunctionSecondCall = ReceiverValue.NO_RECEIVER;
|
||||
public final class CallCandidateResolutionContext<D extends CallableDescriptor, F extends D> extends CallResolutionContext<CallCandidateResolutionContext<D, F>> {
|
||||
public final ResolvedCallImpl<D> candidateCall;
|
||||
public final TracingStrategy tracing;
|
||||
public ReceiverValue receiverForVariableAsFunctionSecondCall = ReceiverValue.NO_RECEIVER;
|
||||
|
||||
private CallCandidateResolutionContext(
|
||||
@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace,
|
||||
@NotNull TracingStrategy tracing, @NotNull Call call, boolean namespacesAllowed
|
||||
@NotNull ResolvedCallImpl<D> candidateCall,
|
||||
@NotNull TracingStrategy tracing,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull Call call,
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
boolean namespacesAllowed
|
||||
) {
|
||||
super(trace, task.scope, call, task.expectedType, task.dataFlowInfo, namespacesAllowed);
|
||||
this.candidateCall = candidateCall;
|
||||
this.tracing = tracing;
|
||||
this.candidateCall.setInitialDataFlowInfo(dataFlowInfo);
|
||||
}
|
||||
|
||||
private CallCandidateResolutionContext(
|
||||
@NotNull BasicResolutionContext context, @NotNull TracingStrategy tracing,
|
||||
@NotNull ResolvedCallImpl<D> candidateCall
|
||||
) {
|
||||
super(context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo, context.namespacesAllowed);
|
||||
super(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
|
||||
this.candidateCall = candidateCall;
|
||||
this.tracing = tracing;
|
||||
this.candidateCall.setInitialDataFlowInfo(dataFlowInfo);
|
||||
@@ -53,7 +53,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor,
|
||||
public static <D extends CallableDescriptor, F extends D> CallCandidateResolutionContext<D, F> create(
|
||||
@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace,
|
||||
@NotNull TracingStrategy tracing, @NotNull Call call) {
|
||||
return new CallCandidateResolutionContext<D, F>(candidateCall, task, trace, tracing, call, task.namespacesAllowed);
|
||||
return new CallCandidateResolutionContext<D, F>(candidateCall, tracing, trace, task.scope, call, task.expectedType, task.dataFlowInfo, task.namespacesAllowed);
|
||||
}
|
||||
|
||||
public static <D extends CallableDescriptor, F extends D> CallCandidateResolutionContext<D, F> create(
|
||||
@@ -63,8 +63,24 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor,
|
||||
}
|
||||
|
||||
public static <D extends CallableDescriptor> CallCandidateResolutionContext<D, D> create(
|
||||
@NotNull BasicResolutionContext context, @NotNull TracingStrategy tracing,
|
||||
@NotNull CallResolutionContext context, @NotNull TracingStrategy tracing,
|
||||
@NotNull ResolvedCallImpl<D> candidateCall) {
|
||||
return new CallCandidateResolutionContext<D, D>(context, tracing, candidateCall);
|
||||
return new CallCandidateResolutionContext<D, D>(candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo, context.namespacesAllowed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CallCandidateResolutionContext<D, F> replace(
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
) {
|
||||
return new CallCandidateResolutionContext<D, F>(candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CallCandidateResolutionContext<D, F> self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-13
@@ -36,7 +36,6 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.expressions.DataFlowUtils;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -59,7 +58,7 @@ public class CallExpressionResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetType lookupNamespaceOrClassObject(@NotNull JetSimpleNameExpression expression, @NotNull ExpressionTypingContext context) {
|
||||
private JetType lookupNamespaceOrClassObject(@NotNull JetSimpleNameExpression expression, @NotNull ResolutionContext context) {
|
||||
Name referencedName = expression.getReferencedNameAsName();
|
||||
ClassifierDescriptor classifier = context.scope.getClassifier(referencedName);
|
||||
if (classifier != null) {
|
||||
@@ -107,7 +106,7 @@ public class CallExpressionResolver {
|
||||
private boolean furtherNameLookup(
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull JetType[] result,
|
||||
@NotNull ExpressionTypingContext context
|
||||
@NotNull ResolutionContext context
|
||||
) {
|
||||
NamespaceType namespaceType = lookupNamespaceType(expression, context);
|
||||
if (namespaceType == null) {
|
||||
@@ -123,7 +122,7 @@ public class CallExpressionResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private NamespaceType lookupNamespaceType(@NotNull JetSimpleNameExpression expression, @NotNull ExpressionTypingContext context) {
|
||||
private NamespaceType lookupNamespaceType(@NotNull JetSimpleNameExpression expression, @NotNull ResolutionContext context) {
|
||||
Name name = expression.getReferencedNameAsName();
|
||||
NamespaceDescriptor namespace = context.scope.getNamespace(name);
|
||||
if (namespace == null) {
|
||||
@@ -146,10 +145,11 @@ public class CallExpressionResolver {
|
||||
@Nullable
|
||||
private ResolvedCall<FunctionDescriptor> getResolvedCallForFunction(
|
||||
@NotNull Call call, @NotNull JetExpression callExpression, @NotNull ReceiverValue receiver,
|
||||
@NotNull ExpressionTypingContext context, @NotNull boolean[] result
|
||||
@NotNull ResolutionContext context, @NotNull boolean[] result
|
||||
) {
|
||||
|
||||
OverloadResolutionResults<FunctionDescriptor> results = context.resolveFunctionCall(call);
|
||||
CallResolver callResolver = expressionTypingServices.getCallResolver();
|
||||
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveFunctionCall(context.toCallResolutionContext(call));
|
||||
if (!results.isNothing()) {
|
||||
checkSuper(receiver, results, context.trace, callExpression);
|
||||
result[0] = true;
|
||||
@@ -164,11 +164,13 @@ public class CallExpressionResolver {
|
||||
|
||||
@Nullable
|
||||
private JetType getVariableType(@NotNull JetSimpleNameExpression nameExpression, @NotNull ReceiverValue receiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull ExpressionTypingContext context, @NotNull boolean[] result) {
|
||||
@Nullable ASTNode callOperationNode, @NotNull ResolutionContext context, @NotNull boolean[] result) {
|
||||
|
||||
TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(
|
||||
context.trace, "trace to resolve as local variable or property", nameExpression);
|
||||
OverloadResolutionResults<VariableDescriptor> resolutionResult = context.replaceBindingTrace(traceForVariable).resolveSimpleProperty(receiver, callOperationNode, nameExpression);
|
||||
CallResolver callResolver = expressionTypingServices.getCallResolver();
|
||||
Call call = CallMaker.makePropertyCall(receiver, callOperationNode, nameExpression);
|
||||
OverloadResolutionResults<VariableDescriptor> resolutionResult = callResolver.resolveSimpleProperty(context.replaceBindingTrace(traceForVariable).toCallResolutionContext(call));
|
||||
if (!resolutionResult.isNothing()) {
|
||||
traceForVariable.commit();
|
||||
checkSuper(receiver, resolutionResult, context.trace, nameExpression);
|
||||
@@ -176,7 +178,7 @@ public class CallExpressionResolver {
|
||||
return resolutionResult.isSingleResult() ? resolutionResult.getResultingDescriptor().getReturnType() : null;
|
||||
}
|
||||
|
||||
ExpressionTypingContext newContext = receiver.exists()
|
||||
ResolutionContext newContext = receiver.exists()
|
||||
? context.replaceScope(receiver.getType().getMemberScope())
|
||||
: context;
|
||||
TemporaryBindingTrace traceForNamespaceOrClassObject = TemporaryBindingTrace.create(
|
||||
@@ -199,7 +201,7 @@ public class CallExpressionResolver {
|
||||
|
||||
@NotNull
|
||||
public JetTypeInfo getSimpleNameExpressionTypeInfo(@NotNull JetSimpleNameExpression nameExpression, @NotNull ReceiverValue receiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull ExpressionTypingContext context) {
|
||||
@Nullable ASTNode callOperationNode, @NotNull ResolutionContext context) {
|
||||
|
||||
boolean[] result = new boolean[1];
|
||||
|
||||
@@ -228,7 +230,7 @@ public class CallExpressionResolver {
|
||||
|
||||
@NotNull
|
||||
public JetTypeInfo getCallExpressionTypeInfo(@NotNull JetCallExpression callExpression, @NotNull ReceiverValue receiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull ExpressionTypingContext context) {
|
||||
@Nullable ASTNode callOperationNode, @NotNull ResolutionContext context) {
|
||||
|
||||
boolean[] result = new boolean[1];
|
||||
Call call = CallMaker.makeCall(receiver, callOperationNode, callExpression);
|
||||
@@ -288,7 +290,7 @@ public class CallExpressionResolver {
|
||||
@NotNull ReceiverValue receiver,
|
||||
@Nullable ASTNode callOperationNode,
|
||||
@NotNull JetExpression selectorExpression,
|
||||
@NotNull ExpressionTypingContext context
|
||||
@NotNull ResolutionContext context
|
||||
) {
|
||||
if (selectorExpression instanceof JetCallExpression) {
|
||||
return getCallExpressionTypeInfo((JetCallExpression) selectorExpression, receiver, callOperationNode, context);
|
||||
@@ -314,7 +316,7 @@ public class CallExpressionResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetTypeInfo getQualifiedExpressionTypeInfo(@NotNull JetQualifiedExpression expression, @NotNull ExpressionTypingContext context) {
|
||||
public JetTypeInfo getQualifiedExpressionTypeInfo(@NotNull JetQualifiedExpression expression, @NotNull ResolutionContext context) {
|
||||
// TODO : functions as values
|
||||
JetExpression selectorExpression = expression.getSelectorExpression();
|
||||
JetExpression receiverExpression = expression.getReceiverExpression();
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public abstract class CallResolutionContext extends ResolutionContext {
|
||||
public abstract class CallResolutionContext<Context extends CallResolutionContext> extends ResolutionContext<Context> {
|
||||
public final Call call;
|
||||
|
||||
protected CallResolutionContext(
|
||||
|
||||
@@ -390,7 +390,7 @@ public class CallResolver {
|
||||
OverloadResolutionResultsImpl<F> resultsForFirstNonemptyCandidateSet = null;
|
||||
for (ResolutionTask<D, F> task : prioritizedTasks) {
|
||||
TemporaryBindingTrace taskTrace = TemporaryBindingTrace.create(context.trace, "trace to resolve a task for", task.reference);
|
||||
OverloadResolutionResultsImpl<F> results = performResolutionGuardedForExtraFunctionLiteralArguments(task.withTrace(taskTrace),
|
||||
OverloadResolutionResultsImpl<F> results = performResolutionGuardedForExtraFunctionLiteralArguments(task.replaceBindingTrace(taskTrace),
|
||||
callTransformer, context.trace);
|
||||
if (results.isSuccess() || results.isAmbiguity()) {
|
||||
taskTrace.commit();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright 2010-2013 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 not use self() file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
@@ -16,16 +16,21 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
|
||||
public class ResolutionContext {
|
||||
public abstract class ResolutionContext<Context extends ResolutionContext> {
|
||||
public final BindingTrace trace;
|
||||
public final JetScope scope;
|
||||
public final JetType expectedType;
|
||||
public final DataFlowInfo dataFlowInfo;
|
||||
// true for positions on the lhs of a '.', i.e. allows namespace results and 'super'
|
||||
public final boolean namespacesAllowed;
|
||||
|
||||
protected ResolutionContext(
|
||||
@@ -41,4 +46,49 @@ public class ResolutionContext {
|
||||
this.dataFlowInfo = dataFlowInfo;
|
||||
this.namespacesAllowed = namespacesAllowed;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Context replace(
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
);
|
||||
|
||||
protected abstract Context self();
|
||||
|
||||
public Context replaceBindingTrace(@NotNull BindingTrace trace) {
|
||||
if (this.trace == trace) return self();
|
||||
return replace(trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceNamespacesAllowed(boolean namespacesAllowed) {
|
||||
if (namespacesAllowed == this.namespacesAllowed) return self();
|
||||
return replace(trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) {
|
||||
if (newDataFlowInfo == dataFlowInfo) return self();
|
||||
return replace(trace, scope, newDataFlowInfo, expectedType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceExpectedType(@Nullable JetType newExpectedType) {
|
||||
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
||||
if (expectedType == newExpectedType) return self();
|
||||
return replace(trace, scope, dataFlowInfo, newExpectedType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceScope(@NotNull JetScope newScope) {
|
||||
if (newScope == scope) return self();
|
||||
return replace(trace, newScope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BasicResolutionContext toCallResolutionContext(@NotNull Call call) {
|
||||
return BasicResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -52,7 +52,7 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
/**
|
||||
* Stores candidates for call resolution.
|
||||
*/
|
||||
public class ResolutionTask<D extends CallableDescriptor, F extends D> extends CallResolutionContext {
|
||||
public class ResolutionTask<D extends CallableDescriptor, F extends D> extends CallResolutionContext<ResolutionTask<D, F>> {
|
||||
private final Collection<ResolutionCandidate<D>> candidates;
|
||||
private final Set<ResolvedCallWithTrace<F>> resolvedCalls = Sets.newLinkedHashSet();
|
||||
public final JetReferenceExpression reference;
|
||||
@@ -97,6 +97,24 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
|
||||
return newTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResolutionTask<D, F> replace(
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
) {
|
||||
ResolutionTask<D, F> newTask = new ResolutionTask<D, F>(candidates, reference, trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed);
|
||||
newTask.setCheckingStrategy(checkingStrategy);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResolutionTask<D, F> self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public interface DescriptorCheckStrategy {
|
||||
<D extends CallableDescriptor> boolean performAdvancedChecks(D descriptor, BindingTrace trace, TracingStrategy tracing);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
|
||||
@@ -129,12 +130,12 @@ public class DataFlowUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetTypeInfo checkType(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context, @NotNull DataFlowInfo dataFlowInfo) {
|
||||
public static JetTypeInfo checkType(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ResolutionContext context, @NotNull DataFlowInfo dataFlowInfo) {
|
||||
return JetTypeInfo.create(checkType(expressionType, expression, context), dataFlowInfo);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetType checkType(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context) {
|
||||
public static JetType checkType(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ResolutionContext context) {
|
||||
if (expressionType == null || context.expectedType == null || context.expectedType == TypeUtils.NO_EXPECTED_TYPE ||
|
||||
JetTypeChecker.INSTANCE.isSubtypeOf(expressionType, context.expectedType)) {
|
||||
return expressionType;
|
||||
@@ -157,12 +158,12 @@ public class DataFlowUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetTypeInfo checkStatementType(@NotNull JetExpression expression, @NotNull ExpressionTypingContext context, @NotNull DataFlowInfo dataFlowInfo) {
|
||||
public static JetTypeInfo checkStatementType(@NotNull JetExpression expression, @NotNull ResolutionContext context, @NotNull DataFlowInfo dataFlowInfo) {
|
||||
return JetTypeInfo.create(checkStatementType(expression, context), dataFlowInfo);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetType checkStatementType(@NotNull JetExpression expression, @NotNull ExpressionTypingContext context) {
|
||||
public static JetType checkStatementType(@NotNull JetExpression expression, @NotNull ResolutionContext context) {
|
||||
if (context.expectedType != TypeUtils.NO_EXPECTED_TYPE && !KotlinBuiltIns.getInstance().isUnit(context.expectedType) && !ErrorUtils.isErrorType(context.expectedType)) {
|
||||
context.trace.report(EXPECTED_TYPE_MISMATCH.on(expression, context.expectedType));
|
||||
return null;
|
||||
|
||||
+15
-46
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.BasicResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
@@ -40,7 +41,7 @@ import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ExpressionTypingContext {
|
||||
public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingContext> {
|
||||
|
||||
@NotNull
|
||||
public static ExpressionTypingContext newContext(
|
||||
@@ -67,17 +68,9 @@ public class ExpressionTypingContext {
|
||||
}
|
||||
|
||||
public final ExpressionTypingServices expressionTypingServices;
|
||||
public final BindingTrace trace;
|
||||
public final JetScope scope;
|
||||
|
||||
public final DataFlowInfo dataFlowInfo;
|
||||
public final JetType expectedType;
|
||||
|
||||
public final LabelResolver labelResolver;
|
||||
|
||||
// true for positions on the lhs of a '.', i.e. allows namespace results and 'super'
|
||||
public final boolean namespacesAllowed;
|
||||
|
||||
private CompileTimeConstantResolver compileTimeConstantResolver;
|
||||
|
||||
private ExpressionTypingContext(
|
||||
@@ -88,49 +81,25 @@ public class ExpressionTypingContext {
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed) {
|
||||
super(trace, scope, expectedType, dataFlowInfo, namespacesAllowed);
|
||||
this.expressionTypingServices = expressionTypingServices;
|
||||
this.trace = trace;
|
||||
this.labelResolver = labelResolver;
|
||||
this.scope = scope;
|
||||
this.dataFlowInfo = dataFlowInfo;
|
||||
this.expectedType = expectedType;
|
||||
this.namespacesAllowed = namespacesAllowed;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ExpressionTypingContext replaceNamespacesAllowed(boolean namespacesAllowed) {
|
||||
if (namespacesAllowed == this.namespacesAllowed) return this;
|
||||
return newContext(expressionTypingServices, labelResolver,
|
||||
trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
@Override
|
||||
protected ExpressionTypingContext replace(
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
) {
|
||||
return new ExpressionTypingContext(expressionTypingServices, labelResolver, trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ExpressionTypingContext replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) {
|
||||
if (newDataFlowInfo == dataFlowInfo) return this;
|
||||
return newContext(expressionTypingServices, labelResolver,
|
||||
trace, scope, newDataFlowInfo, expectedType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ExpressionTypingContext replaceExpectedType(@Nullable JetType newExpectedType) {
|
||||
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
||||
if (expectedType == newExpectedType) return this;
|
||||
return newContext(expressionTypingServices, labelResolver,
|
||||
trace, scope, dataFlowInfo, newExpectedType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ExpressionTypingContext replaceBindingTrace(@NotNull BindingTrace newTrace) {
|
||||
if (newTrace == trace) return this;
|
||||
return newContext(expressionTypingServices, labelResolver,
|
||||
newTrace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ExpressionTypingContext replaceScope(@NotNull JetScope newScope) {
|
||||
if (newScope == scope) return this;
|
||||
return newContext(expressionTypingServices, labelResolver,
|
||||
trace, newScope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
@Override
|
||||
protected ExpressionTypingContext self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
///////////// LAZY ACCESSORS
|
||||
|
||||
Reference in New Issue
Block a user