real immutability

This commit is contained in:
Florian Steurer 2015-11-13 22:45:13 +01:00
parent c83697dedb
commit 9f37139ab3
6 changed files with 36 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,8 +3,10 @@ package de.dhbwstuttgart.typinference.unify.model;
import java.util.Arrays;
import java.util.Iterator;
public class TypeParams implements Iterable<Type>{
private Type[] typeParams;
import de.dhbwstuttgart.typeinference.unifynew.Unifier;
public final class TypeParams implements Iterable<Type>{
private final Type[] typeParams;
public TypeParams(Type... types) {
typeParams = types;
@ -26,8 +28,20 @@ public class TypeParams implements Iterable<Type>{
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