tmf: annotate TmfContext#location as nullable
[deliverable/tracecompass.git] / btf / org.eclipse.tracecompass.btf.core / src / org / eclipse / tracecompass / btf / core / trace / BtfTrace.java
index ef796b9320429e4ea240fa142595bdd3eba6387f..8d938a083c6c696fb8cb5f467a607da8ad6c1ba2 100644 (file)
@@ -29,6 +29,7 @@ import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.btf.core.Activator;
 import org.eclipse.tracecompass.btf.core.event.BtfEvent;
 import org.eclipse.tracecompass.btf.core.event.BtfEventType;
@@ -38,11 +39,11 @@ import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceContext;
+import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceProperties;
 import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
@@ -62,7 +63,7 @@ import com.google.common.collect.ImmutableMap;
  *
  * @author Matthew Khouzam
  */
-public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITmfTraceProperties {
+public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITmfPropertiesProvider {
 
     private static final int MAX_FIELDS = 7;
 
@@ -93,11 +94,11 @@ public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITm
 
     private static int fCheckpointSize = -1;
 
-    private final Map<String, String> fProperties = new HashMap<>();
+    private final @NonNull Map<String, String> fProperties = new HashMap<>();
 
-    private final Map<Integer, String> fEntityTable = new TreeMap<>();
-    private final Map<BtfEventType, String> fEntityTypeTable = new HashMap<>();
-    private final Map<Integer, BtfEventType> fEntityTypes = new TreeMap<>();
+    private final @NonNull Map<Integer, String> fEntityTable = new TreeMap<>();
+    private final @NonNull Map<BtfEventType, String> fEntityTypeTable = new HashMap<>();
+    private final @NonNull Map<Integer, BtfEventType> fEntityTypes = new TreeMap<>();
 
     private String fVersion;
     private String fCreator;
@@ -143,7 +144,8 @@ public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITm
                 fProperties.put(CREATIONDATE, fCreationDate);
 
                 try {
-                    // DateFormats are inherently unsafe for multithreaded use so we can't make this a field. Just in case.
+                    // DateFormats are inherently unsafe for multithreaded use
+                    // so we can't make this a field. Just in case.
                     final SimpleDateFormat ISO8601DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"); //$NON-NLS-1$
                     Date dateTime = ISO8601DATEFORMAT.parse(fCreationDate);
                     fTsOffset = dateTime.getTime() * MICROSECONDS_IN_A_SECOND;
@@ -362,9 +364,10 @@ public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITm
         }
 
         final TmfContext context = (TmfContext) tmfContext;
-        if (context.getLocation() == null
-                || !(context.getLocation().getLocationInfo() instanceof Long)
-                || NULL_LOCATION.equals(context.getLocation())) {
+        ITmfLocation location = context.getLocation();
+        if (location == null
+                || !(location.getLocationInfo() instanceof Long)
+                || NULL_LOCATION.equals(location)) {
             return null;
         }
 
@@ -380,21 +383,24 @@ public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITm
      * @return the event from a given line
      */
     private ITmfEvent parseLine(TmfContext context) {
-        try {
-            if (!context.getLocation().getLocationInfo().equals(fFileInput.getFilePointer())) {
-                seekEvent(context.getLocation());
+        ITmfLocation location = context.getLocation();
+        if (location != null) {
+            try {
+                if (!location.getLocationInfo().equals(fFileInput.getFilePointer())) {
+                    seekEvent(location);
+                }
+            } catch (IOException e1) {
+                seekEvent(location);
             }
-        } catch (IOException e1) {
-            seekEvent(context.getLocation());
-        }
-        String line;
-        try {
-            line = fFileInput.readLine();
-            return parseLine(context.getRank(), line);
+            String line;
+            try {
+                line = fFileInput.readLine();
+                return parseLine(context.getRank(), line);
 
-        } catch (IOException e) {
+            } catch (IOException e) {
+                Activator.logError(e.getMessage(), e);
+            }
         }
-
         return null;
     }
 
@@ -470,13 +476,16 @@ public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITm
         return new TmfBTreeTraceIndexer(this, interval);
     }
 
+    /**
+     * @since 2.0
+     */
     @Override
-    public Map<String, String> getTraceProperties() {
+    public Map<String, String> getProperties() {
         return ImmutableMap.copyOf(fProperties);
     }
 
     @Override
-    public Iterable<ITmfEventAspect> getEventAspects() {
+    public Iterable<ITmfEventAspect<?>> getEventAspects() {
         return BtfEventAspects.getAspects();
     }
 
@@ -498,9 +507,11 @@ public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITm
         if (signal.getTrace() == this) {
             try {
                 synchronized (this) {
-                    // Reset the file handle in case it has reached the end of the
-                    // file already. Otherwise, it will not be able to read new data
-                    // pass the previous end.
+                    /*
+                     * Reset the file handle in case it has reached the end of
+                     * the file already. Otherwise, it will not be able to read
+                     * new data pass the previous end.
+                     */
                     initFile();
                 }
             } catch (TmfTraceException e) {
This page took 0.030713 seconds and 5 git commands to generate.