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 38ba9b8a0b781b7dfa8aaf16cf754966b6d4dfbe..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
@@ -63,6 +69,7 @@ public class FunctionNameMapper {
         try (FileReader fr = new FileReader(mappingFile);
                 BufferedReader reader = new BufferedReader(fr);) {
             for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+                line = line.trim();
                 /* Only lines with 3 elements contain addresses */
                 String[] elems = line.split(" ", 3); //$NON-NLS-1$
                 if (elems.length == 3) {
@@ -80,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);
     }
 
     /**
@@ -112,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) {
@@ -179,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.029905 seconds and 5 git commands to generate.