Add local variable information to DB store.
[cfb.git] / prod / net / jaekl / cfb / xml / BugInstance.java
index f1f8537177befd7c51ad867a89a03ee993e938b4..3386e3f70fd2d47da0d820e174c617f5592e73b5 100644 (file)
@@ -1,9 +1,13 @@
 package net.jaekl.cfb.xml;
 
+import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 import org.xml.sax.Attributes;
 
+import net.jaekl.qd.xml.MissingAttributeException;
 import net.jaekl.qd.xml.ParseResult;
 import net.jaekl.qd.xml.XmlParseException;
 
@@ -15,7 +19,11 @@ public class BugInstance extends ParseResult {
                                                 { BugMethod.TAG, BugMethod.class},
                                                 { LocalVariable.TAG, LocalVariable.class},
                                                 { SourceLine.TAG, SourceLine.class} };
+       static final String CATEGORY = "category";
+       static final String TYPE = "type";
 
+       String m_category;
+       String m_type;
        ArrayList<BugClass> m_classes;
        ArrayList<BugMethod> m_methods;
        ArrayList<LocalVariable> m_locals;
@@ -24,16 +32,25 @@ public class BugInstance extends ParseResult {
        public BugInstance() {
                super(TAG, INTERNAL, EXTERNAL);
                
+               m_category = m_type = null;
                m_classes = new ArrayList<BugClass>();
                m_methods = new ArrayList<BugMethod>();
                m_locals = new ArrayList<LocalVariable>();
                m_lines = new ArrayList<SourceLine>();
        }
        
+       public String getCategory() { return m_category; }
+       public String getType() { return m_type; }
+       public List<BugClass> getClasses() { return Collections.unmodifiableList(m_classes); }
+       public List<BugMethod> getMethods() { return Collections.unmodifiableList(m_methods); }
+       public List<SourceLine> getLines() { return Collections.unmodifiableList(m_lines); }
+       public List<LocalVariable> getVariables() { return Collections.unmodifiableList(m_locals); }
+       
        @Override
-       public void endContents(String uri, String localName, String qName, String chars, Attributes attr
+       public void endContents(String uri, String localName, String qName, String chars) 
                throws XmlParseException 
        {
+               // no-op
        }
 
        @Override
@@ -69,5 +86,33 @@ public class BugInstance extends ParseResult {
                        }
                }
        }
+       
+       @Override
+       public void handleMainAttributes(Attributes attr) throws MissingAttributeException
+       {
+               m_type = this.getRequiredAttr(TAG, attr, TYPE);
+               m_category = this.getRequiredAttr(TAG, attr, CATEGORY);
+       }
 
+       @Override 
+       public void dump(PrintWriter pw, int indent)
+       {
+               int childIndent = indent + 2;
+               String margin = String.format("%" + indent + "s", "");
+               
+               pw.println(margin + TAG + " (" + m_type + ")");
+               pw.println(margin + CATEGORY + " (" + m_category + ")");
+               for (BugClass bc : m_classes) {
+                       bc.dump(pw, childIndent);
+               }
+               for (BugMethod bm : m_methods) {
+                       bm.dump(pw, childIndent);
+               }
+               for (LocalVariable lv : m_locals) {
+                       lv.dump(pw, childIndent);
+               }
+               for (SourceLine sl : m_lines) {
+                       sl.dump(pw, childIndent);
+               }
+       }
 }