From 685bea6446bdd6a1abe87ae2655e0e92880ed0cb Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 3 Sep 2013 15:59:43 +0400 Subject: [PATCH] Extract method --- .../jetbrains/jet/lang/types/TypeUtils.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java index 12a2a8145f1..f2a4057d31a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -23,6 +23,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.intellij.openapi.util.Pair; import com.intellij.util.Processor; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; @@ -456,21 +457,31 @@ public class TypeUtils { } @NotNull - public static JetType substituteParameters(@NotNull ClassDescriptor clazz, @NotNull List actualTypeParameters) { - List clazzTypeParameters = clazz.getTypeConstructor().getParameters(); + public static JetType substituteParameters(@NotNull ClassDescriptor clazz, @NotNull List typeArguments) { + List projections = ContainerUtil.map(typeArguments, new com.intellij.util.Function() { + @Override + public TypeProjection fun(JetType type) { + return new TypeProjection(type); + } + }); - if (clazzTypeParameters.size() != actualTypeParameters.size()) { - throw new IllegalArgumentException("type parameter counts do not match: " + clazz + ", " + actualTypeParameters); + return substituteProjectionsForParameters(clazz, projections); + } + + @NotNull + public static JetType substituteProjectionsForParameters(@NotNull ClassDescriptor clazz, @NotNull List projections) { + List clazzTypeParameters = clazz.getTypeConstructor().getParameters(); + if (clazzTypeParameters.size() != projections.size()) { + throw new IllegalArgumentException("type parameter counts do not match: " + clazz + ", " + projections); } - + Map substitutions = Maps.newHashMap(); - + for (int i = 0; i < clazzTypeParameters.size(); ++i) { TypeConstructor typeConstructor = clazzTypeParameters.get(i).getTypeConstructor(); - TypeProjection typeProjection = new TypeProjection(actualTypeParameters.get(i)); - substitutions.put(typeConstructor, typeProjection); + substitutions.put(typeConstructor, projections.get(i)); } - + return TypeSubstitutor.create(substitutions).substitute(clazz.getDefaultType(), Variance.INVARIANT); }