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>();
39 public void endContents(String uri, String localName, String qName, String chars)
40 throws XmlParseException
46 public void endExternal(String uri, String localName, String qName)
47 throws XmlParseException
49 if (BugClass.TAG.equals(localName)) {
50 ParseResult[] collected = collectParsedChildren(BugClass.class);
51 for (ParseResult pr : collected) {
52 assert(pr instanceof BugClass);
53 m_classes.add((BugClass) pr);
56 else if (BugMethod.TAG.equals(localName)) {
57 ParseResult[] collected = collectParsedChildren(BugMethod.class);
58 for (ParseResult pr : collected) {
59 assert(pr instanceof BugMethod);
60 m_methods.add((BugMethod)pr);
63 else if (LocalVariable.TAG.equals(localName)) {
64 ParseResult[] collected = collectParsedChildren(LocalVariable.class);
65 for (ParseResult pr : collected) {
66 assert(pr instanceof LocalVariable);
67 m_locals.add((LocalVariable)pr);
70 else if (SourceLine.TAG.equals(localName)) {
71 ParseResult[] collected = collectParsedChildren(SourceLine.class);
72 for (ParseResult pr : collected) {
73 assert(pr instanceof SourceLine);
74 m_lines.add((SourceLine)pr);
80 public void handleMainAttributes(Attributes attr) throws MissingAttributeException
82 m_type = this.getRequiredAttr(TAG, attr, TYPE);
86 public void dump(PrintWriter pw, int indent)
88 int childIndent = indent + 2;
89 String margin = String.format("%" + indent + "s", "");
91 pw.println(margin + TAG + " (" + m_type + ")");
92 for (BugClass bc : m_classes) {
93 bc.dump(pw, childIndent);
95 for (BugMethod bm : m_methods) {
96 bm.dump(pw, childIndent);
98 for (LocalVariable lv : m_locals) {
99 lv.dump(pw, childIndent);
101 for (SourceLine sl : m_lines) {
102 sl.dump(pw, childIndent);