JavaTXCompilerInJavaTX/test/typeinference/JavaTXCompilerTest.java
2017-11-03 13:56:04 +01:00

77 lines
3.0 KiB
Java

package typeinference;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class JavaTXCompilerTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
private static final List<File> filesToTest = new ArrayList<>();
protected File fileToTest = null;
public JavaTXCompilerTest(){
}
@Test
public void test() throws IOException, java.lang.ClassNotFoundException {
if(fileToTest != null)filesToTest.add(fileToTest);
else return;
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
//filesToTest.add(new File(rootDirectory+"test.jav"));
filesToTest.add(new File(rootDirectory+"EmptyMethod.jav"));
//filesToTest.add(new File(rootDirectory+"fc.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
//filesToTest.add(new File(rootDirectory+"Generics.jav"));
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
//filesToTest.add(new File(rootDirectory+"Import.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
System.out.println(tip.insert(content));
}
}
}
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}