forked from JavaTX/JavaCompilerCore
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;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
|
||||||
public class ExtendsType extends Type {
|
public final class ExtendsType extends Type {
|
||||||
private Type extendedType;
|
private Type extendedType;
|
||||||
|
|
||||||
public ExtendsType(Type extendedType) {
|
public ExtendsType(Type extendedType) {
|
||||||
|
super("? extends " + extendedType.getTypeParams(), extendedType.getTypeParams());
|
||||||
this.extendedType = extendedType;
|
this.extendedType = extendedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ import java.util.Set;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
|
||||||
public class PlaceholderType extends Type{
|
public final class PlaceholderType extends Type{
|
||||||
|
|
||||||
public PlaceholderType(String name) {
|
public PlaceholderType(String name) {
|
||||||
typeName = name;
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,10 +4,9 @@ import java.util.Set;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
|
||||||
public class SimpleType extends Type {
|
public final class SimpleType extends Type {
|
||||||
public SimpleType(String name, Type... typeParams) {
|
public SimpleType(String name, Type... typeParams) {
|
||||||
this.typeName = name;
|
super(name, new TypeParams(typeParams));
|
||||||
this.typeParams = new TypeParams(typeParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,11 +4,12 @@ import java.util.Set;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
|
||||||
public class SuperType extends Type {
|
public final class SuperType extends Type {
|
||||||
|
|
||||||
private Type superedType;
|
private Type superedType;
|
||||||
|
|
||||||
public SuperType(Type superedType) {
|
public SuperType(Type superedType) {
|
||||||
|
super("? extends " + superedType.getName(), superedType.getTypeParams());
|
||||||
this.superedType = superedType;
|
this.superedType = superedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
package de.dhbwstuttgart.typinference.unify.model;
|
package de.dhbwstuttgart.typinference.unify.model;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
|
||||||
public abstract class Type {
|
public abstract class Type {
|
||||||
|
|
||||||
protected String typeName = "";
|
protected final String typeName;
|
||||||
protected TypeParams typeParams;
|
protected final TypeParams typeParams;
|
||||||
|
|
||||||
public Type() {
|
protected Type(String name, Type... typeParams) {
|
||||||
typeParams = new TypeParams();
|
typeName = name;
|
||||||
|
this.typeParams = new TypeParams(typeParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Type(String name, TypeParams p) {
|
||||||
|
typeName = name;
|
||||||
|
typeParams = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -3,8 +3,10 @@ package de.dhbwstuttgart.typinference.unify.model;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class TypeParams implements Iterable<Type>{
|
import de.dhbwstuttgart.typeinference.unifynew.Unifier;
|
||||||
private Type[] typeParams;
|
|
||||||
|
public final class TypeParams implements Iterable<Type>{
|
||||||
|
private final Type[] typeParams;
|
||||||
|
|
||||||
public TypeParams(Type... types) {
|
public TypeParams(Type... types) {
|
||||||
typeParams = types;
|
typeParams = types;
|
||||||
@ -26,8 +28,20 @@ public class TypeParams implements Iterable<Type>{
|
|||||||
return typeParams.length == 0;
|
return typeParams.length == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type[] asArray() {
|
public void apply(Unifier u) {
|
||||||
return typeParams;
|
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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user