package bytecode; import de.dhbwstuttgart.bytecode.BytecodeGen; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.syntaxtree.visual.OutputGenerator; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.ResultSet; import org.junit.Test; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; 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.HashMap; import java.util.List; import java.util.Set; import static org.junit.Assert.*; public class JavaTXCompilerTest extends JavaTXCompiler { private static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; private static final List filesToTest = new ArrayList<>(); @Test public void test() throws IOException, java.lang.ClassNotFoundException { filesToTest.add(new File(rootDirectory+"EmptyMethod.jav")); for(File f : filesToTest){ SourceFile sf = this.parse(f); String content = readFile(f.getPath(), StandardCharsets.UTF_8); HashMap bytecode = this.getBytecode(sf); this.writeClassFile(bytecode, "EmptyMethod"); } } public HashMap getBytecode(SourceFile sf) { HashMap classFiles = new HashMap<>(); BytecodeGen bytecodeGen = new BytecodeGen(classFiles); bytecodeGen.visit(sf); return bytecodeGen.getClassFiles(); } public void writeClassFile(HashMap classFiles, String name) { FileOutputStream output; byte[] bytecode = classFiles.get(name); try { System.out.println("generating .class file"); output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/" +name+".class")); output.write(bytecode); output.close(); System.out.println(".class file generated"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } static String readFile(String path, Charset encoding) throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, encoding); } }