package net.jaekl.cfb.xml;
+import java.util.ArrayList;
+
import org.xml.sax.Attributes;
import net.jaekl.qd.xml.ParseResult;
public class BugClass extends ParseResult {
- static final String ROOT_TAG = "Class";
+ static final String TAG = "Class";
static final String[] INTERNAL = { };
- static final Object[][] EXTERNAL = { { SourceLine.ROOT_TAG, SourceLine.class} };
+ static final Object[][] EXTERNAL = { { SourceLine.TAG, SourceLine.class} };
+ static final String CLASS_NAME = "classname";
+
+ String m_className;
+ ArrayList<SourceLine> m_sourceLines;
+
public BugClass() {
- super(ROOT_TAG, INTERNAL, EXTERNAL);
+ super(TAG, INTERNAL, EXTERNAL);
+ m_className = "";
}
@Override
- public void endContents(String uri, String localName, String qName,
- String chars, Attributes attr) throws XmlParseException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void endExternal(String uri, String localName, String qName)
- throws XmlParseException {
- // TODO Auto-generated method stub
-
+ public void endContents(String uri, String localName, String qName, String chars, Attributes attr)
+ throws XmlParseException
+ {
+ m_className = getRequiredAttr(TAG, attr, CLASS_NAME);
}
+ @Override
+ public void endExternal(String uri, String localName, String qName)
+ throws XmlParseException
+ {
+ if (SourceLine.TAG.equals(localName)) {
+ ParseResult[] collected = collectParsedChildren(SourceLine.class);
+ for (ParseResult pr : collected) {
+ assert(pr instanceof SourceLine);
+ m_sourceLines.add((SourceLine)pr);
+ }
+ }
+ }
}
public class BugCollection extends ParseResult {
- static final String ROOT_TAG = "BugCollection";
+ static final String TAG = "BugCollection";
static final String[] INTERNAL = { };
- static final Object[][] EXTERNAL = { { BugInstance.ROOT_TAG, BugInstance.class} };
+ static final Object[][] EXTERNAL = { { BugInstance.TAG, BugInstance.class} };
public BugCollection() {
- super(ROOT_TAG, INTERNAL, EXTERNAL);
+ super(TAG, INTERNAL, EXTERNAL);
}
@Override
package net.jaekl.cfb.xml;
+import java.util.ArrayList;
+
import org.xml.sax.Attributes;
import net.jaekl.qd.xml.ParseResult;
public class BugInstance extends ParseResult {
- static final String ROOT_TAG = "BugInstance";
+ static final String TAG = "BugInstance";
static final String[] INTERNAL = { };
- static final Object[][] EXTERNAL = { { BugClass.ROOT_TAG, BugClass.class},
- { BugMethod.ROOT_TAG, BugMethod.class},
- { SourceLine.ROOT_TAG, SourceLine.class} };
+ static final Object[][] EXTERNAL = { { BugClass.TAG, BugClass.class},
+ { BugMethod.TAG, BugMethod.class},
+ { LocalVariable.TAG, LocalVariable.class},
+ { SourceLine.TAG, SourceLine.class} };
+ ArrayList<BugClass> m_classes;
+ ArrayList<BugMethod> m_methods;
+ ArrayList<LocalVariable> m_locals;
+ ArrayList<SourceLine> m_lines;
+
public BugInstance() {
- super(ROOT_TAG, INTERNAL, EXTERNAL);
+ super(TAG, INTERNAL, EXTERNAL);
+
+ m_classes = new ArrayList<BugClass>();
+ m_methods = new ArrayList<BugMethod>();
+ m_locals = new ArrayList<LocalVariable>();
+ m_lines = new ArrayList<SourceLine>();
}
@Override
- public void endContents(String uri, String localName, String qName,
- String chars, Attributes attr) throws XmlParseException {
- // TODO Auto-generated method stub
-
+ public void endContents(String uri, String localName, String qName, String chars, Attributes attr)
+ throws XmlParseException
+ {
}
@Override
public void endExternal(String uri, String localName, String qName)
- throws XmlParseException {
- // TODO Auto-generated method stub
-
+ throws XmlParseException
+ {
+ if (BugClass.TAG.equals(localName)) {
+ ParseResult[] collected = collectParsedChildren(BugClass.class);
+ for (ParseResult pr : collected) {
+ assert(pr instanceof BugClass);
+ m_classes.add((BugClass) pr);
+ }
+ }
+ else if (BugMethod.TAG.equals(localName)) {
+ ParseResult[] collected = collectParsedChildren(BugMethod.class);
+ for (ParseResult pr : collected) {
+ assert(pr instanceof BugMethod);
+ m_methods.add((BugMethod)pr);
+ }
+ }
+ else if (LocalVariable.TAG.equals(localName)) {
+ ParseResult[] collected = collectParsedChildren(LocalVariable.class);
+ for (ParseResult pr : collected) {
+ assert(pr instanceof LocalVariable);
+ m_locals.add((LocalVariable)pr);
+ }
+ }
+ else if (SourceLine.TAG.equals(localName)) {
+ ParseResult[] collected = collectParsedChildren(SourceLine.class);
+ for (ParseResult pr : collected) {
+ assert(pr instanceof SourceLine);
+ m_lines.add((SourceLine)pr);
+ }
+ }
}
}
package net.jaekl.cfb.xml;
+import java.util.ArrayList;
+
import org.xml.sax.Attributes;
import net.jaekl.qd.xml.ParseResult;
public class BugMethod extends ParseResult {
- static final String ROOT_TAG = "Method";
+ static final String TAG = "Method";
static final String[] INTERNAL = { };
- static final Object[][] EXTERNAL = { { SourceLine.ROOT_TAG, SourceLine.class} };
+ static final Object[][] EXTERNAL = { { SourceLine.TAG, SourceLine.class} };
+ static final String CLASS_NAME = "classname";
+ static final String METHOD_NAME = "name";
+ static final String SIGNATURE = "signature";
+ static final String IS_STATIC = "isStatic";
+ static final String ROLE = "role";
+
+ static final String TRUE = "true"; // yes value for isStatic
+
+ String m_className;
+ String m_methodName;
+ String m_signature;
+ boolean m_isStatic;
+ String m_role; // optional
+ ArrayList<SourceLine> m_sourceLines;
+
public BugMethod() {
- super(ROOT_TAG, INTERNAL, EXTERNAL);
+ super(TAG, INTERNAL, EXTERNAL);
+ m_className = m_methodName = m_signature = m_role = null;
+ m_isStatic = false;
+ m_sourceLines = new ArrayList<SourceLine>();
}
@Override
- public void endContents(String uri, String localName, String qName,
- String chars, Attributes attr) throws XmlParseException {
- // TODO Auto-generated method stub
-
+ public void endContents(String uri, String localName, String qName, String chars, Attributes attr)
+ throws XmlParseException
+ {
+ m_className = getRequiredAttr(TAG, attr, CLASS_NAME);
+ m_methodName = getRequiredAttr(TAG, attr, METHOD_NAME);
+ m_signature = getRequiredAttr(TAG, attr, SIGNATURE);
+ m_isStatic = getRequiredAttr(TAG, attr, IS_STATIC).equals(TRUE);
+ m_role = getOptionalAttr(attr, ROLE, null);
}
@Override
public void endExternal(String uri, String localName, String qName)
- throws XmlParseException {
- // TODO Auto-generated method stub
-
+ throws XmlParseException
+ {
+ if (SourceLine.TAG.equals(localName)) {
+ ParseResult[] collected = collectParsedChildren(SourceLine.class);
+ for (ParseResult pr : collected) {
+ assert(pr instanceof SourceLine);
+ m_sourceLines.add((SourceLine)pr);
+ }
+ }
}
}
--- /dev/null
+package net.jaekl.cfb.xml;
+
+import org.xml.sax.Attributes;
+
+import net.jaekl.qd.xml.ParseResult;
+import net.jaekl.qd.xml.XmlParseException;
+
+public class LocalVariable extends ParseResult {
+
+ static final String TAG = "LocalVariable";
+ static final String[] INTERNAL = { };
+ static final Object[][] EXTERNAL = { };
+
+ static final String NAME = "name";
+ static final String ROLE = "role";
+
+ String m_name;
+ String m_role;
+
+ public LocalVariable() {
+ super(TAG, INTERNAL, EXTERNAL);
+
+ m_name = m_role = null;
+ }
+
+ @Override
+ public void endContents(String uri, String localName, String qName, String chars, Attributes attr)
+ throws XmlParseException
+ {
+ m_name = getRequiredAttr(TAG, attr, NAME);
+ m_role = getRequiredAttr(TAG, attr, ROLE);
+ }
+
+ @Override
+ public void endExternal(String uri, String localName, String qName)
+ throws XmlParseException
+ {
+ // no-op
+ }
+}
package net.jaekl.cfb.xml;
-import org.xml.sax.Attributes;
-
-import net.jaekl.qd.xml.MissingAttributeException;
import net.jaekl.qd.xml.ParseResult;
import net.jaekl.qd.xml.XmlParseException;
+import org.xml.sax.Attributes;
+
public class SourceLine extends ParseResult {
- static final String ROOT_TAG = "SourceLine";
+ static final String TAG = "SourceLine";
static final String[] INTERNAL = { };
static final Object[][] EXTERNAL = { };
int m_end;
public SourceLine() {
- super(ROOT_TAG, INTERNAL, EXTERNAL);
+ super(TAG, INTERNAL, EXTERNAL);
m_className = null;
m_start = m_end = (-1);
}
m_end = Integer.parseInt(scratch);
}
- String getRequiredAttr(String tagName, Attributes attr, String attrName)
- throws MissingAttributeException
- {
- String result = attr.getValue(attrName);
- if (null == result) {
- throw new MissingAttributeException(tagName, attrName);
- }
- return result;
- }
-
@Override
public void endExternal(String uri, String localName, String qName)
throws XmlParseException
{
// no-op
}
-
}
public abstract class ParseResult
{
+ public static final String TAG_FIELD_NAME = "TAG";
+
Stack<CurrentInfo> m_current; // Name of the element that we're currently inside
StringBuilder m_chars; // character content of m_current.peek()
ArrayList<ParseResult> m_childParsers; // Set of all child parsers
ParseResult[] result = new ParseResult[collection.size()];
return collection.toArray(result);
}
-
+
// returns true if this ParseResult's context has ended with this endElement() call
public boolean endElement(String uri, String localName, String qName) throws XmlParseException
{
// Default implementation is a no-op.
// Override if you want to validate on endElement()
}
+
+ protected String getRequiredAttr(String tagName, Attributes attr, String attrName)
+ throws MissingAttributeException
+ {
+ String result = attr.getValue(attrName);
+ if (null == result) {
+ throw new MissingAttributeException(tagName, attrName);
+ }
+ return result;
+ }
+
+ protected String getOptionalAttr(Attributes attr, String attrName, String defaultValue)
+ {
+ String value = attr.getValue(attrName);
+ if (null == value) {
+ return defaultValue;
+ }
+ return value;
+ }
}