comments and refactoring

This commit is contained in:
Florian Steurer 2016-04-11 16:26:59 +02:00
parent 044e6fbc3f
commit 0313d297e1
6 changed files with 69 additions and 17 deletions

View File

@ -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() {

View File

@ -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;
}

View File

@ -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() {

View File

@ -17,7 +17,7 @@ public class Unifier implements Function<UnifyType, UnifyType> /*, Set<MPair>*/
/**
* Identity function as an "unifier".
*/
public Unifier() {
protected Unifier() {
}

View File

@ -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<T>)
*/
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<T>, Integer or ? extends Integer)
* @param typeParams Parameters of the type (e.q. <T> for List<T>)
*/
protected UnifyType(String name, TypeParams p) {
typeName = name;
typeParams = p;
}
/**
* Returns the name of the type.
* @return The name e.q. List for List<T>, Integer or ? extends Integer
*/
public String getName() {
return typeName;
}
/**
* The parameters of the type.
* @return Parameters of the type, e.q. <T> for List<T>.
*/
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<UnifyType> 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<UnifyType> 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

View File

@ -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;
}