import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.URIUtil;
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.Activator;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
*
* @author Alexandre Montplaisir
*/
+@NonNullByDefault
public final class TmfTraceManager {
// ------------------------------------------------------------------------
private final Map<ITmfTrace, TmfTraceContext> fTraces;
/** The currently-selected trace. Should always be part of the trace map */
- private ITmfTrace fCurrentTrace = null;
+ private @Nullable ITmfTrace fCurrentTrace = null;
private static final String TEMP_DIR_NAME = ".temp"; //$NON-NLS-1$
}
/** Singleton instance */
- private static TmfTraceManager tm = null;
+ private static @Nullable TmfTraceManager tm = null;
/**
* Get an instance of the trace manager.
* @return The trace manager
*/
public static synchronized TmfTraceManager getInstance() {
- if (tm == null) {
- tm = new TmfTraceManager();
+ TmfTraceManager mgr = tm;
+ if (mgr == null) {
+ mgr = new TmfTraceManager();
+ tm = mgr;
}
- return tm;
+ return mgr;
}
// ------------------------------------------------------------------------
/**
* Get the currently selected trace (normally, the focused editor).
*
- * @return The active trace
+ * @return The active trace, or <code>null</code> if there is no active
+ * trace
*/
- public synchronized ITmfTrace getActiveTrace() {
+ public synchronized @Nullable ITmfTrace getActiveTrace() {
return fCurrentTrace;
}
/**
* Get the trace set of the currently active trace.
*
- * @return The active trace set
+ * @return The active trace set. Empty (but non-null) if there is no
+ * currently active trace.
* @see #getTraceSet(ITmfTrace)
*/
- public synchronized @NonNull Collection<ITmfTrace> getActiveTraceSet() {
+ public synchronized Collection<ITmfTrace> getActiveTraceSet() {
final ITmfTrace trace = fCurrentTrace;
return getTraceSet(trace);
}
* the trace
* @return the editor file or null if the trace is not opened
*/
- public synchronized IFile getTraceEditorFile(ITmfTrace trace) {
+ public synchronized @Nullable IFile getTraceEditorFile(ITmfTrace trace) {
TmfTraceContext ctx = fTraces.get(trace);
if (ctx != null) {
return ctx.getEditorFile();
* all the traces contained in this experiment.
*
* @param trace
- * The trace or experiment
+ * The trace or experiment. If it is null, an empty collection
+ * will be returned.
* @return The corresponding trace set.
*/
- public static @NonNull Collection<@NonNull ITmfTrace> getTraceSet(ITmfTrace trace) {
+ public static Collection<ITmfTrace> getTraceSet(@Nullable ITmfTrace trace) {
if (trace == null) {
return ImmutableSet.of();
}
* this experiment, along with the experiment.
*
* @param trace
- * The trace or experiment
+ * The trace or experiment. If it is null, an empty collection
+ * will be returned.
* @return The corresponding trace set, including the experiment.
*/
- public static @NonNull Collection<ITmfTrace> getTraceSetWithExperiment(ITmfTrace trace) {
+ public static Collection<ITmfTrace> getTraceSetWithExperiment(@Nullable ITmfTrace trace) {
if (trace == null) {
return ImmutableSet.of();
}
/**
* Signal propagator
- * @param signal any signal
+ *
+ * @param signal
+ * any signal
* @since 2.0
*/
@TmfSignalHandler
- public synchronized void signalReceived(final @NonNull TmfTraceModelSignal signal) {
+ public synchronized void signalReceived(final TmfTraceModelSignal signal) {
fTraces.forEach((t, u) -> u.receive(signal));
}
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
SWTBotUtils.createProject(PROJECT_NAME);
SWTBotUtils.openTrace(PROJECT_NAME, f.getAbsolutePath(), XMLSTUB_ID);
WaitUtils.waitForJobs();
- assertEquals("Incorrect opened trace!", f.getAbsolutePath(), (new File(TmfTraceManager.getInstance().getActiveTrace().getPath())).getAbsolutePath());
+ ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
+ assertNotNull(trace);
+ assertEquals("Incorrect opened trace!", f.getAbsolutePath(), (new File(trace.getPath())).getAbsolutePath());
SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
assertNotNull("Cannot find " + PROJECT_EXPLORER, projectExplorerBot);
projectExplorerBot.show();
fBot.waitUntil(Conditions.shellCloses(shell));
fBot = new SWTWorkbenchBot();
SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(f.getName()));
- assertEquals("Test if import matches", f.getName(), TmfTraceManager.getInstance().getActiveTrace().getName());
- assertFalse("Test if import files don't match", f.getAbsolutePath().equals(TmfTraceManager.getInstance().getActiveTrace().getPath()));
+ trace = TmfTraceManager.getInstance().getActiveTrace();
+ assertNotNull(trace);
+ assertEquals("Test if import matches", f.getName(), trace.getName());
+ assertFalse("Test if import files don't match", f.getAbsolutePath().equals(trace.getPath()));
SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
WaitUtils.waitForJobs();
}