From 7defd01db88e55133e74e981ef29384b50c89144 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 19 Mar 2014 15:14:50 +0100 Subject: [PATCH] =?UTF-8?q?=C3=84nderungen=20an=20typeReconstruction=20in?= =?UTF-8?q?=20SourceFile.=20Die=20Constraints=20aller=20Klassen=20einer=20?= =?UTF-8?q?SourceFile=20werden=20nun=20gemeinsam=20Unifiziert=20und=20jede?= =?UTF-8?q?=20Klasse=20aus=20dem=20SourceFile=20erh=C3=A4lt=20das=20selbe?= =?UTF-8?q?=20ResultSet.=20Tests=20angef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mycompiler/SourceFile.java | 165 +++++++++--------- src/mycompiler/myclass/Class.java | 18 +- src/mycompiler/myclass/Constructor.java | 48 +++++ src/mycompiler/myclass/Method.java | 9 + src/mycompiler/mytype/TypePlaceholder.java | 11 ++ .../TypeinferenceResultSet.java | 2 +- .../assumptions/MethodAssumption.java | 12 ++ .../assumptions/TypeAssumptions.java | 15 +- .../test/lambda/testResults/LambdaTest.log | 115 ++++++++++-- test/plugindevelopment/FunNInsertTest.jav | 12 ++ test/plugindevelopment/FunNInsertTest.java | 18 ++ .../MultipleTypesInsertTester.java | 46 +++++ .../OverloadingInsertTest.java | 33 +--- 13 files changed, 369 insertions(+), 135 deletions(-) create mode 100644 test/plugindevelopment/FunNInsertTest.jav create mode 100644 test/plugindevelopment/FunNInsertTest.java create mode 100644 test/plugindevelopment/MultipleTypesInsertTester.java diff --git a/src/mycompiler/SourceFile.java b/src/mycompiler/SourceFile.java index 41bdf506..49ac32c7 100755 --- a/src/mycompiler/SourceFile.java +++ b/src/mycompiler/SourceFile.java @@ -646,89 +646,96 @@ public class SourceFile globalAssumptions.add(klasse.getPublicFieldAssumptions()); } + ConstraintsSet oderConstraints = new ConstraintsSet(); //Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln: for(Class klasse : KlassenVektor){ - ConstraintsSet oderConstraints = klasse.typeReconstruction(finiteClosure, globalAssumptions); - - //Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden): - Vector> xConstraints = new Vector>();// = oderConstraints.getConstraints(); - for(Vector uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt. - Vector cons = new Vector(); - for(UndConstraint undCons:uC){ - cons.addAll(undCons.getConstraintPairs()); - } - xConstraints.add(cons); - } - typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints); - - ////////////////////////////// - // Unifizierung der Constraints: - ////////////////////////////// - for(Vector constraints : xConstraints){ - //Alle durch das Karthesische Produkt entstandenen Möglichkeiten durchgehen: - Vector> result = new Vector>(); - - //Alle FunN-Typen werden per clone-methode in RefTypes verwandelt. (Die clone Methode in FunN darf nicht überschrieben werden. - for(Pair p : constraints){ - if(p.TA1 instanceof FunN){ - p.TA1 = p.TA1.clone(); - } - if(p.TA2 instanceof FunN){ - p.TA2 = p.TA2.clone(); - } - } - - //Erst die Unifizierung erstellen: - Vector constraintsClone = (Vector)constraints.clone(); - Vector> unifyResult = Unify.unify(constraintsClone, finiteClosure); - //Dann den Ergebnissen anfügen - result.addAll(unifyResult); - - // Debugoutput:Vector> - typinferenzLog.debug("Unifiziertes Ergebnis: "+result); - - /* - // Prüfe ob eindeutige Lösung: - if(result.size()>1 && !Unify.hasSolvedForm(result.elementAt(0))){ - - typinferenzLog.debug("Keine eindeutige Lösung!"); - - }else if(result.size()>1){ - - //Replace TPH: - for(Pair res : result.elementAt(0)){ - if(res.OperatorEqual()){ - if(res.TA1 instanceof TypePlaceholder)((TypePlaceholder)res.TA1).fireReplaceTypeEvent(new CReplaceTypeEvent(res.TA1, res.TA2)); - } - } - } - */ - //typinferenzLog.debug(); - //typinferenzLog.debug(supportData.getFiniteClosure()); - //typinferenzLog.debug("Typinformationen: \n"+this.getTypeInformation(this.getMethodList(), fieldInitializers)); - - typinferenzLog.debug("\nJavaFiles:\n"); - - //typinferenzLog.debug(this.printJavaCode(new ResultSet(new Vector()))); - - - //Der Unifikationsalgorithmus kann wiederum auch mehrere Lösungen errechnen, diese werden im folgenden durchlaufen: - for(Vector resultSet : result){ - //Add Result set as a new ReconstructionResult to ret: - TypeinferenceResultSet reconstructionResult = new TypeinferenceResultSet(klasse, constraints, new ResultSet(resultSet)); - ret.add(reconstructionResult); - - //ResultSet res = new ResultSet(resultSet); - typinferenzLog.debug("JavaFile für ResultSet "+reconstructionResult+"\n"); - typinferenzLog.debug(klasse.printJavaCode(reconstructionResult)); - - } - - } - - + oderConstraints.add(klasse.typeReconstruction(finiteClosure, globalAssumptions)); } + //////////////// + //Karthesisches Produkt bilden: + //////////////// + //Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden): + Vector> xConstraints = new Vector>();// = oderConstraints.getConstraints(); + for(Vector uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt. + Vector cons = new Vector(); + for(UndConstraint undCons:uC){ + cons.addAll(undCons.getConstraintPairs()); + } + xConstraints.add(cons); + } + typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints); + + ////////////////////////////// + // Unifizierung der Constraints: + ////////////////////////////// + for(Vector constraints : xConstraints){ + //Alle durch das Karthesische Produkt entstandenen Möglichkeiten durchgehen: + Vector> result = new Vector>(); + + //Alle FunN-Typen werden per clone-methode in RefTypes verwandelt. (Die clone Methode in FunN darf nicht überschrieben werden. + for(Pair p : constraints){ + if(p.TA1 instanceof FunN){ + p.TA1 = p.TA1.clone(); + } + if(p.TA2 instanceof FunN){ + p.TA2 = p.TA2.clone(); + } + } + + //Erst die Unifizierung erstellen: + Vector constraintsClone = (Vector)constraints.clone(); + Vector> unifyResult = Unify.unify(constraintsClone, finiteClosure); + //Dann den Ergebnissen anfügen + result.addAll(unifyResult); + + // Debugoutput:Vector> + typinferenzLog.debug("Unifiziertes Ergebnis: "+result); + + /* + // Prüfe ob eindeutige Lösung: + if(result.size()>1 && !Unify.hasSolvedForm(result.elementAt(0))){ + + typinferenzLog.debug("Keine eindeutige Lösung!"); + + }else if(result.size()>1){ + + //Replace TPH: + for(Pair res : result.elementAt(0)){ + if(res.OperatorEqual()){ + if(res.TA1 instanceof TypePlaceholder)((TypePlaceholder)res.TA1).fireReplaceTypeEvent(new CReplaceTypeEvent(res.TA1, res.TA2)); + } + } + } + */ + //typinferenzLog.debug(); + //typinferenzLog.debug(supportData.getFiniteClosure()); + //typinferenzLog.debug("Typinformationen: \n"+this.getTypeInformation(this.getMethodList(), fieldInitializers)); + + typinferenzLog.debug("\nJavaFiles:\n"); + + //typinferenzLog.debug(this.printJavaCode(new ResultSet(new Vector()))); + + + //Für jede Klasse in diesem SourceFile gilt das selbe ResultSet: + for(Class klasse : this.KlassenVektor){ + //Der Unifikationsalgorithmus kann wiederum auch mehrere Lösungen errechnen, diese werden im folgenden durchlaufen: + for(Vector resultSet : result){ + //Add Result set as a new ReconstructionResult to ret: + TypeinferenceResultSet reconstructionResult = new TypeinferenceResultSet(klasse, constraints, new ResultSet(resultSet)); + ret.add(reconstructionResult); + + //ResultSet res = new ResultSet(resultSet); + typinferenzLog.debug("JavaFile für ResultSet "+reconstructionResult+"\n"); + typinferenzLog.debug(klasse.printJavaCode(reconstructionResult)); + + } + } + + + } + + return ret; /* // HOTI: Nur zur Info.Ich habe den Loglevel auf Info geschaltet, damit diff --git a/src/mycompiler/myclass/Class.java b/src/mycompiler/myclass/Class.java index ac2c923d..b6d49252 100755 --- a/src/mycompiler/myclass/Class.java +++ b/src/mycompiler/myclass/Class.java @@ -630,10 +630,11 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface // @author A10023 - Andreas Stadelmeier: ////////////////////////////// //Erzeuge Assumptions: - TypeAssumptions assumptions = this.getTypeAssumptions(); - //-- + TypeAssumptions assumptions = this.getPrivateFieldAssumptions(); + //Globale Assumptions anfügen: assumptions.add(globalAssumptions); - + + typinferenzLog.debug("Erstellte Assumptions: "+assumptions); /* //Generiere Liste mit Expressions, welche zur Initialisierung von Feldern verwendet werden. Vector fieldInitializers = new Vector(); @@ -816,11 +817,11 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface */ /** - * Die Funktion ist erst nach dem Aufruf von getMethodList() nutzbar. - * Ermittelt alle Felder und Methoden der Klasse und Erstellt eine Assumption für diese. + * Ermittelt alle privaten Felder und Methoden der Klasse und Erstellt eine Assumption für diese. + * Bemerkung: Momentan werden noch alle Felder dieser Klasse zurückgegeben. * @return Die erstellten TypeAssumptions */ - private TypeAssumptions getTypeAssumptions() { + private TypeAssumptions getPrivateFieldAssumptions() { if(this.typeAssumptions != null)return this.typeAssumptions; //Das sorgt dafür, dass die Assumptions nur einmalig generiert werden. TypeAssumptions assumptions = new TypeAssumptions(this.getName()); //this.getMethodList(); //Diese Funktion muss zuerst ausgeführt werden. @@ -839,9 +840,6 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface // assumptions.addMethodAssumption(new RefType(this.getName(),0), "", new RefType(this.getName(),0), new Vector()); //} - - typinferenzLog.debug("Erstellte Assumptions: "+assumptions); - this.typeAssumptions = assumptions; //Diese müssen anschließend nicht wieder generiert werden. return assumptions; } @@ -1247,7 +1245,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface * @return */ public TypeAssumptions getPublicFieldAssumptions() { - TypeAssumptions ret = this.getTypeAssumptions(); + TypeAssumptions ret = this.getPrivateFieldAssumptions(); for(Field f : this.getFields()){ ret.add(f.createTypeAssumptions(this)); } diff --git a/src/mycompiler/myclass/Constructor.java b/src/mycompiler/myclass/Constructor.java index 543e813d..b7c3d789 100644 --- a/src/mycompiler/myclass/Constructor.java +++ b/src/mycompiler/myclass/Constructor.java @@ -273,6 +273,54 @@ public class Constructor extends Method { public Type getType() { return this.methode.getType(); } + + + @Override + public boolean equals(Object obj) { + return this.methode.equals(obj); + } + + + @Override + public void set_DeclId(DeclId did) { + this.methode.set_DeclId(did); + } + + + @Override + public Vector get_Name() { + return this.methode.get_Name(); + } + + + @Override + public Vector getDeclIdVector() { + return this.methode.getDeclIdVector(); + } + + + @Override + public void setDeclIdVector(Vector vDeclId) { + this.methode.setDeclIdVector(vDeclId); + } + + + @Override + public String getIdentifier() { + return this.methode.getIdentifier(); + } + + + @Override + public String getDescription() { + return this.methode.getDescription(); + } + + + @Override + public Class getParentClass() { + return this.methode.getParentClass(); + } } diff --git a/src/mycompiler/myclass/Method.java b/src/mycompiler/myclass/Method.java index f770a066..7fa63b75 100755 --- a/src/mycompiler/myclass/Method.java +++ b/src/mycompiler/myclass/Method.java @@ -702,5 +702,14 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return ret; } + @Override + public boolean equals(Object obj){ + if(!(obj instanceof Method))return false; + Method equals = (Method) obj; + if(!this.returntype.equals(equals.returntype))return false; + if(!this.parameterlist.equals(equals.parameterlist))return false; + return super.equals(obj); + } + } // ino.end diff --git a/src/mycompiler/mytype/TypePlaceholder.java b/src/mycompiler/mytype/TypePlaceholder.java index c1ef7abd..e68c75ae 100755 --- a/src/mycompiler/mytype/TypePlaceholder.java +++ b/src/mycompiler/mytype/TypePlaceholder.java @@ -6,6 +6,7 @@ package mycompiler.mytype; import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; +import java.util.logging.Logger; import typinferenz.JavaCodeResult; import typinferenz.ResultSet; @@ -512,6 +513,16 @@ public class TypePlaceholder extends Type implements IReplaceTypeEventProvider return equalType.printJavaCode(resultSet); } + /** + * Berechnet die InsertPoints dieses TypePlaceholders. + * Alle an diesem TypePlaceholder registrierten ITypeReplacementListener werden darauf kontrolliert, + * ob sie von TypeInsertable erben. + * Diese ergeben zusammen mit den Informationen aus dem übergebenen ResultSet einen TypeInsertPoint. + * Mehrere TypeInsertPoint's ergeben ein TypeInsertSet. + * @param result Das ResultSet das den einzusetzenden Typ für diesen TPH enthält. + * @return + * @see TypeInsertPoint + */ public TypeInsertSet getTypeInsertPoints(ResultSet result) { TypeInsertSet ret = new TypeInsertSet(); for(ITypeReplacementListener ti : this.m_ReplacementListeners){ diff --git a/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java b/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java index a5b8b121..21b53ebe 100755 --- a/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java +++ b/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java @@ -29,7 +29,7 @@ import mycompiler.mytypereconstruction.typeassumptionkey.CTypeAssumptionKey; // ino.class.CTypeReconstructionResult.27238.description type=javadoc /** * Diese Container-Klasse kapselt alle Ergebniswerte f�r eine m�gliche - * Typkombination aller Klassen und deren Methoden sowie lokalen Variablen. Eine + * Typkombination einer Klasse und deren Methoden sowie lokalen Variablen. Eine * Instanz dieser Klasse steht f�r genau eine m�gliche Typkombination.
* Objekte dieser Klasse werden vom Typrekonstruktionsalgorithmus �ber die * Compiler-API zur�ckgegeben. diff --git a/src/typinferenz/assumptions/MethodAssumption.java b/src/typinferenz/assumptions/MethodAssumption.java index b1036cf4..e767b803 100644 --- a/src/typinferenz/assumptions/MethodAssumption.java +++ b/src/typinferenz/assumptions/MethodAssumption.java @@ -43,4 +43,16 @@ public class MethodAssumption extends FieldAssumption { return "MethodAssumption: "+this.method.toString(); } + @Override + public boolean equals(Object obj){ + if(!(obj instanceof MethodAssumption))return false; + MethodAssumption equals = (MethodAssumption)obj; + if(equals.method==null)return false; + if(equals.parentClass==null)return false; + if(!(equals.method.equals(this.method)))return false; + if(!(equals.parentClass.equals(this.parentClass)))return false; + + return true; + } + } diff --git a/src/typinferenz/assumptions/TypeAssumptions.java b/src/typinferenz/assumptions/TypeAssumptions.java index b718fa27..5ff0bf1b 100755 --- a/src/typinferenz/assumptions/TypeAssumptions.java +++ b/src/typinferenz/assumptions/TypeAssumptions.java @@ -68,7 +68,7 @@ public class TypeAssumptions { } public void addMethodAssumption(MethodAssumption mAss){ - this.methodAssumptions.add(mAss); + if(!this.methodAssumptions.contains(mAss))this.methodAssumptions.add(mAss); } public void addConstructorAssumption( @@ -93,12 +93,13 @@ public class TypeAssumptions { * @param withName * @return */ - public Vector getFieldVars(String withName){ + @Deprecated + public Vector getFieldVars2(String withName){ //TODO: Implementieren return new Vector(); } - - public Type getTypeOfFieldVar(String withName, Class inClass){ + @Deprecated + public Type getTypeOfFieldVar2(String withName, Class inClass){ //TODO: Implementieren return null; } @@ -108,7 +109,8 @@ public class TypeAssumptions { * @param withName * @return */ - public Vector getMethods(String withName){ + @Deprecated + public Vector getMethods2(String withName){ //TODO: Implementieren return new Vector(); } @@ -118,7 +120,8 @@ public class TypeAssumptions { * @param withName * @return */ - public Type getTypeOfLocalVar(String withName){ + @Deprecated + public Type getTypeOfLocalVar2(String withName){ //TODO: Implementieren return null; } diff --git a/test/mycompiler/test/lambda/testResults/LambdaTest.log b/test/mycompiler/test/lambda/testResults/LambdaTest.log index aff7b526..e7be789d 100644 --- a/test/mycompiler/test/lambda/testResults/LambdaTest.log +++ b/test/mycompiler/test/lambda/testResults/LambdaTest.log @@ -1,36 +1,123 @@ -Class DEBUG [Typeinference] Erstellte Assumptions: this: ThisTestMethod Assumptions: +Class DEBUG [Typeinference] Erstellte Assumptions: this: MatrixMethod Assumptions: [] FieldVar Assumptions: -[typinferenz.assumptions.FieldAssumption@6d657803] +[typinferenz.assumptions.FieldAssumption@193d22b1, typinferenz.assumptions.FieldAssumption@7cb09f68, typinferenz.assumptions.FieldAssumption@193d22b1, typinferenz.assumptions.FieldAssumption@7cb09f68] LocalVar Assumptions: [] Parameter Assumptions: [] -Class DEBUG [Typeinference] Erstellte Constraints: TPH A < TPH A -ThisTest < TPH A +Block DEBUG [Typeinference] Prozessing statement: null Return null (( [ f, ]) -> null { [null Return null (f.apply( [ null (this(null)), m, ]))]) +Block DEBUG [Typeinference] Prozessing statement: null Return null (f.apply( [ null (this(null)), m, ])) +Block DEBUG [Typeinference] Prozessing statement: TPH BW Return TPH BS (f: TPH BQ.apply( [ Matrix (this(null)), m: TPH BO, ])) +Block DEBUG [Typeinference] Prozessing statement: TPH BX Return TPH BR (( [ TPH BQ f, ]) -> TPH BW { [TPH BW Return TPH BS (f: TPH BQ.apply( [ Matrix (this(null)), m: TPH BO, ]))]) +Class DEBUG [Typeinference] Erstellte Constraints: TPH BM < TPH BM +[[(TPH BT <. TPH BS), (Matrix <. TPH BU), (TPH BO <. TPH BV), (TPH BQ <. FunN), ]| ] +TPH BS < TPH BW +Fun1< TPH BW, TPH BQ > < TPH BR +TPH BR < TPH BX +Fun1< TPH BX, TPH BO > < TPH BP +TPH BP < TPH BM -SourceFile DEBUG [Typeinference] Karthesisches Produkt der Constraints: [[(TPH A <. TPH A), (ThisTest <. TPH A)]] -SourceFile DEBUG [Typeinference] Unifiziertes Ergebnis: [[(TPH A = ThisTest)], [(TPH A = Object)]] +SourceFile DEBUG [Typeinference] Karthesisches Produkt der Constraints: [[(TPH BM <. TPH BM), (TPH BT <. TPH BS), (Matrix <. TPH BU), (TPH BO <. TPH BV), (TPH BQ <. FunN), (TPH BS <. TPH BW), (Fun1< TPH BW, TPH BQ > <. TPH BR), (TPH BR <. TPH BX), (Fun1< TPH BX, TPH BO > <. TPH BP), (TPH BP <. TPH BM)]] +SourceFile DEBUG [Typeinference] Unifiziertes Ergebnis: [[(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Matrix), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< ? super GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? super Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? super Matrix >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)]] SourceFile DEBUG [Typeinference] JavaFiles: -SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH A = ThisTest)] +SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Matrix), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)] -SourceFile DEBUG [Typeinference] class ThisTest extends Object +SourceFile DEBUG [Typeinference] class Matrix extends Vector> { -ThisTest thisVar = this; -ThisTest ThisTest() +Fun1, BO> op = (BO m) -> { +return (FunN f) -> { +return f.apply(this, m);; +}; +}; +Matrix Matrix() { } } -SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH A = Object)] +SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)] -SourceFile DEBUG [Typeinference] class ThisTest extends Object +SourceFile DEBUG [Typeinference] class Matrix extends Vector> { -Object thisVar = this; -ThisTest ThisTest() +Fun1, BO> op = (BO m) -> { +return (FunN f) -> { +return f.apply(this, m);; +}; +}; +Matrix Matrix() +{ +} +} + +SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)] + +SourceFile DEBUG [Typeinference] class Matrix extends Vector> +{ +Fun1, BO> op = (BO m) -> { +return (FunN f) -> { +return f.apply(this, m);; +}; +}; +Matrix Matrix() +{ +} +} + +SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)] + +SourceFile DEBUG [Typeinference] class Matrix extends Vector> +{ +Fun1, BO> op = (BO m) -> { +return (FunN f) -> { +return f.apply(this, m);; +}; +}; +Matrix Matrix() +{ +} +} + +SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< ? super GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)] + +SourceFile DEBUG [Typeinference] class Matrix extends Vector> +{ +Fun1, BO> op = (BO m) -> { +return (FunN f) -> { +return f.apply(this, m);; +}; +}; +Matrix Matrix() +{ +} +} + +SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? super Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)] + +SourceFile DEBUG [Typeinference] class Matrix extends Vector> +{ +Fun1, BO> op = (BO m) -> { +return (FunN f) -> { +return f.apply(this, m);; +}; +}; +Matrix Matrix() +{ +} +} + +SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? super Matrix >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)] + +SourceFile DEBUG [Typeinference] class Matrix extends Vector> +{ +Fun1, BO> op = (BO m) -> { +return (FunN f) -> { +return f.apply(this, m);; +}; +}; +Matrix Matrix() { } } diff --git a/test/plugindevelopment/FunNInsertTest.jav b/test/plugindevelopment/FunNInsertTest.jav new file mode 100644 index 00000000..1709ff2e --- /dev/null +++ b/test/plugindevelopment/FunNInsertTest.jav @@ -0,0 +1,12 @@ +class FunNInsertTest{ + + Object1 var1; + Object2 var2; + Object3 var3; + op = (a) -> (b) -> (c) -> { + var1 = a; + var2 = b; + var3 = c; + }; + +} \ No newline at end of file diff --git a/test/plugindevelopment/FunNInsertTest.java b/test/plugindevelopment/FunNInsertTest.java new file mode 100644 index 00000000..bf6cabeb --- /dev/null +++ b/test/plugindevelopment/FunNInsertTest.java @@ -0,0 +1,18 @@ +package plugindevelopment; + +import java.util.Vector; + +import org.junit.Test; + +public class FunNInsertTest { + + private static final String TEST_FILE = "FunNInsertTest.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("Fun1, Object2>, Object1> op"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } + +} diff --git a/test/plugindevelopment/MultipleTypesInsertTester.java b/test/plugindevelopment/MultipleTypesInsertTester.java new file mode 100644 index 00000000..818c955b --- /dev/null +++ b/test/plugindevelopment/MultipleTypesInsertTester.java @@ -0,0 +1,46 @@ +package plugindevelopment; + +import java.io.File; +import java.io.IOException; +import java.util.Vector; + +import junit.framework.TestCase; +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.myparser.JavaParser.yyException; +import mycompiler.mytypereconstruction.TypeinferenceResultSet; +import typinferenz.TypeInsertSet; + +public class MultipleTypesInsertTester { + + public static void test(String sourceFileToInfere, Vector mustContain){ + String gesamterSrc = ""; + String inferedSource = ""; + MyCompilerAPI compiler = MyCompiler.getAPI(); + try { + compiler.parse(new File(TypeInsertTester.rootDirectory + sourceFileToInfere)); + Vector results = compiler.typeReconstruction(); + //TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1); + for(TypeinferenceResultSet result : results){ + Vector points = result.getTypeInsertionPoints(); + //TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0); + for(TypeInsertSet point : points){ + //TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0); + if(point.points.size()>0){ + inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(TypeInsertTester.rootDirectory + sourceFileToInfere)); + System.out.println(inferedSource); + gesamterSrc += inferedSource; + } + } + } + + } catch (IOException | yyException e) { + e.printStackTrace(); + TestCase.fail(); + } + for(String containString : mustContain){ + TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString)); + } + } + +} diff --git a/test/plugindevelopment/OverloadingInsertTest.java b/test/plugindevelopment/OverloadingInsertTest.java index 49f99f3f..845d9f3b 100644 --- a/test/plugindevelopment/OverloadingInsertTest.java +++ b/test/plugindevelopment/OverloadingInsertTest.java @@ -19,32 +19,15 @@ public class OverloadingInsertTest { @Test public void run(){ - this.test(this.TEST_FILE); + Vector mustContain = new Vector(); + mustContain.add("Overloading2 methode"); + mustContain.add("Overloading2 overload"); + mustContain.add("Overloading2 var2"); + mustContain.add("OverloadingInsertTest methode"); + mustContain.add("OverloadingInsertTest overload"); + mustContain.add("OverloadingInsertTest var2"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); } - public static void test(String sourceFileToInfere){ - String inferedSource = ""; - MyCompilerAPI compiler = MyCompiler.getAPI(); - try { - compiler.parse(new File(TypeInsertTester.rootDirectory + sourceFileToInfere)); - Vector results = compiler.typeReconstruction(); - //TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1); - for(TypeinferenceResultSet result : results){ - Vector points = result.getTypeInsertionPoints(); - TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0); - for(TypeInsertSet point : points){ - TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0); - if(point.points.size()>0){ - inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(TypeInsertTester.rootDirectory + sourceFileToInfere)); - System.out.println(inferedSource); - } - } - } - - } catch (IOException | yyException e) { - e.printStackTrace(); - TestCase.fail(); - } - } }