From 8c1ef5996306ef34531bc1a643c39de332f6e7de Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 26 Jan 2015 17:11:50 +0300 Subject: [PATCH] Minor refactoring: removed unnecessary parameter, inlined method --- .../expressions/ControlStructureTypingVisitor.java | 12 +++++++----- .../types/expressions/ExpressionTypingServices.java | 13 +++---------- .../expressions/PatternMatchingTypingVisitor.java | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index cd5e1b4af0b..3f9c4a101b6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -164,7 +164,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ExpressionTypingContext newContext = context.replaceDataFlowInfo(presentInfo).replaceExpectedType(NO_EXPECTED_TYPE) .replaceContextDependency(INDEPENDENT); JetTypeInfo typeInfo = components.expressionTypingServices.getBlockReturnedTypeWithWritableScope( - presentScope, Collections.singletonList(presentBranch), CoercionStrategy.NO_COERCION, newContext, context.trace); + presentScope, Collections.singletonList(presentBranch), CoercionStrategy.NO_COERCION, newContext); JetType type = typeInfo.getType(); DataFlowInfo dataFlowInfo; if (type != null && KotlinBuiltIns.isNothing(type)) { @@ -195,7 +195,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { DataFlowInfo conditionInfo = DataFlowUtils.extractDataFlowInfoFromCondition(condition, true, context).and(dataFlowInfo); components.expressionTypingServices.getBlockReturnedTypeWithWritableScope( scopeToExtend, Collections.singletonList(body), - CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo), context.trace); + CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo)); } if (!containsJumpOutOfLoop(expression, context)) { @@ -260,7 +260,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { if (!functionLiteral.hasParameterSpecification()) { WritableScope writableScope = newWritableScopeImpl(context, "do..while body scope"); conditionScope = writableScope; - components.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, functionLiteral.getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context, context.trace); + components.expressionTypingServices.getBlockReturnedTypeWithWritableScope( + writableScope, functionLiteral.getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context); context.trace.record(BindingContext.BLOCK, function); } else { @@ -277,7 +278,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { else { block = Collections.singletonList(body); } - components.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context, context.trace); + components.expressionTypingServices.getBlockReturnedTypeWithWritableScope( + writableScope, block, CoercionStrategy.NO_COERCION, context); } JetExpression condition = expression.getCondition(); DataFlowInfo conditionDataFlowInfo = checkCondition(conditionScope, condition, context); @@ -333,7 +335,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { JetExpression body = expression.getBody(); if (body != null) { components.expressionTypingServices.getBlockReturnedTypeWithWritableScope(loopScope, Collections.singletonList(body), - CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(dataFlowInfo), context.trace); + CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(dataFlowInfo)); } return DataFlowUtils.checkType(components.builtIns.getUnitType(), expression, contextWithExpectedType, dataFlowInfo); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java index 567f985a9cb..7cbcea82401 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java @@ -235,7 +235,7 @@ public class ExpressionTypingServices { r = DataFlowUtils.checkType(builtIns.getUnitType(), expression, context, context.dataFlowInfo); } else { - r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, context.trace); + r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context); } scope.changeLockLevel(WritableScope.LockLevel.READING); @@ -276,15 +276,14 @@ public class ExpressionTypingServices { @NotNull WritableScope scope, @NotNull List block, @NotNull CoercionStrategy coercionStrategyForLastExpression, - @NotNull ExpressionTypingContext context, - @NotNull BindingTrace trace + @NotNull ExpressionTypingContext context ) { if (block.isEmpty()) { return JetTypeInfo.create(builtIns.getUnitType(), context.dataFlowInfo); } ExpressionTypingInternals blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(expressionTypingComponents, scope); - ExpressionTypingContext newContext = createContext(context, trace, scope, context.dataFlowInfo, NO_EXPECTED_TYPE); + ExpressionTypingContext newContext = context.replaceScope(scope).replaceExpectedType(NO_EXPECTED_TYPE); JetTypeInfo result = JetTypeInfo.create(null, context.dataFlowInfo); for (Iterator iterator = block.iterator(); iterator.hasNext(); ) { @@ -352,12 +351,6 @@ public class ExpressionTypingServices { return result; } - private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType) { - return ExpressionTypingContext.newContext( - trace, scope, dataFlowInfo, expectedType, oldContext.contextDependency, oldContext.resolutionResultsCache, - oldContext.callChecker, oldContext.isAnnotationContext); - } - @Nullable public JetExpression deparenthesizeWithTypeResolution( @Nullable JetExpression expression, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java index a6de3ed2a91..be07d741e90 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java @@ -107,7 +107,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { .replaceScope(scopeToExtend).replaceDataFlowInfo(infosForCondition.thenInfo).replaceContextDependency(INDEPENDENT); CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION; JetTypeInfo typeInfo = components.expressionTypingServices.getBlockReturnedTypeWithWritableScope( - scopeToExtend, Collections.singletonList(bodyExpression), coercionStrategy, newContext, context.trace); + scopeToExtend, Collections.singletonList(bodyExpression), coercionStrategy, newContext); JetType type = typeInfo.getType(); if (type != null) { expressionTypes.add(type);