1 package net.jaekl.cfb.xml;
3 import java.io.PrintWriter;
4 import java.util.ArrayList;
5 import java.util.Collections;
8 import org.xml.sax.Attributes;
10 import net.jaekl.qd.xml.MissingAttributeException;
11 import net.jaekl.qd.xml.ParseResult;
12 import net.jaekl.qd.xml.XmlParseException;
14 public class BugInstance extends ParseResult {
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 CATEGORY = "category";
23 static final String TYPE = "type";
27 ArrayList<BugClass> m_classes;
28 ArrayList<BugMethod> m_methods;
29 ArrayList<LocalVariable> m_locals;
30 ArrayList<SourceLine> m_lines;
32 public BugInstance() {
33 super(TAG, INTERNAL, EXTERNAL);
35 m_category = m_type = null;
36 m_classes = new ArrayList<BugClass>();
37 m_methods = new ArrayList<BugMethod>();
38 m_locals = new ArrayList<LocalVariable>();
39 m_lines = new ArrayList<SourceLine>();
42 public String getCategory() { return m_category; }
43 public String getType() { return m_type; }
44 public List<BugClass> getClasses() { return Collections.unmodifiableList(m_classes); }
45 public List<BugMethod> getMethods() { return Collections.unmodifiableList(m_methods); }
46 public List<SourceLine> getLines() { return Collections.unmodifiableList(m_lines); }
47 public List<LocalVariable> getVariables() { return Collections.unmodifiableList(m_locals); }
50 public void endContents(String uri, String localName, String qName, String chars)
51 throws XmlParseException
57 public void endExternal(String uri, String localName, String qName)
58 throws XmlParseException
60 if (BugClass.TAG.equals(localName)) {
61 ParseResult[] collected = collectParsedChildren(BugClass.class);
62 for (ParseResult pr : collected) {
63 assert(pr instanceof BugClass);
64 m_classes.add((BugClass) pr);
67 else if (BugMethod.TAG.equals(localName)) {
68 ParseResult[] collected = collectParsedChildren(BugMethod.class);
69 for (ParseResult pr : collected) {
70 assert(pr instanceof BugMethod);
71 m_methods.add((BugMethod)pr);
74 else if (LocalVariable.TAG.equals(localName)) {
75 ParseResult[] collected = collectParsedChildren(LocalVariable.class);
76 for (ParseResult pr : collected) {
77 assert(pr instanceof LocalVariable);
78 m_locals.add((LocalVariable)pr);
81 else if (SourceLine.TAG.equals(localName)) {
82 ParseResult[] collected = collectParsedChildren(SourceLine.class);
83 for (ParseResult pr : collected) {
84 assert(pr instanceof SourceLine);
85 m_lines.add((SourceLine)pr);
91 public void handleMainAttributes(Attributes attr) throws MissingAttributeException
93 m_type = this.getRequiredAttr(TAG, attr, TYPE);
94 m_category = this.getRequiredAttr(TAG, attr, CATEGORY);
98 public void dump(PrintWriter pw, int indent)
100 int childIndent = indent + 2;
101 String margin = String.format("%" + indent + "s", "");
103 pw.println(margin + TAG + " (" + m_type + ")");
104 pw.println(margin + CATEGORY + " (" + m_category + ")");
105 for (BugClass bc : m_classes) {
106 bc.dump(pw, childIndent);
108 for (BugMethod bm : m_methods) {
109 bm.dump(pw, childIndent);
111 for (LocalVariable lv : m_locals) {
112 lv.dump(pw, childIndent);
114 for (SourceLine sl : m_lines) {
115 sl.dump(pw, childIndent);