real immutability
This commit is contained in:
parent
c83697dedb
commit
9f37139ab3
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user