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 extends JavaTXCompiler { public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; private static final List filesToTest = new ArrayList<>(); protected File fileToTest = null; public JavaTXCompilerTest(){ } @Test public void test() throws IOException, java.lang.ClassNotFoundException { for(URL url : ((URLClassLoader) (Thread.currentThread().getContextClassLoader())).getURLs()){ System.out.println(url); } if(fileToTest != null)filesToTest.add(fileToTest); //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+"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")); for(File f : filesToTest){ SourceFile sf = this.parse(f); System.out.println(ASTTypePrinter.print(this.sourceFiles.get(sourceFiles.size()-1))); for(ResultSet resultSet : this.typeInference()){ Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); 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); } }