fixed bugs
[cdsspec-compiler.git] / src / edu / uci / eecs / specCompiler / specExtraction / SourceFileInfo.java
index 85f3422937f45521671560d636822b9d62c5833e..2b9af875b79a05d57d5da7b63b4f7aa19fd07c46 100644 (file)
@@ -1,8 +1,13 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
 import java.util.ArrayList;
 
+import edu.uci.eecs.specCompiler.codeGenerator.Environment;
+
 public class SourceFileInfo {
        public final File file;
        public final ArrayList<String> content;
@@ -23,4 +28,26 @@ public class SourceFileInfo {
                SourceFileInfo another = (SourceFileInfo) o;
                return another.file.equals(file);
        }
+       
+       public void write2File() {
+               String newFileName = Environment.GENERATED_FILE_DIR + "/" + file.getName();
+               File newFile = new File(newFileName);
+               newFile.getParentFile().mkdirs();
+               if (!newFile.exists()) {
+                       try {
+                               newFile.createNewFile();
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
+               }
+               try {
+                       BufferedWriter bw = new BufferedWriter(new FileWriter(newFile));
+                       for (int i = 0; i < content.size(); i++) {
+                               bw.write(content.get(i) + "\n");
+                       }
+                       bw.flush();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+       }
 }