Some progress toward implementing store(Analysis).
[cfb.git] / prod / net / jaekl / cfb / xml / BugInstance.java
1 package net.jaekl.cfb.xml;
2
3 import java.io.PrintWriter;
4 import java.util.ArrayList;
5
6 import javax.tools.JavaFileManager.Location;
7
8 import org.xml.sax.Attributes;
9
10 import net.jaekl.qd.xml.MissingAttributeException;
11 import net.jaekl.qd.xml.ParseResult;
12 import net.jaekl.qd.xml.XmlParseException;
13
14 public class BugInstance extends ParseResult {
15
16         static final String TAG = "BugInstance";
17         static final String[] INTERNAL = {  };
18         static final Object[][] EXTERNAL = { { BugClass.TAG, BugClass.class},
19                                                  { BugMethod.TAG, BugMethod.class},
20                                                  { LocalVariable.TAG, LocalVariable.class},
21                                                  { SourceLine.TAG, SourceLine.class} };
22         static final String TYPE = "type";
23
24         String m_type;
25         ArrayList<BugClass> m_classes;
26         ArrayList<BugMethod> m_methods;
27         ArrayList<LocalVariable> m_locals;
28         ArrayList<SourceLine> m_lines;
29         
30         public BugInstance() {
31                 super(TAG, INTERNAL, EXTERNAL);
32                 
33                 m_type = null;
34                 m_classes = new ArrayList<BugClass>();
35                 m_methods = new ArrayList<BugMethod>();
36                 m_locals = new ArrayList<LocalVariable>();
37                 m_lines = new ArrayList<SourceLine>();
38         }
39         
40         public String getType() { return m_type; }
41         
42         @Override
43         public void endContents(String uri, String localName, String qName, String chars) 
44                 throws XmlParseException 
45         {
46                 // no-op
47         }
48
49         @Override
50         public void endExternal(String uri, String localName, String qName)
51                 throws XmlParseException 
52         {
53                 if (BugClass.TAG.equals(localName)) {
54                         ParseResult[] collected = collectParsedChildren(BugClass.class);
55                         for (ParseResult pr : collected) {
56                                 assert(pr instanceof BugClass);
57                                 m_classes.add((BugClass) pr);
58                         }
59                 }
60                 else if (BugMethod.TAG.equals(localName)) {
61                         ParseResult[] collected = collectParsedChildren(BugMethod.class);
62                         for (ParseResult pr : collected) {
63                                 assert(pr instanceof BugMethod);
64                                 m_methods.add((BugMethod)pr);
65                         }                       
66                 }
67                 else if (LocalVariable.TAG.equals(localName)) {
68                         ParseResult[] collected = collectParsedChildren(LocalVariable.class);
69                         for (ParseResult pr : collected) {
70                                 assert(pr instanceof LocalVariable);
71                                 m_locals.add((LocalVariable)pr);
72                         }                       
73                 }
74                 else if (SourceLine.TAG.equals(localName)) {
75                         ParseResult[] collected = collectParsedChildren(SourceLine.class);
76                         for (ParseResult pr : collected) {
77                                 assert(pr instanceof SourceLine);
78                                 m_lines.add((SourceLine)pr);
79                         }
80                 }
81         }
82         
83         @Override
84         public void handleMainAttributes(Attributes attr) throws MissingAttributeException
85         {
86                 m_type = this.getRequiredAttr(TAG, attr, TYPE);
87         }
88
89         @Override 
90         public void dump(PrintWriter pw, int indent)
91         {
92                 int childIndent = indent + 2;
93                 String margin = String.format("%" + indent + "s", "");
94                 
95                 pw.println(margin + TAG + " (" + m_type + ")");
96                 for (BugClass bc : m_classes) {
97                         bc.dump(pw, childIndent);
98                 }
99                 for (BugMethod bm : m_methods) {
100                         bm.dump(pw, childIndent);
101                 }
102                 for (LocalVariable lv : m_locals) {
103                         lv.dump(pw, childIndent);
104                 }
105                 for (SourceLine sl : m_lines) {
106                         sl.dump(pw, childIndent);
107                 }
108         }
109 }