From dcd358bf3af5cd81da00137e9c5fc09d93395243 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 28 Jan 2013 17:13:37 +0400 Subject: [PATCH] introduced common supertype for contexts (ResolutionContext) --- .../resolve/calls/BasicResolutionContext.java | 18 +++++- .../calls/CallCandidateResolutionContext.java | 56 +++++++++++------ .../resolve/calls/CallExpressionResolver.java | 28 +++++---- .../resolve/calls/CallResolutionContext.java | 2 +- .../jet/lang/resolve/calls/CallResolver.java | 2 +- .../lang/resolve/calls/ResolutionContext.java | 56 ++++++++++++++++- .../resolve/calls/tasks/ResolutionTask.java | 20 +++++- .../lang/types/expressions/DataFlowUtils.java | 9 +-- .../expressions/ExpressionTypingContext.java | 61 +++++-------------- 9 files changed, 162 insertions(+), 90 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/BasicResolutionContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/BasicResolutionContext.java index 4be01f545f8..f9e21e2527c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/BasicResolutionContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/BasicResolutionContext.java @@ -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 { @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; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCandidateResolutionContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCandidateResolutionContext.java index bf41ab9710b..6b7e73ae1b6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCandidateResolutionContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCandidateResolutionContext.java @@ -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 extends CallResolutionContext { - /*package*/ final ResolvedCallImpl candidateCall; - /*package*/ final TracingStrategy tracing; - /*package*/ ReceiverValue receiverForVariableAsFunctionSecondCall = ReceiverValue.NO_RECEIVER; +public final class CallCandidateResolutionContext extends CallResolutionContext> { + public final ResolvedCallImpl candidateCall; + public final TracingStrategy tracing; + public ReceiverValue receiverForVariableAsFunctionSecondCall = ReceiverValue.NO_RECEIVER; private CallCandidateResolutionContext( - @NotNull ResolvedCallImpl candidateCall, @NotNull ResolutionTask task, @NotNull BindingTrace trace, - @NotNull TracingStrategy tracing, @NotNull Call call, boolean namespacesAllowed + @NotNull ResolvedCallImpl 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 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 CallCandidateResolutionContext create( @NotNull ResolvedCallImpl candidateCall, @NotNull ResolutionTask task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing, @NotNull Call call) { - return new CallCandidateResolutionContext(candidateCall, task, trace, tracing, call, task.namespacesAllowed); + return new CallCandidateResolutionContext(candidateCall, tracing, trace, task.scope, call, task.expectedType, task.dataFlowInfo, task.namespacesAllowed); } public static CallCandidateResolutionContext create( @@ -63,8 +63,24 @@ public final class CallCandidateResolutionContext CallCandidateResolutionContext create( - @NotNull BasicResolutionContext context, @NotNull TracingStrategy tracing, + @NotNull CallResolutionContext context, @NotNull TracingStrategy tracing, @NotNull ResolvedCallImpl candidateCall) { - return new CallCandidateResolutionContext(context, tracing, candidateCall); + return new CallCandidateResolutionContext(candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo, context.namespacesAllowed); + } + + @Override + protected CallCandidateResolutionContext replace( + @NotNull BindingTrace trace, + @NotNull JetScope scope, + @NotNull DataFlowInfo dataFlowInfo, + @NotNull JetType expectedType, + boolean namespacesAllowed + ) { + return new CallCandidateResolutionContext(candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed); + } + + @Override + protected CallCandidateResolutionContext self() { + return this; } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallExpressionResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallExpressionResolver.java index 2dd31fc7732..bcd1ad12522 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallExpressionResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallExpressionResolver.java @@ -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 getResolvedCallForFunction( @NotNull Call call, @NotNull JetExpression callExpression, @NotNull ReceiverValue receiver, - @NotNull ExpressionTypingContext context, @NotNull boolean[] result + @NotNull ResolutionContext context, @NotNull boolean[] result ) { - OverloadResolutionResults results = context.resolveFunctionCall(call); + CallResolver callResolver = expressionTypingServices.getCallResolver(); + OverloadResolutionResults 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 resolutionResult = context.replaceBindingTrace(traceForVariable).resolveSimpleProperty(receiver, callOperationNode, nameExpression); + CallResolver callResolver = expressionTypingServices.getCallResolver(); + Call call = CallMaker.makePropertyCall(receiver, callOperationNode, nameExpression); + OverloadResolutionResults 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(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolutionContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolutionContext.java index 10feb8e5da2..d984d538748 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolutionContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolutionContext.java @@ -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 extends ResolutionContext { public final Call call; protected CallResolutionContext( diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index 58353cd4bb2..6608ab5a219 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -390,7 +390,7 @@ public class CallResolver { OverloadResolutionResultsImpl resultsForFirstNonemptyCandidateSet = null; for (ResolutionTask task : prioritizedTasks) { TemporaryBindingTrace taskTrace = TemporaryBindingTrace.create(context.trace, "trace to resolve a task for", task.reference); - OverloadResolutionResultsImpl results = performResolutionGuardedForExtraFunctionLiteralArguments(task.withTrace(taskTrace), + OverloadResolutionResultsImpl results = performResolutionGuardedForExtraFunctionLiteralArguments(task.replaceBindingTrace(taskTrace), callTransformer, context.trace); if (results.isSuccess() || results.isAmbiguity()) { taskTrace.commit(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolutionContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolutionContext.java index e064aa54ede..6d61f2e2a9b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolutionContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolutionContext.java @@ -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 { 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); + } +} \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/ResolutionTask.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/ResolutionTask.java index 37cc5fd33a8..49f02dc2df2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/ResolutionTask.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/ResolutionTask.java @@ -52,7 +52,7 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*; /** * Stores candidates for call resolution. */ -public class ResolutionTask extends CallResolutionContext { +public class ResolutionTask extends CallResolutionContext> { private final Collection> candidates; private final Set> resolvedCalls = Sets.newLinkedHashSet(); public final JetReferenceExpression reference; @@ -97,6 +97,24 @@ public class ResolutionTask extends C return newTask; } + @Override + protected ResolutionTask replace( + @NotNull BindingTrace trace, + @NotNull JetScope scope, + @NotNull DataFlowInfo dataFlowInfo, + @NotNull JetType expectedType, + boolean namespacesAllowed + ) { + ResolutionTask newTask = new ResolutionTask(candidates, reference, trace, scope, call, expectedType, dataFlowInfo, namespacesAllowed); + newTask.setCheckingStrategy(checkingStrategy); + return newTask; + } + + @Override + protected ResolutionTask self() { + return this; + } + public interface DescriptorCheckStrategy { boolean performAdvancedChecks(D descriptor, BindingTrace trace, TracingStrategy tracing); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java index 3d03d4f9853..e14baa67e86 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java @@ -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; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingContext.java index eeaaf741586..574109a575f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingContext.java @@ -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 { @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