From 5dc8cf48bc395ee4658bb1008c05e148dd45f5f4 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 4 May 2012 11:56:22 +0400 Subject: [PATCH] TypeSubstitution moved to top level --- .../descriptors/FunctionDescriptorUtil.java | 2 +- .../jet/lang/resolve/DescriptorUtils.java | 2 +- .../ConstraintSystemWithPriorities.java | 4 +- .../lang/types/CompositeTypeSubstitution.java | 12 ++--- .../jet/lang/types/DescriptorSubstitutor.java | 2 +- .../jet/lang/types/TypeSubstitution.java | 45 +++++++++++++++++++ .../jet/lang/types/TypeSubstitutor.java | 25 +---------- 7 files changed, 57 insertions(+), 35 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitution.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java index e1cd4083a61..101c4a14e06 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java @@ -33,7 +33,7 @@ import java.util.*; * @author abreslav */ public class FunctionDescriptorUtil { - private static final TypeSubstitutor MAKE_TYPE_PARAMETERS_FRESH = TypeSubstitutor.create(new TypeSubstitutor.TypeSubstitution() { + private static final TypeSubstitutor MAKE_TYPE_PARAMETERS_FRESH = TypeSubstitutor.create(new TypeSubstitution() { @Override public TypeProjection get(TypeConstructor key) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java index 5ce30d66e3f..7a4386e4d3a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -71,7 +71,7 @@ public class DescriptorUtils { typeConstructors.put(typeParameter.getTypeConstructor(), typeParameter); } //noinspection unchecked - return (Descriptor) functionDescriptor.substitute(new TypeSubstitutor(TypeSubstitutor.TypeSubstitution.EMPTY) { + return (Descriptor) functionDescriptor.substitute(new TypeSubstitutor(TypeSubstitution.EMPTY) { @Override public boolean inRange(@NotNull TypeConstructor typeConstructor) { return typeConstructors.containsKey(typeConstructor); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemWithPriorities.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemWithPriorities.java index f61be7f2a29..d9104ad76b7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemWithPriorities.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemWithPriorities.java @@ -49,7 +49,7 @@ public class ConstraintSystemWithPriorities implements ConstraintSystem { } final TypeProjection projection = new TypeProjection(type); - return TypeSubstitutor.create(new TypeSubstitutor.TypeSubstitution() { + return TypeSubstitutor.create(new TypeSubstitution() { @Override public TypeProjection get(TypeConstructor key) { if (constructors.contains(key)) { @@ -484,7 +484,7 @@ public class ConstraintSystemWithPriorities implements ConstraintSystem { } public class Solution implements ConstraintSystemSolution { - private final TypeSubstitutor typeSubstitutor = TypeSubstitutor.create(new TypeSubstitutor.TypeSubstitution() { + private final TypeSubstitutor typeSubstitutor = TypeSubstitutor.create(new TypeSubstitution() { @Override public TypeProjection get(TypeConstructor key) { DeclarationDescriptor declarationDescriptor = key.getDeclarationDescriptor(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/CompositeTypeSubstitution.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/CompositeTypeSubstitution.java index 32b2cfd5b52..5d03af142fc 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/CompositeTypeSubstitution.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/CompositeTypeSubstitution.java @@ -21,16 +21,16 @@ import org.jetbrains.annotations.NotNull; /** * @author abreslav */ -public class CompositeTypeSubstitution implements TypeSubstitutor.TypeSubstitution { - private final TypeSubstitutor.TypeSubstitution[] inner; +public class CompositeTypeSubstitution implements TypeSubstitution { + private final TypeSubstitution[] inner; - public CompositeTypeSubstitution(@NotNull TypeSubstitutor.TypeSubstitution... inner) { + public CompositeTypeSubstitution(@NotNull TypeSubstitution... inner) { this.inner = inner; } @Override public TypeProjection get(TypeConstructor key) { - for (TypeSubstitutor.TypeSubstitution substitution : inner) { + for (TypeSubstitution substitution : inner) { TypeProjection value = substitution.get(key); if (value != null) return value; } @@ -39,7 +39,7 @@ public class CompositeTypeSubstitution implements TypeSubstitutor.TypeSubstituti @Override public boolean isEmpty() { - for (TypeSubstitutor.TypeSubstitution substitution : inner) { + for (TypeSubstitution substitution : inner) { if (!substitution.isEmpty()) return false; } return true; @@ -48,7 +48,7 @@ public class CompositeTypeSubstitution implements TypeSubstitutor.TypeSubstituti @Override public String toString() { StringBuilder builder = new StringBuilder(); - for (TypeSubstitutor.TypeSubstitution substitution : inner) { + for (TypeSubstitution substitution : inner) { builder.append(substitution).append(" * "); } return builder.toString(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java index 305739640a2..eada1237fb8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java @@ -36,7 +36,7 @@ public class DescriptorSubstitutor { @NotNull DeclarationDescriptor newContainingDeclaration, @NotNull List result) { final Map mutableSubstitution = Maps.newHashMap(); - TypeSubstitutor substitutor = TypeSubstitutor.create(new TypeSubstitutor.TypeSubstitution() { + TypeSubstitutor substitutor = TypeSubstitutor.create(new TypeSubstitution() { @Override public TypeProjection get(TypeConstructor key) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitution.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitution.java new file mode 100644 index 00000000000..8986c0842f4 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitution.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2012 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 obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.types; + +import org.jetbrains.annotations.Nullable; + +/** +* @author abreslav +*/ +public interface TypeSubstitution { + TypeSubstitution EMPTY = new TypeSubstitution() { + @Override + public TypeProjection get(TypeConstructor key) { + return null; + } + + @Override + public boolean isEmpty() { + return true; + } + + @Override + public String toString() { + return "Empty TypeSubstitution"; + } + }; + + @Nullable + TypeProjection get(TypeConstructor key); + boolean isEmpty(); +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java index 901b2d240fe..f6a4aca71e8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java @@ -39,7 +39,7 @@ public class TypeSubstitutor { } final TypeProjection projection = new TypeProjection(type); - return TypeSubstitutor.create(new TypeSubstitutor.TypeSubstitution() { + return TypeSubstitutor.create(new TypeSubstitution() { @Override public TypeProjection get(TypeConstructor key) { if (constructors.contains(key)) { @@ -60,29 +60,6 @@ public class TypeSubstitutor { }); } - public interface TypeSubstitution { - TypeSubstitution EMPTY = new TypeSubstitution() { - @Override - public TypeProjection get(TypeConstructor key) { - return null; - } - - @Override - public boolean isEmpty() { - return true; - } - - @Override - public String toString() { - return "Empty TypeSubstitution"; - } - }; - - @Nullable - TypeProjection get(TypeConstructor key); - boolean isEmpty(); - } - public static class MapToTypeSubstitutionAdapter implements TypeSubstitution { private final @NotNull Map substitutionContext;