diff --git a/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java index c01ff5d4c..d648c249a 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java @@ -4,10 +4,11 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -public class ExtendsType extends Type { +public final class ExtendsType extends Type { private Type extendedType; public ExtendsType(Type extendedType) { + super("? extends " + extendedType.getTypeParams(), extendedType.getTypeParams()); this.extendedType = extendedType; } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java index 48cf2e6f2..dd40ab23b 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java @@ -4,10 +4,10 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -public class PlaceholderType extends Type{ +public final class PlaceholderType extends Type{ public PlaceholderType(String name) { - typeName = name; + super(name); } @Override diff --git a/src/de/dhbwstuttgart/typinference/unify/model/SimpleType.java b/src/de/dhbwstuttgart/typinference/unify/model/SimpleType.java index 199c6518e..292289779 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/SimpleType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/SimpleType.java @@ -4,10 +4,9 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -public class SimpleType extends Type { +public final class SimpleType extends Type { public SimpleType(String name, Type... typeParams) { - this.typeName = name; - this.typeParams = new TypeParams(typeParams); + super(name, new TypeParams(typeParams)); } @Override diff --git a/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java index 5a734621e..2148e0dfa 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java @@ -4,11 +4,12 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -public class SuperType extends Type { +public final class SuperType extends Type { private Type superedType; public SuperType(Type superedType) { + super("? extends " + superedType.getName(), superedType.getTypeParams()); this.superedType = superedType; } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/Type.java b/src/de/dhbwstuttgart/typinference/unify/model/Type.java index dc5a9d915..3da9dbcd0 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/Type.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/Type.java @@ -1,17 +1,22 @@ package de.dhbwstuttgart.typinference.unify.model; -import java.util.Arrays; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; public abstract class Type { - protected String typeName = ""; - protected TypeParams typeParams; + protected final String typeName; + protected final TypeParams typeParams; - public Type() { - typeParams = new TypeParams(); + protected Type(String name, Type... typeParams) { + typeName = name; + this.typeParams = new TypeParams(typeParams); + } + + protected Type(String name, TypeParams p) { + typeName = name; + typeParams = p; } public String getName() { diff --git a/src/de/dhbwstuttgart/typinference/unify/model/TypeParams.java b/src/de/dhbwstuttgart/typinference/unify/model/TypeParams.java index c89b207d4..c6e3ee005 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/TypeParams.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/TypeParams.java @@ -3,8 +3,10 @@ package de.dhbwstuttgart.typinference.unify.model; import java.util.Arrays; import java.util.Iterator; -public class TypeParams implements Iterable{ - private Type[] typeParams; +import de.dhbwstuttgart.typeinference.unifynew.Unifier; + +public final class TypeParams implements Iterable{ + private final Type[] typeParams; public TypeParams(Type... types) { typeParams = types; @@ -26,8 +28,20 @@ public class TypeParams implements Iterable{ return typeParams.length == 0; } - public Type[] asArray() { - return typeParams; + public void apply(Unifier u) { + for(int i = 0; i < typeParams.length; i++) + typeParams[i] = u.apply(typeParams[i]); + } + + public boolean contains(Type t) { + for(Type t1 : typeParams) + if(t1.equals(t1)) + return true; + return false; + } + + public Type get(int i) { + return typeParams[i]; } @Override