TypeInsertSet.equals() verbessert. TypinferenceResult.getTypeInsertPoints() liefert keine doppelten InsertSets mehr zurück

This commit is contained in:
JanUlrich 2014-03-21 16:34:16 +01:00
parent f16a9345eb
commit 7031839f52
11 changed files with 166 additions and 7 deletions

View File

@ -115,7 +115,8 @@ public class TypeinferenceResultSet
Vector<TypeInsertSet> ret = new Vector<TypeInsertSet>();
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;

View File

@ -71,4 +71,8 @@ public class ResultSet implements Iterable<Pair> {
return this.getResultSet().toString();
}
@Override
public boolean equals(Object obj){
return true;
}
}

View File

@ -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<TypeInsertSet> replaceSet = new Vector<TypeInsertSet>();
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<Pair> resultContent = new Vector<Pair>();
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;
}
}

View File

@ -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();

View File

@ -1,4 +1,4 @@
package plugindevelopment;
package plugindevelopment.TypeInsertTests;
import java.util.Vector;

View File

@ -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<String> mustContain){
String gesamterSrc = "";
String inferedSource = "";
MyCompilerAPI compiler = MyCompiler.getAPI();
try {
compiler.parse(new File(TypeInsertTester.rootDirectory + sourceFileToInfere));
compiler.parse(new File(rootDirectory + sourceFileToInfere));
Vector<TypeinferenceResultSet> 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;
}

View File

@ -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<String> mustContain = new Vector<String>();
mustContain.add("OverloadingTest testMethode");
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}

View File

@ -1,4 +1,4 @@
package plugindevelopment;
package plugindevelopment.TypeInsertTests;
import java.io.File;
import java.io.IOException;

View File

@ -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;
}
}