forked from JavaTX/JavaCompilerCore
modified: src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java
modified: src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java modified: src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java Visitors verallgemeinert
This commit is contained in:
parent
0b680f831d
commit
fae26a8f26
@ -1,47 +1,15 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||
|
||||
public class freshPlaceholder implements UnifyTypeVisitor {
|
||||
|
||||
public ReferenceType visit(ReferenceType refty, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
return new ReferenceType(refty.getName(),
|
||||
new TypeParams(
|
||||
Arrays.stream(refty.getTypeParams().get())
|
||||
.map(x -> x.accept(this, ht))
|
||||
.collect(Collectors.toCollection(ArrayList::new))));
|
||||
}
|
||||
|
||||
public class freshPlaceholder extends visitUnifyTypeVisitor<HashMap<PlaceholderType,PlaceholderType>> {
|
||||
|
||||
@Override
|
||||
public PlaceholderType visit(PlaceholderType phty, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
return ht.get(phty);
|
||||
}
|
||||
|
||||
public FunNType visit(FunNType funnty, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
return FunNType.getFunNType(
|
||||
new TypeParams(
|
||||
Arrays.stream(funnty.getTypeParams().get())
|
||||
.map(x -> x.accept(this, ht))
|
||||
.collect(Collectors.toCollection(ArrayList::new)))
|
||||
);
|
||||
}
|
||||
|
||||
public SuperType visit(SuperType suty, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
return new SuperType(suty.getWildcardedType().accept(this, ht));
|
||||
}
|
||||
|
||||
public ExtendsType visit(ExtendsType extty, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
return new ExtendsType(extty.getWildcardedType().accept(this, ht));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,16 +8,16 @@ import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||
|
||||
public interface UnifyTypeVisitor {
|
||||
public interface UnifyTypeVisitor<T> {
|
||||
|
||||
public ReferenceType visit(ReferenceType refty, HashMap<PlaceholderType,PlaceholderType> ht);
|
||||
public ReferenceType visit(ReferenceType refty, T ht);
|
||||
|
||||
public PlaceholderType visit(PlaceholderType phty, HashMap<PlaceholderType,PlaceholderType> ht);
|
||||
public PlaceholderType visit(PlaceholderType phty, T ht);
|
||||
|
||||
public FunNType visit(FunNType funnty, HashMap<PlaceholderType,PlaceholderType> ht);
|
||||
public FunNType visit(FunNType funnty, T ht);
|
||||
|
||||
public SuperType visit(SuperType suty, HashMap<PlaceholderType,PlaceholderType> ht);
|
||||
public SuperType visit(SuperType suty, T ht);
|
||||
|
||||
public ExtendsType visit(ExtendsType extty, HashMap<PlaceholderType,PlaceholderType> ht);
|
||||
public ExtendsType visit(ExtendsType extty, T ht);
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
|
||||
*/
|
||||
public final class ExtendsType extends WildcardType {
|
||||
|
||||
public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
||||
return visitor.visit(this, ht);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
|
||||
*/
|
||||
public class FunNType extends UnifyType {
|
||||
|
||||
public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
||||
return visitor.visit(this, ht);
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ public final class PlaceholderType extends UnifyType{
|
||||
IsGenerated = isGenerated;
|
||||
}
|
||||
|
||||
public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
||||
return visitor.visit(this, ht);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ public final class ReferenceType extends UnifyType {
|
||||
private final int hashCode;
|
||||
|
||||
|
||||
public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
||||
return visitor.visit(this, ht);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
|
||||
*/
|
||||
public final class SuperType extends WildcardType {
|
||||
|
||||
public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
|
||||
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
||||
return visitor.visit(this, ht);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public abstract class UnifyType {
|
||||
}
|
||||
|
||||
|
||||
abstract public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht);
|
||||
abstract public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht);
|
||||
|
||||
/**
|
||||
* Returns the name of the type.
|
||||
|
Loading…
Reference in New Issue
Block a user