1 package net.jaekl.cfb.xml;
3 import java.io.PrintWriter;
4 import java.util.ArrayList;
6 import javax.tools.JavaFileManager.Location;
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 TYPE = "type";
25 ArrayList<BugClass> m_classes;
26 ArrayList<BugMethod> m_methods;
27 ArrayList<LocalVariable> m_locals;
28 ArrayList<SourceLine> m_lines;
30 public BugInstance() {
31 super(TAG, INTERNAL, EXTERNAL);
34 m_classes = new ArrayList<BugClass>();
35 m_methods = new ArrayList<BugMethod>();
36 m_locals = new ArrayList<LocalVariable>();
37 m_lines = new ArrayList<SourceLine>();
40 public String getType() { return m_type; }
43 public void endContents(String uri, String localName, String qName, String chars)
44 throws XmlParseException
50 public void endExternal(String uri, String localName, String qName)
51 throws XmlParseException
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);
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);
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);
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);
84 public void handleMainAttributes(Attributes attr) throws MissingAttributeException
86 m_type = this.getRequiredAttr(TAG, attr, TYPE);
90 public void dump(PrintWriter pw, int indent)
92 int childIndent = indent + 2;
93 String margin = String.format("%" + indent + "s", "");
95 pw.println(margin + TAG + " (" + m_type + ")");
96 for (BugClass bc : m_classes) {
97 bc.dump(pw, childIndent);
99 for (BugMethod bm : m_methods) {
100 bm.dump(pw, childIndent);
102 for (LocalVariable lv : m_locals) {
103 lv.dump(pw, childIndent);
105 for (SourceLine sl : m_lines) {
106 sl.dump(pw, childIndent);