2017-03-02 17:16:14 +00:00
|
|
|
package typeinference;
|
|
|
|
|
|
|
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
2017-07-05 15:42:41 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
2017-06-30 09:13:15 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
2017-06-14 02:07:27 +00:00
|
|
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
2017-07-05 15:42:41 +00:00
|
|
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
2017-09-07 17:52:05 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
2017-03-02 17:16:14 +00:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2017-09-19 16:51:44 +00:00
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLClassLoader;
|
2017-05-18 11:17:52 +00:00
|
|
|
import java.nio.charset.Charset;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
2017-05-31 15:10:50 +00:00
|
|
|
import java.util.ArrayList;
|
2017-05-18 11:17:52 +00:00
|
|
|
import java.util.List;
|
2017-08-22 14:45:28 +00:00
|
|
|
import java.util.Set;
|
2017-03-02 17:16:14 +00:00
|
|
|
|
2017-09-20 16:20:52 +00:00
|
|
|
public class JavaTXCompilerTest {
|
2017-03-02 17:16:14 +00:00
|
|
|
|
2017-09-19 16:51:44 +00:00
|
|
|
public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
|
2017-05-31 15:10:50 +00:00
|
|
|
private static final List<File> filesToTest = new ArrayList<>();
|
2017-09-19 16:51:44 +00:00
|
|
|
protected File fileToTest = null;
|
|
|
|
|
|
|
|
public JavaTXCompilerTest(){
|
|
|
|
}
|
2017-03-02 17:16:14 +00:00
|
|
|
|
|
|
|
@Test
|
2017-07-14 15:47:02 +00:00
|
|
|
public void test() throws IOException, java.lang.ClassNotFoundException {
|
2017-09-19 16:51:44 +00:00
|
|
|
if(fileToTest != null)filesToTest.add(fileToTest);
|
2017-09-28 14:55:29 +00:00
|
|
|
else return;
|
2017-08-28 13:42:51 +00:00
|
|
|
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
2017-08-30 13:29:34 +00:00
|
|
|
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
2017-10-05 18:02:11 +00:00
|
|
|
//filesToTest.add(new File(rootDirectory+"test.jav"));
|
|
|
|
filesToTest.add(new File(rootDirectory+"EmptyMethod.jav"));
|
2017-11-03 12:56:04 +00:00
|
|
|
//filesToTest.add(new File(rootDirectory+"fc.jav"));
|
2017-08-28 13:42:51 +00:00
|
|
|
//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"));
|
2017-08-28 16:36:26 +00:00
|
|
|
//filesToTest.add(new File(rootDirectory+"Import.jav"));
|
2017-09-20 16:20:52 +00:00
|
|
|
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
2017-10-03 19:58:39 +00:00
|
|
|
List<ResultSet> results = compiler.typeInference();
|
2017-09-20 16:20:52 +00:00
|
|
|
|
|
|
|
for(File f : compiler.sourceFiles.keySet()){
|
|
|
|
SourceFile sf = compiler.sourceFiles.get(f);
|
|
|
|
System.out.println(ASTTypePrinter.print(sf));
|
2017-10-03 19:58:39 +00:00
|
|
|
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
2017-09-25 09:22:53 +00:00
|
|
|
assert results.size()>0;
|
|
|
|
for(ResultSet resultSet : results){
|
2017-09-07 17:52:05 +00:00
|
|
|
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
2017-09-25 09:22:53 +00:00
|
|
|
assert result.size()>0;
|
2017-09-07 17:52:05 +00:00
|
|
|
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
|
|
|
for(TypeInsert tip : result){
|
|
|
|
System.out.println(tip.insert(content));
|
|
|
|
}
|
2017-05-31 15:10:50 +00:00
|
|
|
}
|
2017-05-18 11:17:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static String readFile(String path, Charset encoding)
|
|
|
|
throws IOException
|
|
|
|
{
|
|
|
|
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
|
|
|
return new String(encoded, encoding);
|
2017-03-02 17:16:14 +00:00
|
|
|
}
|
2017-06-30 09:13:15 +00:00
|
|
|
|
2017-09-19 16:51:44 +00:00
|
|
|
}
|
|
|
|
|