diff --git a/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java b/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java index 9d7a2c47..a2815455 100755 --- a/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java +++ b/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java @@ -115,7 +115,8 @@ public class TypeinferenceResultSet Vector ret = new Vector(); for(Pair p : constraints){ for(TypePlaceholder tph : p.getTypePlaceholder()){ - ret.add(tph.getTypeInsertPoints(this.unifiedConstraints)); + TypeInsertSet toAdd = tph.getTypeInsertPoints(this.unifiedConstraints); + if(!ret.contains(toAdd))ret.add(toAdd); } } return ret; diff --git a/src/typinferenz/ResultSet.java b/src/typinferenz/ResultSet.java index 274bf02d..ac4ab89d 100755 --- a/src/typinferenz/ResultSet.java +++ b/src/typinferenz/ResultSet.java @@ -71,4 +71,8 @@ public class ResultSet implements Iterable { return this.getResultSet().toString(); } + @Override + public boolean equals(Object obj){ + return true; + } } diff --git a/test/plugindevelopment/TRMEqualTest.java b/test/plugindevelopment/TRMEqualTest.java new file mode 100644 index 00000000..a847e8d3 --- /dev/null +++ b/test/plugindevelopment/TRMEqualTest.java @@ -0,0 +1,108 @@ +package plugindevelopment; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Vector; + +import org.junit.Test; + +import junit.framework.TestCase; +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.myparser.JavaParser.yyException; +import mycompiler.mytype.Pair; +import mycompiler.mytype.Pair.PairOperator; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.TypeinferenceResultSet; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import typinferenz.ResultSet; +import typinferenz.TypeInsertSet; +import typinferenz.TypeInsertable; + +public class TRMEqualTest { + Vector replaceSet = new Vector(); + TestNode node; + TypePlaceholder tph; + + + public void initTRMEqualTest(){ + node = new TestNode(); + tph = TypePlaceholder.fresh(node); + node.setType(tph); + } + + @Test + public void test(){ + initTRMEqualTest(); + assertTrue("Zu Beginn ist das Set leer",replaceSet.size()==0); + addTestNode("Typ1"); + assertTrue("Nach dem Anfügen eines Type muss das Set 1 Element enthalten",replaceSet.size()==1); + addTestNode("Typ2"); + assertTrue("Nach dem Anfügen eines weiteren Typs muss das Set 2 Elemente enthalten",replaceSet.size()==2); + addTestNode("Typ1"); + assertTrue("Nach dem Anfügen des selben Typs wie zuvor muss das Set immer noch 2 Element enthalten. Und nicht "+replaceSet.size(),replaceSet.size()==2); + } + private void addTestNode(String type){ + + Vector resultContent = new Vector(); + Pair pair = new Pair(tph,new RefType(type,0)); + pair.SetOperator(PairOperator.Equal); + resultContent.add(pair); + ResultSet resultSet = new ResultSet(resultContent); + TypeInsertSet toAdd = tph.getTypeInsertPoints(resultSet); + System.out.println("Füge hinzu: "+toAdd); + if(!replaceSet.contains(toAdd))replaceSet.add(toAdd); + } +} + +class TestNode implements TypeInsertable{ + + @Override + public void replaceType(CReplaceTypeEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public int getTypeLineNumber() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setType(Type typ) { + // TODO Auto-generated method stub + + } + + @Override + public Type getType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getOffset() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setOffset(int offset) { + // TODO Auto-generated method stub + + } + + @Override + public String getIdentifier() { + // TODO Auto-generated method stub + return null; + } + +} + diff --git a/test/plugindevelopment/TypeInsertTester.java b/test/plugindevelopment/TypeInsertTester.java index febaa105..7cb863b9 100644 --- a/test/plugindevelopment/TypeInsertTester.java +++ b/test/plugindevelopment/TypeInsertTester.java @@ -68,7 +68,7 @@ public class TypeInsertTester{ } //Source: https://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file - static String getFileContent(String path)throws IOException + public static String getFileContent(String path)throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(path)); return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString(); diff --git a/test/plugindevelopment/FunNInsertTest.jav b/test/plugindevelopment/TypeInsertTests/FunNInsertTest.jav similarity index 100% rename from test/plugindevelopment/FunNInsertTest.jav rename to test/plugindevelopment/TypeInsertTests/FunNInsertTest.jav diff --git a/test/plugindevelopment/FunNInsertTest.java b/test/plugindevelopment/TypeInsertTests/FunNInsertTest.java similarity index 89% rename from test/plugindevelopment/FunNInsertTest.java rename to test/plugindevelopment/TypeInsertTests/FunNInsertTest.java index bf6cabeb..161e4e80 100644 --- a/test/plugindevelopment/FunNInsertTest.java +++ b/test/plugindevelopment/TypeInsertTests/FunNInsertTest.java @@ -1,4 +1,4 @@ -package plugindevelopment; +package plugindevelopment.TypeInsertTests; import java.util.Vector; diff --git a/test/plugindevelopment/MultipleTypesInsertTester.java b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java similarity index 83% rename from test/plugindevelopment/MultipleTypesInsertTester.java rename to test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java index 818c955b..1861c5ec 100644 --- a/test/plugindevelopment/MultipleTypesInsertTester.java +++ b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java @@ -1,9 +1,10 @@ -package plugindevelopment; +package plugindevelopment.TypeInsertTests; import java.io.File; import java.io.IOException; import java.util.Vector; +import plugindevelopment.TypeInsertTester; import junit.framework.TestCase; import mycompiler.MyCompiler; import mycompiler.MyCompilerAPI; @@ -13,12 +14,14 @@ import typinferenz.TypeInsertSet; public class MultipleTypesInsertTester { + public final static String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/TypeInsertTests/"; + public static void test(String sourceFileToInfere, Vector mustContain){ String gesamterSrc = ""; String inferedSource = ""; MyCompilerAPI compiler = MyCompiler.getAPI(); try { - compiler.parse(new File(TypeInsertTester.rootDirectory + sourceFileToInfere)); + compiler.parse(new File(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){ @@ -27,7 +30,7 @@ public class MultipleTypesInsertTester { 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)); + inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(rootDirectory + sourceFileToInfere)); System.out.println(inferedSource); gesamterSrc += inferedSource; } diff --git a/test/plugindevelopment/TypeInsertTests/MutlitpleTestCases.java b/test/plugindevelopment/TypeInsertTests/MutlitpleTestCases.java new file mode 100644 index 00000000..5df8575a --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/MutlitpleTestCases.java @@ -0,0 +1,18 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class MutlitpleTestCases { + + private static final String TEST_FILE = "Test1.jav"; + + @Test + public void test1(){ + Vector mustContain = new Vector(); + mustContain.add("OverloadingTest testMethode"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } + +} diff --git a/test/plugindevelopment/OverloadingInsertTest.jav b/test/plugindevelopment/TypeInsertTests/OverloadingInsertTest.jav similarity index 100% rename from test/plugindevelopment/OverloadingInsertTest.jav rename to test/plugindevelopment/TypeInsertTests/OverloadingInsertTest.jav diff --git a/test/plugindevelopment/OverloadingInsertTest.java b/test/plugindevelopment/TypeInsertTests/OverloadingInsertTest.java similarity index 95% rename from test/plugindevelopment/OverloadingInsertTest.java rename to test/plugindevelopment/TypeInsertTests/OverloadingInsertTest.java index 845d9f3b..1347e703 100644 --- a/test/plugindevelopment/OverloadingInsertTest.java +++ b/test/plugindevelopment/TypeInsertTests/OverloadingInsertTest.java @@ -1,4 +1,4 @@ -package plugindevelopment; +package plugindevelopment.TypeInsertTests; import java.io.File; import java.io.IOException; diff --git a/test/plugindevelopment/TypeInsertTests/Test1.jav b/test/plugindevelopment/TypeInsertTests/Test1.jav new file mode 100644 index 00000000..4f7f5661 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/Test1.jav @@ -0,0 +1,25 @@ +class OverloadingTest{ + + OverloadingTest var; + + + clone(){ + return this; + } + + testMethode(var2){ + var.clone(); + return var.clone(); + } + +} + +class OverloadingTest2{ + + String var = "test"; + + OverloadingTest2 clone(){ + return this; + } + +} \ No newline at end of file