1 package net.jaekl.cfb.xml;
3 import java.io.PrintWriter;
4 import java.util.ArrayList;
6 import org.xml.sax.Attributes;
8 import net.jaekl.qd.xml.MissingAttributeException;
9 import net.jaekl.qd.xml.ParseResult;
10 import net.jaekl.qd.xml.XmlParseException;
12 public class BugInstance extends ParseResult {
14 static final String TAG = "BugInstance";
15 static final String[] INTERNAL = { };
16 static final Object[][] EXTERNAL = { { BugClass.TAG, BugClass.class},
17 { BugMethod.TAG, BugMethod.class},
18 { LocalVariable.TAG, LocalVariable.class},
19 { SourceLine.TAG, SourceLine.class} };
20 static final String TYPE = "type";
23 ArrayList<BugClass> m_classes;
24 ArrayList<BugMethod> m_methods;
25 ArrayList<LocalVariable> m_locals;
26 ArrayList<SourceLine> m_lines;
28 public BugInstance() {
29 super(TAG, INTERNAL, EXTERNAL);
32 m_classes = new ArrayList<BugClass>();
33 m_methods = new ArrayList<BugMethod>();
34 m_locals = new ArrayList<LocalVariable>();
35 m_lines = new ArrayList<SourceLine>();
38 public String getType() { return m_type; }
41 public void endContents(String uri, String localName, String qName, String chars)
42 throws XmlParseException
48 public void endExternal(String uri, String localName, String qName)
49 throws XmlParseException
51 if (BugClass.TAG.equals(localName)) {
52 ParseResult[] collected = collectParsedChildren(BugClass.class);
53 for (ParseResult pr : collected) {
54 assert(pr instanceof BugClass);
55 m_classes.add((BugClass) pr);
58 else if (BugMethod.TAG.equals(localName)) {
59 ParseResult[] collected = collectParsedChildren(BugMethod.class);
60 for (ParseResult pr : collected) {
61 assert(pr instanceof BugMethod);
62 m_methods.add((BugMethod)pr);
65 else if (LocalVariable.TAG.equals(localName)) {
66 ParseResult[] collected = collectParsedChildren(LocalVariable.class);
67 for (ParseResult pr : collected) {
68 assert(pr instanceof LocalVariable);
69 m_locals.add((LocalVariable)pr);
72 else if (SourceLine.TAG.equals(localName)) {
73 ParseResult[] collected = collectParsedChildren(SourceLine.class);
74 for (ParseResult pr : collected) {
75 assert(pr instanceof SourceLine);
76 m_lines.add((SourceLine)pr);
82 public void handleMainAttributes(Attributes attr) throws MissingAttributeException
84 m_type = this.getRequiredAttr(TAG, attr, TYPE);
88 public void dump(PrintWriter pw, int indent)
90 int childIndent = indent + 2;
91 String margin = String.format("%" + indent + "s", "");
93 pw.println(margin + TAG + " (" + m_type + ")");
94 for (BugClass bc : m_classes) {
95 bc.dump(pw, childIndent);
97 for (BugMethod bm : m_methods) {
98 bm.dump(pw, childIndent);
100 for (LocalVariable lv : m_locals) {
101 lv.dump(pw, childIndent);
103 for (SourceLine sl : m_lines) {
104 sl.dump(pw, childIndent);