TypeSubstitution moved to top level

This commit is contained in:
Andrey Breslav
2012-05-04 11:56:22 +04:00
parent 3ca8bf6f63
commit 5dc8cf48bc
7 changed files with 57 additions and 35 deletions
@@ -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) {
@@ -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);
@@ -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();
@@ -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();
@@ -36,7 +36,7 @@ public class DescriptorSubstitutor {
@NotNull DeclarationDescriptor newContainingDeclaration,
@NotNull List<TypeParameterDescriptor> result) {
final Map<TypeConstructor, TypeProjection> mutableSubstitution = Maps.newHashMap();
TypeSubstitutor substitutor = TypeSubstitutor.create(new TypeSubstitutor.TypeSubstitution() {
TypeSubstitutor substitutor = TypeSubstitutor.create(new TypeSubstitution() {
@Override
public TypeProjection get(TypeConstructor key) {
@@ -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();
}
@@ -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<TypeConstructor, TypeProjection> substitutionContext;