Use the NonNull utility methods where we can
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / statesystem / TmfStateSystemAnalysisModule.java
index 8ce4dcc447324462b43c70a61a71f705c74e273e..9a087a341f7a14261043ecaf35feb3bf4108783a 100644 (file)
@@ -13,6 +13,8 @@
 
 package org.eclipse.tracecompass.tmf.core.statesystem;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.io.File;
 import java.io.IOException;
 import java.util.Collections;
@@ -21,7 +23,6 @@ import java.util.concurrent.CountDownLatch;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.tmf.core.statesystem.backends.partial.PartialHistoryBackend;
@@ -44,8 +45,9 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceCompleteness;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 
 /**
  * Abstract analysis module to generate a state system. It is a base class that
@@ -92,7 +94,6 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         PARTIAL
     }
 
-
     /**
      * Retrieve a state system belonging to trace, by passing the ID of the
      * relevant analysis module.
@@ -109,7 +110,37 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
      */
     public static @Nullable ITmfStateSystem getStateSystem(ITmfTrace trace, String moduleId) {
         TmfStateSystemAnalysisModule module =
-                trace.getAnalysisModuleOfClass(TmfStateSystemAnalysisModule.class, moduleId);
+                TmfTraceUtils.getAnalysisModuleOfClass(trace, TmfStateSystemAnalysisModule.class, moduleId);
+        if (module != null) {
+            IStatus status = module.schedule();
+            if (status.isOK()) {
+                module.waitForInitialization();
+                return module.getStateSystem();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Retrieve a state system belonging to trace, by passing the class of the
+     * relevant analysis module. If many modules of the same class exists, the
+     * state system of the first one will be returned.
+     *
+     * This will start the execution of the analysis module, and start the
+     * construction of the state system, if needed.
+     *
+     * @param trace
+     *            The trace for which you want the state system
+     * @param clazz
+     *            The class of the state system module to retrieve
+     * @return The state system, or null if there was no match
+     */
+    public static @Nullable ITmfStateSystem getStateSystemByModuleClass(ITmfTrace trace, Class<? extends TmfStateSystemAnalysisModule> clazz) {
+        TmfStateSystemAnalysisModule module = null;
+        for (TmfStateSystemAnalysisModule mod : TmfTraceUtils.getAnalysisModulesOfClass(trace, clazz)) {
+            module = mod;
+            break;
+        }
         if (module != null) {
             IStatus status = module.schedule();
             if (status.isOK()) {
@@ -455,9 +486,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
             this.sci = sp;
 
             // sci.getTrace() will eventually return a @NonNull
-            @SuppressWarnings("null")
-            @NonNull ITmfTrace tr = sci.getTrace();
-            trace = tr;
+            trace = checkNotNull(sci.getTrace());
 
         }
 
@@ -527,9 +556,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
 
     @Override
     public Iterable<ITmfStateSystem> getStateSystems() {
-        @SuppressWarnings("null")
-        @NonNull Iterable<ITmfStateSystem> ret = Collections.singleton((ITmfStateSystem) fStateSystem);
-        return ret;
+        return checkNotNull(Collections.<ITmfStateSystem> singleton(fStateSystem));
     }
 
     /**
This page took 0.025374 seconds and 5 git commands to generate.