diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/typeinference/ResultSet.html b/doc/LambdaJavadoc/de/dhbwstuttgart/typeinference/ResultSet.html
index 711ccc169..b96e7a0bf 100644
--- a/doc/LambdaJavadoc/de/dhbwstuttgart/typeinference/ResultSet.html
+++ b/doc/LambdaJavadoc/de/dhbwstuttgart/typeinference/ResultSet.html
@@ -100,7 +100,7 @@ var activeTableTab = "activeTableTab";
java.lang.Object
-- de.dhbwstuttgart.typeinference.ResultSet
+- de.dhbwstuttgart.typeinference.result.ResultSet
diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/typeinference/class-use/ResultSet.html b/doc/LambdaJavadoc/de/dhbwstuttgart/typeinference/class-use/ResultSet.html
index cb62bfa35..aa2bb95c2 100644
--- a/doc/LambdaJavadoc/de/dhbwstuttgart/typeinference/class-use/ResultSet.html
+++ b/doc/LambdaJavadoc/de/dhbwstuttgart/typeinference/class-use/ResultSet.html
@@ -3,7 +3,7 @@
-Uses of Class de.dhbwstuttgart.typeinference.ResultSet
+Uses of Class de.dhbwstuttgart.typeinference.result.ResultSet
@@ -70,7 +70,7 @@
diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java
index e89297296..0968fe9da 100644
--- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java
+++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java
@@ -1,25 +1,18 @@
package de.dhbwstuttgart.core;
-import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
-import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
-import de.dhbwstuttgart.typedeployment.TypeInsert;
-import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
-import de.dhbwstuttgart.typedeployment.TypeInsertPoint;
-import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
+import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
-import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
-import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import java.io.File;
import java.io.IOException;
@@ -52,7 +45,7 @@ public class JavaTXCompiler {
System.out.println("RESULT: " + result);
results.addAll(result);
}
- return new ResultSet(UnifyTypeFactory.convert(results, generateTPHMap(cons)));
+ return new ResultSet(UnifyTypeFactory.convert(results.iterator().next(), generateTPHMap(cons)));
//return new ResultSet(new HashSet<>(Arrays.asList(UnifyTypeFactory.convert(results, generateTPHMap(cons)).iterator().next())));
}
diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
index 89bc43742..38cbd0cbd 100644
--- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
+++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
@@ -467,7 +467,7 @@ public class StatementGenerator {
private Statement convert(Java8Parser.ReturnStatementContext stmt){
if(stmt.expression() != null){
- return new Return( convert(stmt.expression()),stmt.getStart());
+ return new Return( convert(stmt.expression()),stmt.getStart() );
}else{
return new ReturnVoid(stmt.getStart());
}
diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
index 9775fa174..72b9ccd8a 100644
--- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
+++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
@@ -11,6 +11,9 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
+import de.dhbwstuttgart.typeinference.result.PairTPHequalRefType;
+import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
+import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
@@ -133,18 +136,20 @@ public class UnifyTypeFactory {
* Convert from
* UnifyType -> ASTType
*/
- public static Set> convert(Set> unifyPairSet, Map tphs) {
+ public static Set convert(Set unifyPairSet, Map tphs) {
return unifyPairSet.stream().map(
- set -> set.stream().map(
- unifyPair -> convert(unifyPair, tphs))
- .collect(Collectors.toSet()))
- .collect(Collectors.toSet());
+ unifyPair -> convert(unifyPair, tphs))
+ .collect(Collectors.toSet());
}
- public static Pair convert(UnifyPair mp, Map tphs) {
+ public static ResultPair convert(UnifyPair mp, Map tphs) {
RefTypeOrTPHOrWildcardOrGeneric tl = UnifyTypeFactory.convert(mp.getLhsType(), tphs);
RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs);
- return new Pair(tl, tr, mp.getPairOp());
+ if(tl instanceof TypePlaceholder){
+ if(tr instanceof TypePlaceholder) return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr);
+ if(tr instanceof RefType)return new PairTPHequalRefType((TypePlaceholder)tl, (RefType)tr);
+ throw new NotImplementedException();
+ }else throw new NotImplementedException();
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map tphs) {
diff --git a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java
index 0767c59d9..f283362a9 100755
--- a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java
+++ b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java
@@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
+import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
/**
@@ -38,4 +39,9 @@ public class ExtendsWildcardType extends WildcardType{
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
+
+ @Override
+ public void accept(ResultSetVisitor visitor) {
+ visitor.visit(this);
+ }
}
diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java
index ebb289469..8de5f1ab0 100755
--- a/src/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java
+++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java
@@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.typecheck.GenericTypeName;
import de.dhbwstuttgart.typecheck.JavaClassName;
+import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
@@ -26,5 +27,10 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
+
+ @Override
+ public void accept(ResultSetVisitor visitor) {
+ visitor.visit(this);
+ }
}
diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java
index e8030403d..238fe12d6 100755
--- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java
+++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java
@@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.typecheck.JavaClassName;
+import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
@@ -105,5 +106,10 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
+
+ @Override
+ public void accept(ResultSetVisitor visitor) {
+ visitor.visit(this);
+ }
}
diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java b/src/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java
index 20bc5b457..75638712d 100644
--- a/src/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java
+++ b/src/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java
@@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
+import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
@@ -11,4 +12,6 @@ public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
@Override
public abstract void accept(ASTVisitor visitor);
+
+ public abstract void accept(ResultSetVisitor visitor);
}
diff --git a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java
index 4cbee79e8..d1945f80f 100755
--- a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java
+++ b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java
@@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
+import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
/**
@@ -48,4 +49,9 @@ public class SuperWildcardType extends WildcardType{
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
+
+ @Override
+ public void accept(ResultSetVisitor visitor) {
+ visitor.visit(this);
+ }
}
diff --git a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java
index 978455454..99a34cd56 100755
--- a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java
+++ b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java
@@ -4,6 +4,7 @@ import java.util.Hashtable;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
+import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
/**
@@ -71,4 +72,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
+
+ @Override
+ public void accept(ResultSetVisitor visitor) {
+ visitor.visit(this);
+ }
}
diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java
index 046ae735e..b1aebc8d9 100644
--- a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java
+++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java
@@ -3,8 +3,9 @@ package de.dhbwstuttgart.typedeployment;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.type.*;
-import de.dhbwstuttgart.typeinference.ResultSet;
-import de.dhbwstuttgart.typeinference.constraints.Pair;
+import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
+import de.dhbwstuttgart.typeinference.result.ResolvedType;
+import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.antlr.v4.runtime.Token;
import java.util.*;
@@ -30,10 +31,16 @@ public class TypeInsertFactory {
}
public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
- Set pairs) {
+ ResultSet resultSet) {
Set ret = new HashSet<>();
TypeInsertPoint insertPoint = null;
- Set additionalInserts = new HashSet<>();
+ ResolvedType resolvedType = resultSet.resolveType(type);
+ if(resolvedType.resolvedType instanceof RefType){
+ insertPoint = new TypeInsertPoint(offset,
+ createInsertString((RefType) resolvedType.resolvedType));
+ }
+ return new TypeInsert(insertPoint, new HashSet<>(Arrays.asList(createGenericInsert(resolvedType.additionalGenerics, cl, m))));
+ /*
for (Pair pair : pairs) {
RefTypeOrTPHOrWildcardOrGeneric relatedType = null;
if (pair.TA1.equals(type)) {
@@ -97,10 +104,10 @@ public class TypeInsertFactory {
ret.add(createGenericInsert(newGenerics, cl, m));
//return ret;
- return new TypeInsert(insertPoint, ret);
+ */
}
- private static String createInsertString(RefType resolved, Set additionalInserts) {
+ private static String createInsertString(RefType resolved) {
String insert = resolved.getName().toString();
if(resolved.getParaList().size() > 0){
insert += "<";
@@ -109,13 +116,12 @@ public class TypeInsertFactory {
RefTypeOrTPHOrWildcardOrGeneric typeParam = iterator.next();
if(typeParam instanceof TypePlaceholder){
insert += ((TypePlaceholder) typeParam).getName();
- additionalInserts.add((TypePlaceholder) typeParam);
}else if(typeParam instanceof RefType) {
- insert += createInsertString((RefType) typeParam, additionalInserts);
+ insert += createInsertString((RefType) typeParam);
}else if(typeParam instanceof SuperWildcardType){
- insert += "? super " + createInsertString(((SuperWildcardType) typeParam).getInnerType(), additionalInserts);
+ insert += "? super " + createInsertString(((SuperWildcardType) typeParam).getInnerType());
}else if(typeParam instanceof ExtendsWildcardType){
- insert += "? extends " + createInsertString(((ExtendsWildcardType) typeParam).getInnerType(), additionalInserts);
+ insert += "? extends " + createInsertString(((ExtendsWildcardType) typeParam).getInnerType());
}else throw new NotImplementedException();
if(iterator.hasNext())insert += ", ";
}
diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java
index a8fc9de6e..17ef45851 100644
--- a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java
+++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java
@@ -1,16 +1,13 @@
package de.dhbwstuttgart.typedeployment;
import de.dhbwstuttgart.syntaxtree.*;
-import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
-import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
-import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
+import de.dhbwstuttgart.typeinference.result.ResultPair;
+import de.dhbwstuttgart.typeinference.result.ResultSet;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
public class TypeInsertPlacer extends AbstractASTWalker{
@@ -43,18 +40,16 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
@Override
public void visit(Method method) {
- for(Set pairs : results.results)
inserts.add(TypeInsertFactory.createInsertPoints(
- method.getReturnType(), method.getReturnType().getOffset(), cl, null, pairs));
+ method.getReturnType(), method.getReturnType().getOffset(), cl, null, results));
super.visit(method);
}
@Override
public void visit(Field field) {
if(field.getType() instanceof TypePlaceholder){
- for(Set pairs : results.results)
inserts.add(TypeInsertFactory.createInsertPoints(
- field.getType(), field.getType().getOffset(), cl, null, pairs));
+ field.getType(), field.getType().getOffset(), cl, null, results));
}
super.visit(field);
}
@@ -62,9 +57,8 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
@Override
public void visit(ParameterList params) {
for(FormalParameter param : params){
- for(Set pairs : results.results)
inserts.add(TypeInsertFactory.createInsertPoints(
- param.getType(), param.getType().getOffset(), cl, null, pairs));
+ param.getType(), param.getType().getOffset(), cl, null, results));
}
super.visit(params);
}
diff --git a/src/de/dhbwstuttgart/typeinference/ResultSet.java b/src/de/dhbwstuttgart/typeinference/ResultSet.java
deleted file mode 100644
index 915fb81fc..000000000
--- a/src/de/dhbwstuttgart/typeinference/ResultSet.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package de.dhbwstuttgart.typeinference;
-
-import de.dhbwstuttgart.exceptions.NotImplementedException;
-import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
-import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
-import de.dhbwstuttgart.typeinference.constraints.Pair;
-import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
-import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-public class ResultSet {
- public final Set> results;
- public ResultSet(Set> results){
- this.results = results;
- }
-
- public List resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
- /*//Probleme:
- * Es müssen teilweise mehrere TPH eingesetzt werden
- * Es werden alle eingesetzt, welch in der Kette stehen!
- * TPHs müssen zu eindeutigen Namen aufgelöst werden
- */
- final List ret = new ArrayList<>();
- for(Set pairs : results)for(Pair pair : pairs){
- //if(pair.OperatorEqual()){ //type ist vom Typ TypePlaceholder
- if(pair.TA1.equals(type) || pair.TA2.equals(type)){
- ret.add(pair);
- }
- //}
- }
- return ret;
- }
-}
diff --git a/src/de/dhbwstuttgart/typedeployment/GenericInsertPair.java b/src/de/dhbwstuttgart/typeinference/result/GenericInsertPair.java
similarity index 94%
rename from src/de/dhbwstuttgart/typedeployment/GenericInsertPair.java
rename to src/de/dhbwstuttgart/typeinference/result/GenericInsertPair.java
index 9377c063c..824d20838 100644
--- a/src/de/dhbwstuttgart/typedeployment/GenericInsertPair.java
+++ b/src/de/dhbwstuttgart/typeinference/result/GenericInsertPair.java
@@ -1,4 +1,4 @@
-package de.dhbwstuttgart.typedeployment;
+package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
diff --git a/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java b/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java
new file mode 100644
index 000000000..71db19d82
--- /dev/null
+++ b/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java
@@ -0,0 +1,23 @@
+package de.dhbwstuttgart.typeinference.result;
+
+import de.dhbwstuttgart.syntaxtree.type.RefType;
+import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
+
+/**
+ * Steht für A =. RefType
+ */
+public class PairTPHequalRefType extends ResultPair{
+ public final TypePlaceholder left;
+ public final RefType right;
+
+ public PairTPHequalRefType(TypePlaceholder left, RefType right){
+ super(left, right);
+ this.left = left;
+ this.right = right;
+ }
+
+ @Override
+ public void accept(ResultSetVisitor visitor) {
+ visitor.visit(this);
+ }
+}
diff --git a/src/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java b/src/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java
new file mode 100644
index 000000000..854d4aac4
--- /dev/null
+++ b/src/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java
@@ -0,0 +1,23 @@
+package de.dhbwstuttgart.typeinference.result;
+
+import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
+import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
+
+/**
+ * Steht für: A <. B
+ */
+public class PairTPHsmallerTPH extends ResultPair{
+ public final TypePlaceholder left;
+ public final TypePlaceholder right;
+
+ public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right){
+ super(left, right);
+ this.left = left;
+ this.right = right;
+ }
+
+ @Override
+ public void accept(ResultSetVisitor visitor) {
+ visitor.visit(this);
+ }
+}
diff --git a/src/de/dhbwstuttgart/typeinference/result/ResolvedType.java b/src/de/dhbwstuttgart/typeinference/result/ResolvedType.java
new file mode 100644
index 000000000..b9e6985b2
--- /dev/null
+++ b/src/de/dhbwstuttgart/typeinference/result/ResolvedType.java
@@ -0,0 +1,17 @@
+package de.dhbwstuttgart.typeinference.result;
+
+import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
+import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
+import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
+
+import java.util.Set;
+
+public class ResolvedType{
+ public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
+ public final Set additionalGenerics;
+
+ public ResolvedType(RefTypeOrTPHOrWildcardOrGeneric resolvedType, Set additionalGenerics){
+ this.resolvedType = resolvedType;
+ this.additionalGenerics = additionalGenerics;
+ }
+}
diff --git a/src/de/dhbwstuttgart/typeinference/result/ResultPair.java b/src/de/dhbwstuttgart/typeinference/result/ResultPair.java
new file mode 100644
index 000000000..4c7541980
--- /dev/null
+++ b/src/de/dhbwstuttgart/typeinference/result/ResultPair.java
@@ -0,0 +1,26 @@
+package de.dhbwstuttgart.typeinference.result;
+
+import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
+
+/**
+ * Paare, welche das Unifikationsergebnis darstellen
+ */
+public abstract class ResultPair {
+ private final RefTypeOrTPHOrWildcardOrGeneric left;
+ private final RefTypeOrTPHOrWildcardOrGeneric right;
+
+ public abstract void accept(ResultSetVisitor visitor);
+
+ public ResultPair(RefTypeOrTPHOrWildcardOrGeneric left, RefTypeOrTPHOrWildcardOrGeneric right){
+ this.left = left;
+ this.right = right;
+ }
+
+ public RefTypeOrTPHOrWildcardOrGeneric getLeft() {
+ return left;
+ }
+
+ public RefTypeOrTPHOrWildcardOrGeneric getRight() {
+ return right;
+ }
+}
diff --git a/src/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/de/dhbwstuttgart/typeinference/result/ResultSet.java
new file mode 100644
index 000000000..289c53443
--- /dev/null
+++ b/src/de/dhbwstuttgart/typeinference/result/ResultSet.java
@@ -0,0 +1,230 @@
+package de.dhbwstuttgart.typeinference.result;
+
+import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
+import de.dhbwstuttgart.syntaxtree.type.*;
+import de.dhbwstuttgart.typeinference.constraints.Pair;
+
+import javax.xml.transform.Result;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class ResultSet {
+ public final Set results;
+ public ResultSet(Set results){
+ this.results = results;
+ }
+
+ public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
+ if(type instanceof TypePlaceholder)
+ return new Resolver(this).resolve((TypePlaceholder)type);
+ if(type instanceof RefType){
+ RelatedTypeWalker related = new RelatedTypeWalker(null, this);
+ type.accept(related);
+ return new ResolvedType(type, related.relatedTPHs);
+ }else{
+ return new ResolvedType(type,new HashSet<>());
+ }
+ }
+
+ //TODO Beim Einsetzen eines Generics, müssen die new und Methodenaufrufe verändert werden
+
+
+}
+
+class Resolver implements ResultSetVisitor {
+ private final ResultSet result;
+ private TypePlaceholder toResolve;
+ private RefType resolved;
+ private final Set additionalTPHs = new HashSet<>();
+
+ public Resolver(ResultSet resultPairs){
+ this.result = resultPairs;
+ }
+
+ public ResolvedType resolve(TypePlaceholder tph){
+ toResolve = tph;
+ resolved = null;
+ for(ResultPair resultPair : result.results){
+ resultPair.accept(this);
+ }
+ if(resolved==null){//TPH kommt nicht im Result vor:
+
+ }
+
+ return new ResolvedType(resolved, additionalTPHs);//resolved;
+ }
+
+ @Override
+ public void visit(PairTPHsmallerTPH p) {
+ if(p.left.equals(toResolve)){
+ additionalTPHs.add(new GenericInsertPair(p.left, p.right));
+ additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs);
+ }
+ if(p.right.equals(toResolve))
+ additionalTPHs.addAll(new RelatedTypeWalker(p.left, result).relatedTPHs);
+ }
+
+ @Override
+ public void visit(PairTPHequalRefType p) {
+ if(p.left.equals(toResolve)){
+ resolved = p.right;
+ RelatedTypeWalker related = new RelatedTypeWalker(null, result);
+ related.visit(p.right);
+ additionalTPHs.addAll(related.relatedTPHs);
+ }
+ }
+
+ @Override
+ public void visit(RefType refType) {
+
+ }
+
+ @Override
+ public void visit(GenericRefType genericRefType) {
+
+ }
+
+ @Override
+ public void visit(SuperWildcardType superWildcardType) {
+
+ }
+
+ @Override
+ public void visit(TypePlaceholder typePlaceholder) {
+
+ }
+
+ @Override
+ public void visit(ExtendsWildcardType extendsWildcardType) {
+
+ }
+
+}
+
+/**
+ * Sucht aus dem Result Set den Sub/supertyp für einen TPH
+ */
+class TPHResolver implements ResultSetVisitor {
+
+ private final TypePlaceholder tph;
+ Set resolved = new HashSet<>();
+
+ TPHResolver(TypePlaceholder tph, ResultSet resultSet){
+ this.tph = tph;
+ for(ResultPair p : resultSet.results){
+ p.accept(this);
+ }
+ if(resolved.size() == 0){
+ resolved.add(new GenericInsertPair(tph, null));
+ }
+ }
+
+ @Override
+ public void visit(PairTPHsmallerTPH p) {
+ if(p.left.equals(tph) || p.right.equals(tph)){
+ resolved.add(new GenericInsertPair(p.left, p.right));
+ }
+ }
+
+ @Override
+ public void visit(PairTPHequalRefType p) {
+
+ }
+
+ @Override
+ public void visit(RefType refType) {
+
+ }
+
+ @Override
+ public void visit(GenericRefType genericRefType) {
+
+ }
+
+ @Override
+ public void visit(SuperWildcardType superWildcardType) {
+
+ }
+
+ @Override
+ public void visit(TypePlaceholder typePlaceholder) {
+
+ }
+
+ @Override
+ public void visit(ExtendsWildcardType extendsWildcardType) {
+
+ }
+}
+
+class RelatedTypeWalker implements ResultSetVisitor {
+
+ final Set relatedTPHs = new HashSet<>();
+ private final TypePlaceholder toResolve;
+ private final ResultSet resultSet;
+
+ /**
+ * Läuft über das resultSet und speichert alle TPHs, welche mit start in Verbindung stehen
+ * @param start
+ * @param resultSet
+ */
+ RelatedTypeWalker(TypePlaceholder start, ResultSet resultSet){
+ this.toResolve = start;
+ this.resultSet = resultSet;
+ for(ResultPair p : resultSet.results){
+ p.accept(this);
+ p.accept(this);
+ }
+ }
+
+ @Override
+ public void visit(PairTPHsmallerTPH p) {
+ if(p.getRight().equals(toResolve)){
+ relatedTPHs.addAll(new TPHResolver(p.right, resultSet).resolved);
+ relatedTPHs.addAll(new RelatedTypeWalker(p.right, resultSet).relatedTPHs);
+ }
+ if(p.getLeft().equals(toResolve)){
+ relatedTPHs.addAll(new TPHResolver(p.left, resultSet).resolved);
+ relatedTPHs.addAll(new RelatedTypeWalker(p.left, resultSet).relatedTPHs);
+ }
+ }
+
+ @Override
+ public void visit(PairTPHequalRefType p) {
+ if(p.getLeft().equals(toResolve)){
+ p.getRight().accept(this);
+ }
+ }
+
+ /*
+ Die folgenden Funktionen fügen alle TPHs an die relatedTPHs an, denen sie begegnen:
+ */
+
+ @Override
+ public void visit(RefType refType) {
+ for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
+ param.accept(this);
+ }
+ }
+
+ @Override
+ public void visit(SuperWildcardType superWildcardType) {
+ superWildcardType.getInnerType().accept(this);
+ }
+
+ @Override
+ public void visit(TypePlaceholder typePlaceholder) {
+ relatedTPHs.addAll(new TPHResolver(typePlaceholder, resultSet).resolved);
+ }
+
+ @Override
+ public void visit(ExtendsWildcardType extendsWildcardType) {
+ extendsWildcardType.getInnerType().accept(this);
+ }
+
+ @Override
+ public void visit(GenericRefType genericRefType) {
+ }
+}
\ No newline at end of file
diff --git a/src/de/dhbwstuttgart/typeinference/result/ResultSetVisitor.java b/src/de/dhbwstuttgart/typeinference/result/ResultSetVisitor.java
new file mode 100644
index 000000000..3f21ae314
--- /dev/null
+++ b/src/de/dhbwstuttgart/typeinference/result/ResultSetVisitor.java
@@ -0,0 +1,18 @@
+package de.dhbwstuttgart.typeinference.result;
+
+import de.dhbwstuttgart.syntaxtree.type.*;
+
+public interface ResultSetVisitor {
+ void visit(PairTPHsmallerTPH p);
+ void visit(PairTPHequalRefType p);
+
+ void visit(RefType refType);
+
+ void visit(GenericRefType genericRefType);
+
+ void visit(SuperWildcardType superWildcardType);
+
+ void visit(TypePlaceholder typePlaceholder);
+
+ void visit(ExtendsWildcardType extendsWildcardType);
+}
diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java
index 2337dad64..2aac0f6ad 100644
--- a/test/typeinference/JavaTXCompilerTest.java
+++ b/test/typeinference/JavaTXCompilerTest.java
@@ -1,17 +1,10 @@
package typeinference;
import de.dhbwstuttgart.core.JavaTXCompiler;
-import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.syntaxtree.SourceFile;
-import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
-import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
-import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
-import de.dhbwstuttgart.syntaxtree.visual.OutputGenerator;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
-import de.dhbwstuttgart.typedeployment.TypeInsertPoint;
-import de.dhbwstuttgart.typeinference.ResultSet;
import org.junit.Test;
import java.io.File;
@@ -24,8 +17,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import static org.junit.Assert.*;
-
public class JavaTXCompilerTest extends JavaTXCompiler {
private static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";