From 54cd8c82a33d961200550ed0da9c95043db0ae0f Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 6 Mar 2013 15:06:36 +0400 Subject: [PATCH] refactoring unite two similar methods (replaceTypeVariables, copy) --- .../calls/inference/ConstraintSystemImpl.java | 21 ++++++++++--------- .../calls/inference/TypeConstraintsImpl.java | 12 +++-------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java index bbd0c1360f3..f97aec5d012 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.lang.resolve.calls.inference; import com.google.common.base.Function; +import com.google.common.base.Functions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -123,19 +124,19 @@ public class ConstraintSystemImpl implements ConstraintSystem { @Override @NotNull public ConstraintSystem copy() { - ConstraintSystemImpl newConstraintSystem = new ConstraintSystemImpl(); - for (Map.Entry entry : typeParameterConstraints.entrySet()) { - TypeParameterDescriptor typeParameter = entry.getKey(); - TypeConstraintsImpl typeConstraints = entry.getValue(); - newConstraintSystem.typeParameterConstraints.put(typeParameter, typeConstraints.copy()); - } - newConstraintSystem.errorConstraintPositions.addAll(errorConstraintPositions); - newConstraintSystem.hasErrorInConstrainingTypes = hasErrorInConstrainingTypes; - return newConstraintSystem; + return replaceTypeVariables(Functions.identity(), true); } @NotNull public ConstraintSystem replaceTypeVariables(@NotNull Function typeVariablesMap) { + return replaceTypeVariables(typeVariablesMap, false); + } + + @NotNull + private ConstraintSystem replaceTypeVariables( + @NotNull Function typeVariablesMap, + boolean recreateTypeConstraints + ) { ConstraintSystemImpl newConstraintSystem = new ConstraintSystemImpl(); for (Map.Entry entry : typeParameterConstraints.entrySet()) { TypeParameterDescriptor typeParameter = entry.getKey(); @@ -143,7 +144,7 @@ public class ConstraintSystemImpl implements ConstraintSystem { TypeParameterDescriptor newTypeParameter = typeVariablesMap.apply(typeParameter); assert newTypeParameter != null; - newConstraintSystem.typeParameterConstraints.put(newTypeParameter, typeConstraints); + newConstraintSystem.typeParameterConstraints.put(newTypeParameter, recreateTypeConstraints ? typeConstraints.copy() : typeConstraints); } newConstraintSystem.errorConstraintPositions.addAll(errorConstraintPositions); newConstraintSystem.hasErrorInConstrainingTypes = hasErrorInConstrainingTypes; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java index 785de5a6abe..58b5f23bd13 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java @@ -77,15 +77,9 @@ public class TypeConstraintsImpl implements TypeConstraints { /*package*/ TypeConstraintsImpl copy() { TypeConstraintsImpl typeConstraints = new TypeConstraintsImpl(varianceOfPosition); - for (JetType upperBound : upperBounds) { - typeConstraints.upperBounds.add(upperBound); - } - for (JetType lowerBound : lowerBounds) { - typeConstraints.lowerBounds.add(lowerBound); - } - for (JetType exactBound : exactBounds) { - typeConstraints.exactBounds.add(exactBound); - } + typeConstraints.upperBounds.addAll(upperBounds); + typeConstraints.lowerBounds.addAll(lowerBounds); + typeConstraints.exactBounds.addAll(exactBounds); return typeConstraints; }