diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 51549f23..79901bba 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,8 +3,12 @@
-
-
+
+
+
+
+
+
@@ -20,11 +24,21 @@
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -32,103 +46,101 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -141,8 +153,6 @@
- ConstraintS
- Constraint
methodCa
getClass
ConstraintM
@@ -171,6 +181,8 @@
r_20
20
new
+ getNeu
+ adapt
@@ -184,12 +196,6 @@
@@ -375,6 +387,110 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -413,8 +529,8 @@
-
+
@@ -425,7 +541,7 @@
-
+
@@ -478,32 +594,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -556,6 +646,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -939,17 +1055,17 @@
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
@@ -967,44 +1083,44 @@
1492600650522
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
@@ -1032,7 +1148,7 @@
-
+
@@ -1103,7 +1219,7 @@
-
+
@@ -1112,54 +1228,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1352,24 +1420,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1412,50 +1462,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1484,35 +1490,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1537,14 +1514,6 @@
-
-
-
-
-
-
-
-
@@ -1555,36 +1524,188 @@
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/de/dhbwstuttgart/strucTypes5/algo/TI.java b/src/de/dhbwstuttgart/strucTypes5/algo/TI.java
index b0cce412..e0861171 100644
--- a/src/de/dhbwstuttgart/strucTypes5/algo/TI.java
+++ b/src/de/dhbwstuttgart/strucTypes5/algo/TI.java
@@ -8,6 +8,7 @@ import de.dhbwstuttgart.strucTypes5.ausgabe.Class2String;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintSubType;
import de.dhbwstuttgart.strucTypes5.constraints.OldConstraints;
+import de.dhbwstuttgart.strucTypes5.solve.Rules;
import de.dhbwstuttgart.strucTypes5.typeVars.ResultTuple;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
@@ -111,7 +112,9 @@ public class TI {
- // Result of Solve ->
+ // Result of Construct Basis für die Unifikation
+ System.out.println("Result of Solve: ");
+ System.out.println(newResultConstraints);
diff --git a/src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintInterface.java b/src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintInterface.java
new file mode 100644
index 00000000..8c65ed51
--- /dev/null
+++ b/src/de/dhbwstuttgart/strucTypes5/constraints/ConstraintInterface.java
@@ -0,0 +1,60 @@
+package de.dhbwstuttgart.strucTypes5.constraints;
+
+import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
+
+/**
+ * Created by sebastian on 02.05.17.
+ */
+public class ConstraintInterface extends ConstraintAbstract {
+
+ private TypeVarAbstract SubType;
+ private TypeVarAbstract SuperType;
+
+ public ConstraintInterface(TypeVarAbstract subType, TypeVarAbstract superType) {
+ SubType = subType;
+ SuperType = superType;
+ }
+
+
+ public TypeVarAbstract getSubType() {
+ return SubType;
+ }
+
+ public void setSubType(TypeVarAbstract subType) {
+ SubType = subType;
+ }
+
+ public TypeVarAbstract getSuperType() {
+ return SuperType;
+ }
+
+ public void setSuperType(TypeVarAbstract superType) {
+ SuperType = superType;
+ }
+
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ConstraintInterface)) return false;
+
+ ConstraintInterface that = (ConstraintInterface) o;
+
+ if (getSubType() != null ? !getSubType().equals(that.getSubType()) : that.getSubType() != null) return false;
+ return getSuperType() != null ? getSuperType().equals(that.getSuperType()) : that.getSuperType() == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = getSubType() != null ? getSubType().hashCode() : 0;
+ result = 31 * result + (getSuperType() != null ? getSuperType().hashCode() : 0);
+ return result;
+ }
+
+
+ //
+ @Override
+ public String toString() {
+ return String.format("ConstraintInterface( %s <* %s ) " , getSubType(), getSuperType());
+ }
+}
diff --git a/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java b/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java
index 347b3b30..4e66e253 100644
--- a/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java
+++ b/src/de/dhbwstuttgart/strucTypes5/solve/Rules.java
@@ -1,13 +1,16 @@
package de.dhbwstuttgart.strucTypes5.solve;
-import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract;
-import de.dhbwstuttgart.strucTypes5.constraints.ConstraintShouldEqual;
-import de.dhbwstuttgart.strucTypes5.constraints.ConstraintSubType;
+import de.dhbwstuttgart.strucTypes5.algo.Type;
+import de.dhbwstuttgart.strucTypes5.constraints.*;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
+import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarRefType;
+import de.dhbwstuttgart.syntaxtree.Generic;
+import de.dhbwstuttgart.typeinference.constraints.Constraint;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -16,9 +19,25 @@ import java.util.List;
public class Rules {
+ private List constraintInterfaces = new ArrayList<>();
+ /*
+ Achtung höchstwahrscheinlich ist \theta auch ein type (eben ein Struktureller ), Dieser muss auch verglichen werden!!!
+ - Rules given by Plümicke
+ - reduce (1/2) reduceEqual implemented
+ - adapt1 - implemented
+ - adapt2 -
+ - erase1 - implemented
+ - erase2 - implemented
+ - swap - implemented
+ - subst - implemented
+ - refl - implemented
+ */
+
+
+ public List substitutions = new ArrayList<>();
public void erase1(List constraints) {
for (ConstraintAbstract cs : constraints) {
@@ -73,8 +92,251 @@ public class Rules {
C[T -> Typ vereinigt mit T =* Theta
Wenn T eine Typvariable ist und T in C aber nicht in Theta vorkommt
*/
- public void subst(List constratins) {
+ public void subst(List constraints) {
+ for (ConstraintAbstract cs : constraints) {
+ if (cs instanceof ConstraintShouldEqual) {
+ TypeVarAbstract t1 = ((ConstraintShouldEqual) cs).getT1();
+ TypeVarAbstract t2 = ((ConstraintShouldEqual) cs).getT2();
+ if (t1 instanceof TypeVar) {
+ if (t2 instanceof TypeVarRefType || t2 instanceof TypeVarInterface) {
+ ConstraintSubstitution constraintSubstitution = new ConstraintSubstitution(t1 , t2);
+ substitutions.add(constraintSubstitution);
+ // Todo Occors Check
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ // ToDo Not implemented
+ public void reduce(List constraints) {
+ for (ConstraintAbstract cs : constraints) {
+
+
+ }
+ }
+
+ // Todo wer sagt dass man nicht irgendwo in der mitte anfängt
+ public void reflect(List constriants) {
+ for (ConstraintAbstract cs : constriants) {
+ if (cs instanceof ConstraintSubType) {
+ TypeVarAbstract t1 = ((ConstraintSubType) cs).getSubtype();
+
+ if (t1 instanceof TypeVarRefType || t1 instanceof TypeVarInterface ) {
+ // Hier muss geschaut werden ob es einen nächsten gibt
+ List chain = reflectNext(t1,((ConstraintSubType) cs).getSubtype() , constriants);
+ if (chain != null) {
+ System.out.println("erfolg");
+ System.out.println(chain);
+ }
+ else {
+ System.out.println("kein erfolg");
+ return;
+ }
+
+
+ }
+ }
+ }
+ }
+
+ private List reflectNext(TypeVarAbstract startValue, TypeVarAbstract lastValue , List remainingConstraints) {
+
+ // suche next
+
+
+ for (ConstraintAbstract cs : remainingConstraints) {
+ if (cs instanceof ConstraintSubType) {
+ TypeVarAbstract tProbNext = ((ConstraintSubType) cs).getSubtype();
+ TypeVarAbstract tNextSuper = ((ConstraintSubType) cs).getSuperType();
+
+ if (tProbNext.equals(lastValue)) {
+
+
+ // 1. Supertyp ist der gesuchte Typ
+ if (tNextSuper.equals(startValue)) {
+ List chain = new ArrayList<>();
+
+ // Füge Type Var in die Kette ein
+ // ToDo Substituion
+ if (tProbNext instanceof TypeVar) {
+ //chain.add((TypeVar) tProbNext);
+ }
+ else {
+ System.err.println(Rules.class.getName() + "LogikFehler");
+ }
+ return chain;
+ }
+
+ //2. Supertyp != der gesuchte Typ aber TypVar
+ else if (tNextSuper instanceof TypeVar) {
+ List remainingConstriants2 = new ArrayList<>();
+ remainingConstriants2.addAll(remainingConstraints);
+ remainingConstriants2.remove(cs);
+ List chain = reflectNext(startValue,tNextSuper, remainingConstriants2);
+
+ if (chain != null) {
+ chain.add((TypeVar) tNextSuper);
+ return chain;
+ }
+ else {
+ return null;
+ }
+
+
+ }
+ // 3. sonst
+ else {
+ return null;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+
+
+ public void reduceEqual(List constraints) {
+ for (ConstraintAbstract cs : constraints) {
+ if (cs instanceof ConstraintShouldEqual) {
+ ConstraintShouldEqual css = (ConstraintShouldEqual) cs;
+ if (css.getT1() instanceof TypeVarInterface && css.getT2() instanceof TypeVarInterface ) {
+
+
+ TypeVarInterface st1 = (TypeVarInterface) css.getT1();
+ TypeVarInterface st2 = (TypeVarInterface) css.getT2();
+
+ InterfaceForConstraint if1 = st1.getInterfaceForConstraint();
+ InterfaceForConstraint if2 = st2.getInterfaceForConstraint();
+
+
+ // 1. Prüfe Gleichheit des Namens
+ // Todo .... Name ist noch Objekt TypeVar
+ if (if1.getStrucType().toString().equals(if2.getStrucType().toString())) {
+
+ // Prüfe ob die Listen gleich lange sind
+ if (if1.getGenerics().size() == if2.getGenerics().size()) {
+
+ // Erstelle neue Constraints
+ for (int i = 0 ; i < if1.getGenerics().size() ; i++) {
+ TypeVarAbstract tnX = if1.getGenerics().get(i);
+ TypeVarAbstract tnY = if2.getGenerics().get(i);
+
+ // Ergebnis an ConstraintList
+ constraints.add(new ConstraintShouldEqual(tnX,tnY));
+ }
+ // Lösche element
+ constraints.remove(cs);
+ return;
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+
+ public void adapt1 (List constraints) {
+ for (ConstraintAbstract cs : constraints) {
+ if (cs instanceof ConstraintSubType) {
+ ConstraintSubType csub = (ConstraintSubType) cs;
+ ConstraintInterface cinterface = sucheInterface( csub.getSubtype() , csub.getSuperType() );
+ if (cinterface != null) {
+ ConstraintShouldEqual constraintShouldEqual = new ConstraintShouldEqual(cinterface.getSuperType() , csub.getSuperType());
+ constraints.remove(cs);
+ constraints.add(constraintShouldEqual);
+ // Todo Substitution für Types
+ return;
+ }
+ }
+ }
+ }
+
+
+ private ConstraintInterface sucheInterface( TypeVarAbstract tvSub , TypeVarAbstract tvSuper ) {
+
+ for (ConstraintInterface cs : constraintInterfaces) {
+ if ( cs.getSubType().equalsForUnify(tvSub) && cs.getSuperType().equalsForUnify(tvSuper) ) {
+ return cs;
+ }
+ }
+ return null;
+ }
+
+
+
+
+ public void adapt2(List constraints) {
+
+ List newConstraints = new ArrayList<>();
+
+ for (ConstraintAbstract cs : constraints) {
+
+ // Start
+ if (cs instanceof ConstraintSubType) {
+ ConstraintSubType css = (ConstraintSubType) cs;
+ if (css.getSuperType() instanceof TypeVar) {
+ if (css.getSubtype() instanceof TypeVarInterface || css.getSubtype() instanceof TypeVarRefType) {
+ adapt2Next(((ConstraintSubType) cs).getSubtype(), ((ConstraintSubType) cs).getSuperType() , constraints, newConstraints);
+ }
+ }
+ }
+ }
+ constraints.addAll(newConstraints);
+ }
+
+
+ public void adapt2Next(TypeVarAbstract start , TypeVarAbstract last , List remainingConstraints, List newConstraints) {
+
+ for (ConstraintAbstract cs : remainingConstraints) {
+
+
+
+ if (cs instanceof ConstraintSubType) {
+ ConstraintSubType css = (ConstraintSubType) cs;
+ if (css.getSubtype().equals(last)) {
+
+ // Next ist irgendein Interface
+ if (css.getSuperType() instanceof TypeVarInterface) {
+
+ // Next ist gesuchtes Inteface
+ ConstraintInterface constraintInterface = sucheInterface(start, css.getSuperType());
+ if (constraintInterface != null) {
+ System.out.println("adapt2Next : gefunden");
+ System.out.println(constraintInterface);
+
+
+ // Should Equal ermitteln
+ if (constraintInterface.getSuperType() instanceof TypeVarInterface) {
+ TypeVarInterface iFGiven = (TypeVarInterface) constraintInterface.getSuperType();
+ TypeVarInterface iFthis = (TypeVarInterface) css.getSuperType();
+
+ List iFGivenGenerics = iFGiven.getInterfaceForConstraint().getGenerics();
+ List iFthisGenerics = iFthis.getInterfaceForConstraint().getGenerics();
+
+ if (iFGivenGenerics.size() == iFthisGenerics.size()) {
+ for (int i = 0 ; i < iFGivenGenerics.size() ; i++ ) {
+ newConstraints.add(new ConstraintShouldEqual(iFGivenGenerics.get(i) , iFthisGenerics.get(i)));
+ }
+ }
+ }
+ return;
+ }
+
+ }
+ else if (css.getSuperType() instanceof TypeVar) {
+ List remConst2 = new ArrayList<>();
+ remConst2.addAll(remainingConstraints);
+ remConst2.remove(cs);
+ adapt2Next(start,css.getSuperType() , remConst2 , newConstraints);
+ }
+ }
+ }
+ }
}
@@ -86,4 +348,24 @@ public class Rules {
+
+
+ // Getter und Setter
+
+
+ public List getConstraintInterfaces() {
+ return constraintInterfaces;
+ }
+
+ public void setConstraintInterfaces(List constraintInterfaces) {
+ this.constraintInterfaces = constraintInterfaces;
+ }
+
+ public List getSubstitutions() {
+ return substitutions;
+ }
+
+ public void setSubstitutions(List substitutions) {
+ this.substitutions = substitutions;
+ }
}
diff --git a/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarAbstract.java b/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarAbstract.java
index 880e824b..a9936383 100644
--- a/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarAbstract.java
+++ b/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarAbstract.java
@@ -5,7 +5,13 @@ package de.dhbwstuttgart.strucTypes5.typeVars;
*/
public abstract class TypeVarAbstract {
-
-
+ public boolean equalsForUnify(TypeVarAbstract tv) {
+ if (tv.equals(this)) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
}
diff --git a/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarFactory.java b/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarFactory.java
index 360fcb53..65efbe1a 100644
--- a/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarFactory.java
+++ b/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarFactory.java
@@ -18,11 +18,11 @@ public class TypeVarFactory {
return new TypeVar(zaehler.toString());
}
- public static TypeVarAbstract makeTypeVar(InterfaceForConstraint ifc) {
+ public static TypeVarInterface makeTypeVar(InterfaceForConstraint ifc) {
return new TypeVarInterface(ifc);
}
- public static TypeVarAbstract makeTypeVar(RefTypeOrTPHOrWildcardOrGeneric refType) {
+ public static TypeVarRefType makeTypeVar(RefTypeOrTPHOrWildcardOrGeneric refType) {
if (refType instanceof RefType) {
RefType refType2 = (RefType) refType;
return new TypeVarRefType(refType2);
diff --git a/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarInterface.java b/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarInterface.java
index 437d3f4a..db282514 100644
--- a/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarInterface.java
+++ b/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarInterface.java
@@ -24,6 +24,9 @@ public class TypeVarInterface extends TypeVarAbstract {
}
+
+
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -35,6 +38,29 @@ public class TypeVarInterface extends TypeVarAbstract {
}
+
+ // Equal_for_Unify
+ public boolean equalsForUnify(TypeVarAbstract tv) {
+
+ if (tv instanceof TypeVarInterface) {
+ String name = ((TypeVarInterface) tv).getInterfaceForConstraint().getStrucType().toString();
+ String name2 = getInterfaceForConstraint().getStrucType().toString();
+ if (name.equals(name2)) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ return false;
+ }
+
+
+
+
+
+
@Override
public String toString() {
return String.format("TVar_%s" , interfaceForConstraint.toString());
diff --git a/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarType.java b/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarType.java
index 0e14ec77..32293331 100644
--- a/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarType.java
+++ b/src/de/dhbwstuttgart/strucTypes5/typeVars/TypeVarType.java
@@ -34,6 +34,7 @@ public class TypeVarType extends TypeVarAbstract {
+
@Override
public boolean equals(Object obj) {
if (obj.getClass().equals(TypeVarType.class)) {
diff --git a/test/strucTypes5/NewOperatorTest2.java b/test/strucTypes5/NewOperatorTest2.java
index 8f62c3e3..b3a1b93d 100644
--- a/test/strucTypes5/NewOperatorTest2.java
+++ b/test/strucTypes5/NewOperatorTest2.java
@@ -60,6 +60,10 @@ public class NewOperatorTest2 {
+
+
+
+
}
} catch (Exception exc) {
diff --git a/test/strucTypes5/SolveTest.jav b/test/strucTypes5/SolveTest.jav
new file mode 100644
index 00000000..57b0d741
--- /dev/null
+++ b/test/strucTypes5/SolveTest.jav
@@ -0,0 +1,20 @@
+
+
+
+class Main {
+main () { return new A().mt( new MyInteger() , new MyInteger() , new MyInteger() ); }
+}
+
+
+class A{
+mt(x,y,z) { return x.sub(y).add(z); }
+}
+
+
+class MyInteger {
+
+}
+
+
+
+
diff --git a/test/strucTypes5/SolveTest.java b/test/strucTypes5/SolveTest.java
new file mode 100644
index 00000000..a36af03c
--- /dev/null
+++ b/test/strucTypes5/SolveTest.java
@@ -0,0 +1,73 @@
+package strucTypes5;
+
+import de.dhbwstuttgart.parser.JavaTXParser;
+import de.dhbwstuttgart.strucTypes5.algo.TI;
+import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap;
+import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
+import de.dhbwstuttgart.syntaxtree.SourceFile;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der
+ * dabei erstellte Syntaxbaum wird nicht kontrolliert.
+ *
+ * @author janulrich
+ *
+ */
+public class SolveTest {
+ private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/";
+
+ @Test
+ public void run() {
+
+
+ List filenames = new ArrayList();
+ filenames.add("SolveTest.jav");
+
+ JavaTXParser parser = new JavaTXParser();
+ try {
+ for (String filename : filenames) {
+
+ System.out.println("Teste: " + filename);
+
+ SourceFile sf = parser.parse(new File(rootDirectory + filename));
+
+ SourceFile sfdebug = sf;
+
+ ClassOrInterface mainClass = sf.getClasses().get(0);
+ ClassOrInterface aClass = sf.getClasses().get(1);
+
+
+ AssumptionMap assumptionMap = new AssumptionMap();
+
+ TI ti = new TI(assumptionMap, aClass);
+
+ TI ti1 = new TI(ti.assresult, mainClass);
+
+ // Take The Generatet Constraints from ti:
+ // Try To Solve
+
+
+
+
+
+
+
+
+
+ }
+
+ } catch (Exception exc) {
+ exc.printStackTrace();
+ fail();
+ }
+ assertTrue("Tests durchlaufen", filenames.size() > 0);
+ }
+}
diff --git a/test/strucTypes5/SolveTest_Dev.java b/test/strucTypes5/SolveTest_Dev.java
new file mode 100644
index 00000000..f11bc688
--- /dev/null
+++ b/test/strucTypes5/SolveTest_Dev.java
@@ -0,0 +1,331 @@
+package strucTypes5;
+
+import de.dhbwstuttgart.parser.NullToken;
+import de.dhbwstuttgart.strucTypes5.constraints.*;
+import de.dhbwstuttgart.strucTypes5.solve.Rules;
+import de.dhbwstuttgart.strucTypes5.typeVars.*;
+import de.dhbwstuttgart.syntaxtree.type.RefType;
+import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
+import de.dhbwstuttgart.typecheck.JavaClassName;
+import de.dhbwstuttgart.typeinference.constraints.Constraint;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ For Develop the solve Funktion
+ */
+public class SolveTest_Dev {
+ private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/";
+
+
+ RefType myInteger;
+
+ @Test
+ public void run() {
+
+ // Initialisiere den gleichen RefType
+ List list = new ArrayList<>();
+ myInteger = new RefType(new JavaClassName("MyInteger"),list, new NullToken());
+
+
+ TypeVarRefType typeVarRefType1 = TypeVarFactory.makeTypeVar(myInteger);
+ TypeVarRefType typeVarRefType2 = TypeVarFactory.makeTypeVar(myInteger);
+
+ System.out.println(typeVarRefType1.equals(typeVarRefType2));
+
+
+
+
+ System.out.println("Starte Test der Regeln");
+
+ /*
+ Wie soll das Funktionieren
+ - klein sigma ist der Unifikator
+ - Rules ist solange anzuwenden bis alles unifiziert oder oder keine Regel mehr angewendet werden kann.
+ -
+ */
+
+ // Erstellen Beispiel:
+
+
+ testSwap();
+
+ testErase1();
+
+ testErase2();
+
+ testSubstition();
+
+ reflectTest();
+
+ reduceEqualTest();
+
+ adapt1Test();
+
+ adapt2Test();
+
+ }
+
+
+
+
+
+
+ public void testSwap() {
+
+ System.out.println("Teste Swap");
+ TypeVarRefType typeVarRefType = TypeVarFactory.makeTypeVar(myInteger);
+ TypeVar typeVar = TypeVarFactory.makeTypeVar();
+
+ List constraints = new ArrayList<>();
+ ConstraintShouldEqual cs = new ConstraintShouldEqual(typeVarRefType,typeVar);
+
+ constraints.add(cs);
+
+ System.out.println(constraints);
+ Rules rules = new Rules();
+ rules.swap(constraints);
+ System.out.println(constraints);
+ }
+
+
+ // Subtype Relation
+ public void testErase1() {
+ System.out.println("Test Erase 1 ");
+ TypeVarRefType typeVarRefType1 = TypeVarFactory.makeTypeVar(myInteger);
+ TypeVarRefType typeVarRefType2 = TypeVarFactory.makeTypeVar(myInteger);
+ ConstraintSubType constraintSubType = new ConstraintSubType(typeVarRefType1,typeVarRefType2);
+
+ List constraints = new ArrayList<>();
+ constraints.add(constraintSubType);
+ System.out.println(constraints);
+
+ Rules rules = new Rules();
+ rules.erase1(constraints);
+
+ System.out.println(constraints);
+ }
+
+
+ // Erase SchouldEqual
+ public void testErase2() {
+ System.out.println("Test Erase 2 ");
+ TypeVarRefType typeVarRefType1 = TypeVarFactory.makeTypeVar(myInteger);
+ TypeVarRefType typeVarRefType2 = TypeVarFactory.makeTypeVar(myInteger);
+ ConstraintShouldEqual constraintShouldEqual = new ConstraintShouldEqual(typeVarRefType1,typeVarRefType2);
+
+ List constraints = new ArrayList<>();
+ constraints.add(constraintShouldEqual);
+ System.out.println(constraints);
+
+ Rules rules = new Rules();
+ rules.erase2(constraints);
+
+ System.out.println(constraints);
+ }
+
+
+ public void testSubstition() {
+ System.out.println("Test Substitions ");
+ TypeVar typeVar = TypeVarFactory.makeTypeVar();
+ TypeVarRefType typeVarRefType = TypeVarFactory.makeTypeVar(myInteger);
+ ConstraintShouldEqual constraintShouldEqual = new ConstraintShouldEqual(typeVar,typeVarRefType);
+
+ List constraints = new ArrayList<>();
+ constraints.add(constraintShouldEqual);
+ System.out.println(constraints);
+
+ Rules rules = new Rules();
+ rules.subst(constraints);
+ System.out.println(rules.substitutions);
+
+ System.out.println(constraints);
+ }
+
+
+ public void reflectTest() {
+ System.out.println("Reflect Test");
+ TypeVarRefType t1 = TypeVarFactory.makeTypeVar(myInteger);
+ TypeVar t2 = TypeVarFactory.makeTypeVar();
+ TypeVar t3 = TypeVarFactory.makeTypeVar();
+ TypeVarRefType t4 = TypeVarFactory.makeTypeVar(myInteger);
+
+ ConstraintSubType csub1 = new ConstraintSubType(t1,t2);
+ ConstraintSubType csub2 = new ConstraintSubType(t2,t3);
+ ConstraintSubType csub3 = new ConstraintSubType(t3,t4);
+
+ List constraints = new ArrayList<>();
+ //constraints.add(csub2);
+ constraints.add(csub1);
+ constraints.add(csub3);
+
+ System.out.println(constraints);
+
+ Rules rules = new Rules();
+ rules.reflect(constraints);
+
+ System.out.println(constraints);
+ System.out.println(rules.substitutions);
+ }
+
+
+
+
+ public void reduceEqualTest() {
+ System.out.println("ReduceEqualTest");
+
+ // Gemeinsamer SrucType
+ TypeVar t1 = TypeVarFactory.makeTypeVar();
+
+ // Erstelle Interface 1
+ List genericsA = new ArrayList<>();
+ TypeVar t2 = TypeVarFactory.makeTypeVar();
+ TypeVar t3 = TypeVarFactory.makeTypeVar();
+ genericsA.add(t3);
+ genericsA.add(t2);
+ InterfaceForConstraint if1 = new InterfaceForConstraint(t1,genericsA);
+
+
+ // Erstelle Interface 2
+ List genericsB = new ArrayList<>();
+ TypeVarRefType refType1 = TypeVarFactory.makeTypeVar(myInteger);
+ TypeVarRefType refType2 = TypeVarFactory.makeTypeVar(myInteger);
+ genericsB.add(refType1);
+ genericsB.add(refType2);
+ InterfaceForConstraint if2 = new InterfaceForConstraint(t1,genericsB);
+
+
+ List constraints = new ArrayList<>();
+
+ constraints.add(new ConstraintShouldEqual(TypeVarFactory.makeTypeVar(if2) , TypeVarFactory.makeTypeVar(if1)));
+ System.out.println(constraints);
+
+ Rules rules = new Rules();
+ rules.reduceEqual(constraints);
+ System.out.println(constraints);
+ }
+
+
+
+ public void adapt1Test() {
+ System.out.println("Adapt1 Test");
+
+ // gemeinsamer Typ
+ TypeVarAbstract t1 = TypeVarFactory.makeTypeVar();
+
+ // implements Interface myInteger implements Interface
+ List generics = new ArrayList<>();
+ generics.add(TypeVarFactory.makeTypeVar(myInteger));
+ generics.add(TypeVarFactory.makeTypeVar(myInteger));
+ InterfaceForConstraint if1 = new InterfaceForConstraint(t1, generics);
+ ConstraintInterface constraintInterface = new ConstraintInterface(TypeVarFactory.makeTypeVar(myInteger) , TypeVarFactory.makeTypeVar(if1) );
+ List interfaces = new ArrayList<>();
+ interfaces.add(constraintInterface);
+
+ // Erstelle zu testenden Constraint
+ List genericsA = new ArrayList<>();
+ TypeVar t2 = TypeVarFactory.makeTypeVar();
+ TypeVar t3 = TypeVarFactory.makeTypeVar();
+ genericsA.add(t3);
+ genericsA.add(t2);
+ InterfaceForConstraint if2 = new InterfaceForConstraint(t1,genericsA);
+
+
+ ConstraintSubType constraintSubType = new ConstraintSubType(TypeVarFactory.makeTypeVar(myInteger) , TypeVarFactory.makeTypeVar(if2));
+ List constraints = new ArrayList<>();
+ constraints.add(constraintSubType);
+
+
+ System.out.println("Implemented Interfaces: " + interfaces);
+
+ System.out.println("ConstraintSet: " + constraints);
+
+ Rules rules = new Rules();
+ rules.setConstraintInterfaces(interfaces);
+
+ rules.adapt1(constraints);
+ System.out.println("Neue Constraints: " + constraints);
+
+ rules.reduceEqual(constraints);
+ System.out.println(constraints);
+ }
+
+
+
+
+ public void adapt2Test() {
+ System.out.println("Adapt2 Test");
+
+ // gemeinsamer Typ
+ TypeVarAbstract t1 = TypeVarFactory.makeTypeVar();
+
+ // extend
+ TypeVarAbstract text1 = TypeVarFactory.makeTypeVar();
+ TypeVarAbstract text2 = TypeVarFactory.makeTypeVar();
+ ConstraintSubType csub = new ConstraintSubType(text1,text2);
+
+
+ // implements Interface myInteger implements Interface
+ List generics = new ArrayList<>();
+ generics.add(TypeVarFactory.makeTypeVar(myInteger));
+ generics.add(TypeVarFactory.makeTypeVar(myInteger));
+ InterfaceForConstraint if1 = new InterfaceForConstraint(t1, generics);
+ ConstraintInterface constraintInterface = new ConstraintInterface(TypeVarFactory.makeTypeVar(myInteger) , TypeVarFactory.makeTypeVar(if1) );
+ List interfaces = new ArrayList<>();
+ interfaces.add(constraintInterface);
+
+ // Erstelle zu testenden Constraint
+ List genericsA = new ArrayList<>();
+ TypeVar t2 = TypeVarFactory.makeTypeVar();
+ TypeVar t3 = TypeVarFactory.makeTypeVar();
+ genericsA.add(t3);
+ genericsA.add(t2);
+ InterfaceForConstraint if2 = new InterfaceForConstraint(t1,genericsA);
+
+
+ ConstraintSubType constraintSubType = new ConstraintSubType(TypeVarFactory.makeTypeVar(myInteger) , text1);
+ ConstraintSubType constraintSubType1 = new ConstraintSubType(text2 , TypeVarFactory.makeTypeVar(if2));
+ List constraints = new ArrayList<>();
+ constraints.add(constraintSubType);
+ constraints.add(constraintSubType1);
+ constraints.add(csub);
+
+
+ System.out.println("Implemented Interfaces: " + interfaces);
+
+ System.out.println("ConstraintSet: " + constraints);
+
+ Rules rules = new Rules();
+ rules.setConstraintInterfaces(interfaces);
+
+ rules.adapt2(constraints);
+ System.out.println("Neue Constraints: " + constraints);
+
+ //rules.reduceEqual(constraints);
+ //System.out.println(constraints);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}