]> jaekl.net Git - cfb.git/commitdiff
Exclude "METHOD_CALLED" references from consideration as a bug's principal location.
authorChris Jaekl <cejaekl@yahoo.com>
Sun, 13 Dec 2015 04:32:47 +0000 (13:32 +0900)
committerChris Jaekl <cejaekl@yahoo.com>
Sun, 13 Dec 2015 04:32:47 +0000 (13:32 +0900)
prod/net/jaekl/cfb/store/Location.java
prod/net/jaekl/cfb/xml/BugInstance.java
test/net/jaekl/cfb/xml/BugInstanceTest.java [new file with mode: 0644]

index 51857eb48c2289ca6aa94991dcec7b2ed4716927..d4d1972dbcb7bb55e6d1c75ff9006a935ab70621 100644 (file)
@@ -8,6 +8,8 @@ import net.jaekl.cfb.xml.BugMethod;
 import net.jaekl.cfb.xml.SourceLine;
 
 public class Location {
+       public static String METHOD_CALLED = "METHOD_CALLED";
+       
        Long m_id;
        String m_className;
        String m_methodName;
index 0683a7d23c83dd1437b08ebe77bd545d01a830f4..b805096c67551c7f3a35847b12f6660bc35acca0 100644 (file)
@@ -212,9 +212,21 @@ public class BugInstance extends ParseResult {
        // This should be the place where the bug is reported.
        Location getPrincipalLocation()
        {
-               if (null != m_locations && m_locations.size() > 0) {
-                       return m_locations.get(0);
+               if (null == m_locations) {
+                       return null;
                }
+               
+               for (int idx = 0; idx < m_locations.size(); ++idx) {
+                       Location loc = m_locations.get(idx);
+                       if (Location.METHOD_CALLED.equals(loc.getMethodRole())) {
+                               // METHOD_CALLED locations describe the method that is being called,
+                               // but the bug is located in the caller, not in the callee.
+                               // Thus, ignore this information about the callee.
+                               continue;
+                       }
+                       return loc;
+               }
+               
                return null;
        }
        
diff --git a/test/net/jaekl/cfb/xml/BugInstanceTest.java b/test/net/jaekl/cfb/xml/BugInstanceTest.java
new file mode 100644 (file)
index 0000000..b7e98fb
--- /dev/null
@@ -0,0 +1,77 @@
+package net.jaekl.cfb.xml;
+
+import static org.junit.Assert.*;
+
+import net.jaekl.cfb.store.Location;
+
+import org.junit.Test;
+
+public class BugInstanceTest {
+
+       @Test
+       public void testGetPrincpalLocation() {
+               Location[][][] data = 
+               {
+                       {
+                               // Location(Long id, String className, String methodName, String methodRole, Integer startLine, Integer endLine)
+                               { 
+                                       // input
+                                       new Location( 1L, "ClassOne", "methodOne", "METHOD_CALLED", 1, 12),
+                                       new Location( 2L, "ClassTwo", "methodTwo", "", 23, 34)
+                               },
+                               {
+                                       // expected result
+                                       new Location( 2L, "ClassTwo", "methodTwo", "", 23, 34)                                          
+                               }
+                       },
+                       {
+                               {
+                                       // input:  empty set
+                               },
+                               {
+                                       // expected result
+                                       null
+                               }
+                       },
+                       {
+                               {
+                                       // input
+                                       new Location( 3L, "ClassThree", "methodThree", null, 34, 45),
+                                       new Location( 4L, "ClassFour",  "methodFour",  null, 45, 56),
+                                       new Location( 5L, "ClassFive",  "methodFive",  null, 56, 67)
+                               },
+                               {
+                                       // expected result
+                                       new Location( 3L, "ClassThree", "methodThree", null, 34, 45),
+                               }
+                       },
+                       {
+                               {
+                                       // input
+                                       new Location( 6L, "CLassSix",   "methodSix",   "METHOD_CALLED", 67, 78)
+                               },
+                               {
+                                       // expected result
+                                       null
+                               }
+                       }
+               };
+               
+               for (Location[][] datum : data) {
+                       Location[] input = datum[0];
+                       Location expected = datum[1][0];
+                       
+                       BugInstance bug = new BugInstance(
+                                               101L, // id
+                                               "CATEGORY",
+                                               "TYPE",
+                                               input,
+                                               new LocalVariable[0]
+                                       );
+                       Location actual = bug.getPrincipalLocation();
+                       
+                       assertEquals(expected, actual);
+               }
+       }
+
+}