Add knowledge about the specific FB tags
authorChris Jaekl <chris@ringo.jaekl.net>
Fri, 4 Sep 2015 13:02:05 +0000 (22:02 +0900)
committerChris Jaekl <chris@ringo.jaekl.net>
Fri, 4 Sep 2015 13:02:05 +0000 (22:02 +0900)
prod/net/jaekl/cfb/xml/BugClass.java
prod/net/jaekl/cfb/xml/BugCollection.java
prod/net/jaekl/cfb/xml/BugInstance.java
prod/net/jaekl/cfb/xml/BugMethod.java
prod/net/jaekl/cfb/xml/LocalVariable.java [new file with mode: 0644]
prod/net/jaekl/cfb/xml/SourceLine.java
prod/net/jaekl/qd/xml/ParseResult.java

index 34e02a242de215902d60fd284af1f4964e20caa6..eb2c5929347c5c108331286f6362e76d3097a3c1 100644 (file)
@@ -1,5 +1,7 @@
 package net.jaekl.cfb.xml;
 
+import java.util.ArrayList;
+
 import org.xml.sax.Attributes;
 
 import net.jaekl.qd.xml.ParseResult;
@@ -7,26 +9,37 @@ import net.jaekl.qd.xml.XmlParseException;
 
 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);
+                       }
+               }
+    }
 }
index 9078e2fe95ef73f1a946ee397331264e33de470b..b59bdc8263b630bb38b4056d5a007dbba67d2f72 100644 (file)
@@ -7,12 +7,12 @@ import net.jaekl.qd.xml.XmlParseException;
 
 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
index 81ebcfcd671f4abdf8afa16fe62bec1175116abd..f1f8537177befd7c51ad867a89a03ee993e938b4 100644 (file)
@@ -1,5 +1,7 @@
 package net.jaekl.cfb.xml;
 
+import java.util.ArrayList;
+
 import org.xml.sax.Attributes;
 
 import net.jaekl.qd.xml.ParseResult;
@@ -7,28 +9,65 @@ import net.jaekl.qd.xml.XmlParseException;
 
 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);
+                       }
+               }
        }
 
 }
index 6a63b439e339de56d556616357ada548d80cf6a9..2e001b23abe93116f71c47782bc1f21b428308e6 100644 (file)
@@ -1,5 +1,7 @@
 package net.jaekl.cfb.xml;
 
+import java.util.ArrayList;
+
 import org.xml.sax.Attributes;
 
 import net.jaekl.qd.xml.ParseResult;
@@ -7,26 +9,54 @@ import net.jaekl.qd.xml.XmlParseException;
 
 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);
+                       }
+               }
        }
 
 }
diff --git a/prod/net/jaekl/cfb/xml/LocalVariable.java b/prod/net/jaekl/cfb/xml/LocalVariable.java
new file mode 100644 (file)
index 0000000..b52823f
--- /dev/null
@@ -0,0 +1,40 @@
+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
+       }
+}
index c78ae3af8717835bf21d207b3c9660a19d55edcf..627667a161ac4e3902c6170412e5f32badf2c6b8 100644 (file)
@@ -1,14 +1,13 @@
 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 = { };
        
@@ -21,7 +20,7 @@ public class SourceLine extends ParseResult {
        int m_end;
 
        public SourceLine() {
-               super(ROOT_TAG, INTERNAL, EXTERNAL);
+               super(TAG, INTERNAL, EXTERNAL);
                m_className = null;
                m_start = m_end = (-1);
        }       
@@ -41,21 +40,10 @@ public class SourceLine extends ParseResult {
                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
        }
-
 }
index 6c2c25f6e9c2e7b22567cbaf388038a9cc2cb685..e8210159951327dfbb7646f28c8d05bfe55e7f80 100644 (file)
@@ -19,6 +19,8 @@ import org.xml.sax.helpers.AttributesImpl;
 
 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
@@ -90,7 +92,7 @@ public abstract class ParseResult
                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
        {
@@ -179,5 +181,24 @@ public abstract class ParseResult
                // 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;
+       }
 }