From 6b709f0198a2082ed674a5d2adefd2f4105318f9 Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Sat, 7 Nov 2015 13:57:54 +0100 Subject: [PATCH] fc smaller greater tests --- .../unify/interfaces/IFiniteClosure.java | 2 -- .../unify/model/FiniteClosure.java | 26 ++++++++++++++----- .../typinference/unify/model/Node.java | 5 ++++ .../unify/model/PlaceholderType.java | 5 +++- .../typinference/unify/model/Type.java | 4 +++ 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java index 7c020817..83f17ca9 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java @@ -29,7 +29,5 @@ public interface IFiniteClosure { public boolean isInSmArg(Type smArgT, Type t); - public Set smaller(String typeName); - public Type getType(String typeName); } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java index 712b99a6..1d969043 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java @@ -36,6 +36,7 @@ public class FiniteClosure implements IFiniteClosure { // Add edges to build the transitive closure parentNode.getPredecessors().stream().forEach(x -> x.AddDescendant(childNode)); + childNode.getDescendants().stream().forEach(x -> x.AddPredecessor(parentNode)); } } @@ -48,8 +49,7 @@ public class FiniteClosure implements IFiniteClosure { return smaller(type.getName()); } - @Override - public Set smaller(String typeName) { + private Set smaller(String typeName) { if(!inheritanceGraph.containsKey(typeName)) return new HashSet<>(); @@ -70,20 +70,34 @@ public class FiniteClosure implements IFiniteClosure { */ @Override public Set greater(Type type) { - if(!inheritanceGraph.containsKey(type.getName())) + return greater(type.typeName); + } + + private Set greater(String typeName) { + if(!inheritanceGraph.containsKey(typeName)) return new HashSet<>(); - return inheritanceGraph.get(type.getName()).getContentOfPredecessors(); + return inheritanceGraph.get(typeName).getContentOfPredecessors(); } @Override public Set grArg(Type type) { - throw new NotImplementedException(); + return grArg(type.getName()); + } + + private Set grArg(String typeName) { + // TODO Auto-generated method stub + return null; } @Override public Set smArg(Type type) { - throw new NotImplementedException(); + return smArg(type.getName()); + } + + private Set smArg(String typeName) { + // TODO Auto-generated method stub + return null; } @Override diff --git a/src/de/dhbwstuttgart/typinference/unify/model/Node.java b/src/de/dhbwstuttgart/typinference/unify/model/Node.java index f0eaa635..e42a2608 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/Node.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/Node.java @@ -49,4 +49,9 @@ public class Node { public Set getContentOfPredecessors() { return predecessors.stream().map(x -> x.getContent()).collect(Collectors.toSet()); } + + @Override + public String toString() { + return "Node(" + content.toString() + ")"; + } } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java index 7ef1f38b..03e66c80 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java @@ -1,5 +1,8 @@ package de.dhbwstuttgart.typinference.unify.model; public class PlaceholderType extends Type{ - + + public PlaceholderType(String name) { + typeName = name; + } } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/Type.java b/src/de/dhbwstuttgart/typinference/unify/model/Type.java index ed317e73..52c58868 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/Type.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/Type.java @@ -7,6 +7,10 @@ public abstract class Type { protected String typeName = ""; protected TypeParams typeParams; + public Type() { + typeParams = new TypeParams(); + } + public String getName() { return typeName; }