analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / callstack / FunctionNameMapper.java
index 5fa9f45ab5dd1ec0356f04ee2de599702b9034a2..d118252c4bf0f31a06465d96dd8ae5024994343c 100644 (file)
@@ -21,10 +21,10 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.IBinaryParser;
@@ -39,12 +39,18 @@ import org.eclipse.core.runtime.SafeRunner;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
 
+import com.google.common.collect.ImmutableMap;
+
 /**
  * Class containing the different methods to import an address->name mapping.
  *
  * @author Alexandre Montplaisir
  */
-public class FunctionNameMapper {
+public final class FunctionNameMapper {
+
+    private FunctionNameMapper() {}
+
+    private static final Pattern REMOVE_ZEROS_PATTERN = Pattern.compile("^0+(?!$)"); //$NON-NLS-1$
 
     /**
      * Get the function name mapping from a text file obtained by doing
@@ -81,14 +87,7 @@ public class FunctionNameMapper {
         if (map.isEmpty()) {
             return null;
         }
-        return Collections.unmodifiableMap(map);
-    }
-
-    /**
-     * Strip the leading zeroes from the address
-     * */
-    private static String stripLeadingZeros(String address) {
-        return address.replaceFirst("^0+(?!$)", "");  //$NON-NLS-1$ //$NON-NLS-2$;
+        return ImmutableMap.copyOf(map);
     }
 
     /**
@@ -113,7 +112,15 @@ public class FunctionNameMapper {
             }
         }
 
-        return map;
+        return ImmutableMap.copyOf(map);
+    }
+
+
+    /**
+     * Strip the leading zeroes from the address
+     * */
+    private static String stripLeadingZeros(String address) {
+        return REMOVE_ZEROS_PATTERN.matcher(address).replaceFirst(""); //$NON-NLS-1$
     }
 
     private static @Nullable IBinaryParser.IBinaryObject getBinaryObject(File file) {
@@ -180,7 +187,7 @@ public class FunctionNameMapper {
                 IBinaryFile binFile;
                 try {
                     binFile = parser.getBinary(hintBuffer, filePath);
-                    if (binFile != null && binFile instanceof IBinaryParser.IBinaryObject) {
+                    if (binFile instanceof IBinaryParser.IBinaryObject) {
                         return (IBinaryParser.IBinaryObject)binFile;
                     }
                 } catch (IOException e) {
This page took 0.026569 seconds and 5 git commands to generate.