small change
[cdsspec-compiler.git] / src / edu / uci / eecs / specCompiler / specExtraction / SpecExtractor.java
index 1286a143a3eed84665a04be677fcb04a93695747..2de7be92f0448ba74459180dcd2f0f3a069b2115 100644 (file)
@@ -7,6 +7,7 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.LineNumberReader;
 import java.util.ArrayList;
+import java.util.HashMap;
 
 import edu.uci.eecs.specCompiler.grammerParser.ParseException;
 import edu.uci.eecs.specCompiler.grammerParser.SpecParser;
@@ -24,18 +25,16 @@ import edu.uci.eecs.specCompiler.grammerParser.TokenMgrError;
  * 
  */
 public class SpecExtractor {
-       private ArrayList<Construct> _constructs;
-       private int _beginLineNum, _endLineNum;
-       private String _beginLine;
+       public final ArrayList<Construct> constructs;
+       
+       public final HashMap<File, ArrayList<String>> contents;
+       
 
        public SpecExtractor() {
-               _constructs = new ArrayList<Construct>();
+               constructs = new ArrayList<Construct>();
+               contents = new HashMap<File, ArrayList<String>>();
        }
        
-       ArrayList<Construct> getConstructs() {
-               return this._constructs;
-       }
-
        /**
         * <p>
         * Given a list of files, it scans each file and add found SpecConstrcut to
@@ -51,26 +50,20 @@ public class SpecExtractor {
        }
 
        public void extract(File file) {
-               StringBuilder specText = new StringBuilder();
-               
-       }
-
-       public static String trimSpace(String line) {
-               int i, j;
-               char ch;
-               for (i = 0; i < line.length(); i++) {
-                       ch = line.charAt(i);
-                       if (ch != ' ' && ch != '\t')
-                               break;
-               }
-               for (j = line.length() - 1; j >= 0; j--) {
-                       ch = line.charAt(j);
-                       if (ch != ' ' && ch != '\t')
-                               break;
+               if (contents.containsKey(file))
+                       return;
+               ArrayList<String> content = new ArrayList<String>();
+               ArrayList<Construct> localConstructs = new ArrayList<Construct>();
+               try {
+                       SpecParser.ParseFile(file, content, localConstructs);
+                       contents.put(file, content);
+                       constructs.addAll(localConstructs);
+               } catch (ParseException e) {
+                       e.printStackTrace();
+               } catch (TokenMgrError e) {
+                       e.printStackTrace();
                }
-               if (i > j)
-                       return "";
-               else
-                       return line.substring(i, j + 1);
        }
+
+       
 }