diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java index 847abfd5..9416d786 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java @@ -14,7 +14,7 @@ public final class ExtendsType extends WildcardType { * @param extendedType The extended type e.g. Integer in "? extends Integer" */ public ExtendsType(UnifyType extendedType) { - super("? extends " + extendedType.getName(), extendedType, extendedType.getTypeParams()); + super("? extends " + extendedType.getName(), extendedType); } public UnifyType getExtendedType() { diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index 879fe87d..ddb7d273 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -16,13 +16,13 @@ public final class PlaceholderType extends UnifyType{ private final boolean IsGenerated; public PlaceholderType(String name) { - super(name); + super(name, new TypeParams()); EXISTING_PLACEHOLDERS.add(name); IsGenerated = false; } protected PlaceholderType(String name, boolean isGenerated) { - super(name); + super(name, new TypeParams()); EXISTING_PLACEHOLDERS.add(name); IsGenerated = isGenerated; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java index 363dbbf6..7c557ade 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java @@ -6,7 +6,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; public final class SuperType extends WildcardType { public SuperType(UnifyType superedType) { - super("? super " + superedType.getName(), superedType, superedType.getTypeParams()); + super("? super " + superedType.getName(), superedType); } public UnifyType getSuperedType() { diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index cccaf591..f5af52d0 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -17,7 +17,7 @@ public class Unifier implements Function /*, Set*/ /** * Identity function as an "unifier". */ - public Unifier() { + protected Unifier() { } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index 341eabd1..4f1965eb 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -4,35 +4,76 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +/** + * Represents a java type. + * @author Florian Steurer + */ public abstract class UnifyType { + /** + * The name of the type e.q. "Integer", "? extends Integer" or "List" for (List) + */ protected final String typeName; + + /** + * The type parameters of the type. + */ protected final TypeParams typeParams; - protected UnifyType(String name, UnifyType... typeParams) { - typeName = name; - this.typeParams = new TypeParams(typeParams); - } - + /** + * Creates a new instance + * @param name Name of the type (e.q. List for List, Integer or ? extends Integer) + * @param typeParams Parameters of the type (e.q. for List) + */ protected UnifyType(String name, TypeParams p) { typeName = name; typeParams = p; } + /** + * Returns the name of the type. + * @return The name e.q. List for List, Integer or ? extends Integer + */ public String getName() { return typeName; } + /** + * The parameters of the type. + * @return Parameters of the type, e.q. for List. + */ public TypeParams getTypeParams() { return typeParams; } + /** + * Returns a new type that equals this type except for the type parameters. + * @param newTp The type params of the new type. + * @return A new type object. + */ public abstract UnifyType setTypeParams(TypeParams newTp); + /** + * Implementation of the visitor-pattern. Returns the set of smArg + * by calling the most specific overload in the FC. + * @param fc The FC that is called. + * @return The set that is smArg(this) + */ abstract Set smArg(IFiniteClosure fc); + /** + * Implementation of the visitor-pattern. Returns the set of grArg + * by calling the most specific overload in the FC. + * @param fc The FC that is called. + * @return The set that is grArg(this) + */ abstract Set grArg(IFiniteClosure fc); + /** + * Applies a unifier to this object. + * @param unif The unifier + * @return A UnifyType, that may or may not be a new object, that has its subtypes substituted. + */ abstract UnifyType apply(Unifier unif); @Override diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java b/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java index 08c49783..9db59498 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java @@ -1,19 +1,30 @@ package de.dhbwstuttgart.typeinference.unify.model; +/** + * A wildcard type that is either a ExtendsType or a SuperType. + * @author Florian Steurer + */ public abstract class WildcardType extends UnifyType { + /** + * The wildcarded type, e.q. Integer for ? extends Integer. Never a wildcard type itself. + */ protected UnifyType wildcardedType; - protected WildcardType(String name, UnifyType wildcardedType, UnifyType[] typeParams) { - super(name, typeParams); - this.wildcardedType = wildcardedType; - } - - protected WildcardType(String name, UnifyType wildcardedType, TypeParams p) { - super(name, p); + /** + * Creates a new instance. + * @param name The name of the type, e.q. ? extends Integer + * @param wildcardedType The wildcarded type, e.q. Integer for ? extends Integer. Never a wildcard type itself. + */ + protected WildcardType(String name, UnifyType wildcardedType) { + super(name, wildcardedType.getTypeParams()); this.wildcardedType = wildcardedType; } + /** + * Returns the wildcarded type, e.q. Integer for ? extends Integer. + * @return The wildcarded type. Never a wildcard type itself. + */ public UnifyType getWildcardedType() { return wildcardedType; }