[317289] Extract information from Exception objects in the heap dumps

Simple resolver and a test

Change-Id: I75348c81d618c1530f38302ce5e99ad4f710af8c
diff --git a/plugins/org.eclipse.mat.api/plugin.xml b/plugins/org.eclipse.mat.api/plugin.xml
index b329592..ebe275f 100644
--- a/plugins/org.eclipse.mat.api/plugin.xml
+++ b/plugins/org.eclipse.mat.api/plugin.xml
Binary files differ
diff --git a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/CommonNameResolver.java b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/CommonNameResolver.java
index 63c32d3..7c6bc04 100644
--- a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/CommonNameResolver.java
+++ b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/CommonNameResolver.java
@@ -425,4 +425,43 @@
             return r.toString();

         }

     }

+

+    @Subject("java.lang.StackTraceElement")

+    public static class StackTraceElementResolver implements IClassSpecificNameResolver

+    {

+        public String resolve(IObject obj) throws SnapshotException

+        {

+            IObject cls = (IObject)obj.resolveValue("declaringClass");

+            IObject methodName = (IObject)obj.resolveValue("methodName");

+            if (cls == null || methodName == null)

+                return null;

+            int line = (Integer)obj.resolveValue("lineNumber");

+            IObject fn = (IObject)obj.resolveValue("fileName");

+            String ln;

+            if (line == -2)

+                ln = "(Compiled Code)";

+            else if (line == -3)

+                ln = "(Native Method)";

+            else if (line == -1)

+                ln = "";

+            else if (line == 0)

+                ln = "";

+            else

+                ln = Integer.toString(line);

+            String name;

+            if (fn == null)

+                if (line > 0)

+                    name = cls.getClassSpecificName() + "." + methodName.getClassSpecificName() + "() " + ln;

+                else

+                    name = cls.getClassSpecificName() + "." + methodName.getClassSpecificName() + "()";

+            else

+                if (line > 0)

+                    name = cls.getClassSpecificName() + "." + methodName.getClassSpecificName() + "() ("

+                                + fn.getClassSpecificName() + ":" + ln + ")";

+                else

+                    name = cls.getClassSpecificName() + "." + methodName.getClassSpecificName() + "() ("

+                                    + fn.getClassSpecificName() + ")";

+            return name;

+        }

+    }

 }

diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/GeneralSnapshotTests.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/GeneralSnapshotTests.java
index 2337e7f..061e1c3 100644
--- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/GeneralSnapshotTests.java
+++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/GeneralSnapshotTests.java
@@ -22,6 +22,7 @@
 import static org.junit.Assert.assertSame;

 import static org.junit.Assert.assertThat;

 import static org.junit.Assert.assertTrue;

+import static org.junit.Assume.assumeNotNull;

 import static org.junit.Assume.assumeThat;

 import static org.junit.Assume.assumeTrue;

 

@@ -455,7 +456,7 @@
     }

 

     /**

-     * Test value of Strings

+     * Test value of {@link java.lang.String}

      */

     @Test

     public void stringToString() throws SnapshotException

@@ -488,7 +489,7 @@
     }

     

     /**

-     * Test value of Strings

+     * Test value of {@link java.lang.StringBuilder}

      */

     @Test

     public void stringBuilderToString() throws SnapshotException

@@ -512,7 +513,7 @@
     }

     

     /**

-     * Test value of StringBuffers

+     * Test value of {@link java.lang.StringBuffer}

      */

     @Test

     public void stringBufferToString() throws SnapshotException

@@ -534,7 +535,32 @@
         }

         assertThat(printables, greaterThanOrEqualTo(objects * 2 / 3));

     }

-    

+

+    /**

+     * Test value of {@link java.lang.StackTraceElement}

+     */

+    @Test

+    public void stackFrameElementResolver() throws SnapshotException

+    {

+        int objects = 0;

+        int printables = 0;

+        assumeThat(snapshot.getSnapshotInfo().getProperty("$heapFormat"), not(equalTo((Serializable)"DTFJ-PHD")));

+        Collection<IClass>tClasses = snapshot.getClassesByName("java.lang.StackTraceElement", true);

+        assumeNotNull(tClasses);

+        for (IClass cls : tClasses)

+        {

+            for (int id : cls.getObjectIds()) {

+                IObject o = snapshot.getObject(id);

+                String cn = o.getClassSpecificName();

+                if (cn != null && cn.length() > 0)

+                {

+                    ++printables;

+                }

+            }

+        }

+        assertThat(printables, greaterThanOrEqualTo(objects * 2 / 3));

+    }

+

     /**

      * Test caching of snapshots

      * @throws SnapshotException