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-03-02 17:16:14 +00:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
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-06-28 19:10:28 +00:00
|
|
|
public class JavaTXCompilerTest extends JavaTXCompiler {
|
2017-03-02 17:16:14 +00:00
|
|
|
|
|
|
|
private 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-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-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"));
|
|
|
|
filesToTest.add(new File(rootDirectory+"test.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-05-31 15:10:50 +00:00
|
|
|
for(File f : filesToTest){
|
2017-07-05 15:50:38 +00:00
|
|
|
SourceFile sf = this.parse(f);
|
2017-06-30 09:13:15 +00:00
|
|
|
System.out.println(ASTTypePrinter.print(this.sourceFiles.get(sourceFiles.size()-1)));
|
2017-08-22 14:45:28 +00:00
|
|
|
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, this.typeInference());
|
2017-05-31 15:10:50 +00:00
|
|
|
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
2017-06-14 02:07:27 +00:00
|
|
|
for(TypeInsert tip : result){
|
2017-05-31 15:10:50 +00:00
|
|
|
System.out.println(tip.insert(content));
|
|
|
|
}
|
2017-05-18 11:17:52 +00:00
|
|
|
}
|
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-03-02 17:16:14 +00:00
|
|
|
}
|