tmf.core: make ITmfCallsite getFileName @NonNull
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 1 Oct 2015 02:03:24 +0000 (22:03 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 2 Oct 2015 20:13:47 +0000 (16:13 -0400)
Change-Id: Ie93ca879cb2954bb86eaf68f3dea40fb056b6c2e
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/42916
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/event/lookup/TmfCallsiteTest.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/event/lookup/ITmfCallsite.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/event/lookup/TmfCallsite.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventsTable.java

index 6dcaffb83793af6f83aa183c3918884e7d9005cb..644e3757f86630d038def2a82f794820571a55d7 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
+ * Copyright (c) 2013, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -41,9 +41,14 @@ public class TmfCallsiteTest {
     private final static String fFunctionName3 = null;
     private final static long fLine3 = 123;
 
+    private final static String fFileName4 = "filename1";
+    private final static String fFunctionName4 = "func1";
+    private final static long fLine4 = 11;
+
     private final static ITmfCallsite fCallsite1 = new TmfCallsite(fFileName1, fFunctionName1, fLine1);
     private final static ITmfCallsite fCallsite2 = new TmfCallsite(fFileName2, fFunctionName2, fLine2);
     private final static ITmfCallsite fCallsite3 = new TmfCallsite(fFileName3, fFunctionName3, fLine3);
+    private final static ITmfCallsite fCallsite4 = new TmfCallsite(fFileName4, fFunctionName4, fLine4);
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -58,39 +63,19 @@ public class TmfCallsiteTest {
 
     @Test
     public void testCallsiteCopy() {
-        TmfCallsite copy =  new TmfCallsite(fCallsite1);
+        TmfCallsite copy = new TmfCallsite(fCallsite1);
 
         assertEquals(fFileName1, copy.getFileName());
         assertEquals(fFunctionName1, copy.getFunctionName());
         assertEquals(fLine1, copy.getLineNumber());
     }
 
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testCallsiteCopy2() {
         new TmfCallsite(null);
     }
 
-    @Test(expected=IllegalArgumentException.class)
-    public void testCallsiteCopy3() {
-        new TmfCallsite(new ITmfCallsite() {
-            @Override
-            public long getLineNumber() {
-                return 0;
-            }
-
-            @Override
-            public String getFunctionName() {
-                return null;
-            }
-
-            @Override
-            public String getFileName() {
-                return null;
-            }
-        });
-    }
-
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testCallsiteFileNull() {
         new TmfCallsite(null, fFunctionName1, fLine1);
     }
@@ -103,12 +88,11 @@ public class TmfCallsiteTest {
     public void testHashCode() {
         final ITmfCallsite callsite1b = new TmfCallsite(fCallsite1);
         final ITmfCallsite callsite2b = new TmfCallsite(fCallsite2);
+        final ITmfCallsite callsite3b = new TmfCallsite(fCallsite3);
 
-        assertTrue("hashCode", fCallsite1.hashCode() == callsite1b.hashCode());
-        assertTrue("hashCode", fCallsite2.hashCode() == callsite2b.hashCode());
-
-        assertTrue("hashCode", fCallsite1.hashCode() != fCallsite2.hashCode());
-        assertTrue("hashCode", fCallsite2.hashCode() != fCallsite1.hashCode());
+        assertEquals("hashCode", fCallsite1.hashCode(), callsite1b.hashCode());
+        assertEquals("hashCode", fCallsite2.hashCode(), callsite2b.hashCode());
+        assertEquals("hashCode", fCallsite3.hashCode(), callsite3b.hashCode());
     }
 
     // ------------------------------------------------------------------------
@@ -122,6 +106,8 @@ public class TmfCallsiteTest {
 
         assertFalse("equals", fCallsite1.equals(fCallsite2));
         assertFalse("equals", fCallsite2.equals(fCallsite1));
+        assertFalse("equals", fCallsite1.equals(fCallsite4));
+        assertFalse("equals", fCallsite4.equals(fCallsite1));
     }
 
     @Test
index e74b7dade315232e5ebd282072c0874b07ea475e..4954388e318a6e579f6076a5c9d140024e883550 100644 (file)
@@ -12,6 +12,7 @@
 
 package org.eclipse.tracecompass.tmf.core.event.lookup;
 
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * The generic call site structure in TMF. A call site has:
@@ -32,7 +33,7 @@ public interface ITmfCallsite {
      *
      * @return the file name
      */
-    String getFileName();
+    @NonNull String getFileName();
 
     /**
      * Returns the function name of the call site.
index e09907be08d10d09de51da8ef02351402fe4a269..9e61bb38d63705e1a985b66e51ee6d4e50b62a87 100644 (file)
@@ -14,6 +14,8 @@ package org.eclipse.tracecompass.tmf.core.event.lookup;
 
 import static org.eclipse.tracecompass.common.core.NonNullUtils.equalsNullable;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * TMF call site information for source code lookup.
  *
@@ -26,7 +28,7 @@ public class TmfCallsite implements ITmfCallsite {
     // ------------------------------------------------------------------------
 
     /** The file name string. */
-    private final String fFileName;
+    private final @NonNull String fFileName;
 
     /** The function name. */
     private final String fFunctionName;
@@ -64,7 +66,7 @@ public class TmfCallsite implements ITmfCallsite {
      *            - An other call site implementation
      */
     public TmfCallsite(ITmfCallsite other) {
-        if ((other == null) || (other.getFileName() == null)) {
+        if (other == null) {
             throw new IllegalArgumentException();
         }
         fFileName = other.getFileName();
@@ -77,7 +79,7 @@ public class TmfCallsite implements ITmfCallsite {
     // ------------------------------------------------------------------------
 
     @Override
-    public String getFileName() {
+    public @NonNull String getFileName() {
         return fFileName;
     }
 
index 7786c3ff543cca39dce83e26bf68f0c0a8be9b04..e4cc672a0261e50d8d03192747d05816d95c9ff8 100644 (file)
@@ -1018,13 +1018,16 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                 if (data instanceof ITmfSourceLookup) {
                     ITmfSourceLookup event = (ITmfSourceLookup) data;
                     ITmfCallsite cs = event.getCallsite();
-                    if (cs == null || cs.getFileName() == null) {
+                    if (cs == null) {
                         return;
                     }
                     IMarker marker = null;
                     try {
                         String fileName = cs.getFileName();
                         final String trimmedPath = fileName.replaceAll("\\.\\./", EMPTY_STRING); //$NON-NLS-1$
+                        if (trimmedPath.isEmpty()) {
+                            return;
+                        }
                         final ArrayList<IFile> files = new ArrayList<>();
                         ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() {
                             @Override
This page took 0.029441 seconds and 5 git commands to generate.