tmf: Make ITmfTrace.getEventAspects() @NonNull
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 21 Nov 2014 02:02:50 +0000 (21:02 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 28 Nov 2014 23:07:56 +0000 (18:07 -0500)
It's easier to deal with empty collections than dealing with
null/non-null references (for Collection.addAll() and such).

Change-Id: I9e8d0091e099027b5da0c15881b73130b4ef2e9d
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/37121
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Hudson CI
org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/trace/BtfEventAspects.java
org.eclipse.tracecompass.gdbtrace.core/src/org/eclipse/tracecompass/internal/gdbtrace/core/trace/GdbEventAspects.java
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/trace/TmfTraceUtilsTest.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/parsers/custom/CustomEventAspects.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/ITmfTrace.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTrace.java
org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/editors/TmfEventsEditor.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventsTable.java

index 45b5a46e65a3bafc8749783818298a705bc6c48f..5b5ab35e3e8104f4c2158c775bc690d6bf64fe4d 100644 (file)
@@ -151,7 +151,7 @@ public final class BtfEventAspects {
      *
      * @return The aspects
      */
-    public static Iterable<ITmfEventAspect> getAspects() {
+    public static @NonNull Iterable<ITmfEventAspect> getAspects() {
         return BTF_ASPECTS;
     }
 }
\ No newline at end of file
index 2d5f21d48d935d8bb023ed8d13cfd0b5bc0c1a00..9debbec986e65c01d1cd88888f093784297202b8 100644 (file)
@@ -83,7 +83,7 @@ public final class GdbEventAspects {
      *
      * @return The set of aspects
      */
-    public static Iterable<ITmfEventAspect> getAspects() {
+    public static @NonNull Iterable<ITmfEventAspect> getAspects() {
         return GDB_ASPECTS;
     }
 }
index 9e100f1efd17e9f3784d417c6f1b3ad68cfa5ecc..34b06a81787bfde350d7d31d8aed6979196fc1b1 100644 (file)
@@ -27,6 +27,7 @@ import java.util.Iterator;
 
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
@@ -63,7 +64,7 @@ public class TmfTraceUtilsTest {
 
     private static class TmfTraceStubWithAspects extends TmfTraceStub {
 
-        private static final Collection<ITmfEventAspect> EVENT_ASPECTS;
+        private static final @NonNull Collection<ITmfEventAspect> EVENT_ASPECTS;
         static {
             ImmutableList.Builder<ITmfEventAspect> builder = ImmutableList.builder();
             builder.add(new TmfCpuAspect() {
@@ -77,7 +78,9 @@ public class TmfTraceUtilsTest {
                 }
             });
             builder.addAll(TmfTrace.BASE_ASPECTS);
-            EVENT_ASPECTS = builder.build();
+            @SuppressWarnings("null")
+            @NonNull Collection<ITmfEventAspect> ret = builder.build();
+            EVENT_ASPECTS = ret;
         }
 
         public TmfTraceStubWithAspects(String path) throws TmfTraceException {
index d0956c92795042a081ea2d473e908c723d82db73..461c6e12e6c9eb019fc9dff598eaee071f545bfb 100644 (file)
@@ -92,7 +92,7 @@ public class CustomEventAspects {
      *            want the aspects
      * @return The set of event aspects for the given trace
      */
-    public static Iterable<ITmfEventAspect> generateAspects(CustomTraceDefinition definition) {
+    public static @NonNull Iterable<ITmfEventAspect> generateAspects(CustomTraceDefinition definition) {
         ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>();
         List<OutputColumn> outputs = definition.outputs;
         for (int i = 0; i < outputs.size(); i++) {
@@ -101,6 +101,8 @@ public class CustomEventAspects {
                 builder.add(new CustomEventFieldAspect(name, i));
             }
         }
-        return builder.build();
+        @SuppressWarnings("null")
+        @NonNull Iterable<ITmfEventAspect> ret = builder.build();
+        return ret;
     }
 }
index aede3ca57d7d0ff2f9fb0aeca32229f485338e7b..ac76479cff9afa95e9216466adbf1ebb07411639 100644 (file)
@@ -260,9 +260,12 @@ public interface ITmfTrace extends ITmfEventProvider {
     /**
      * Return the pre-defined set of event aspects exposed by this trace.
      *
+     * It should not be null, but could be empty. You are suggested to use at
+     * least the ones defined in {@link TmfTrace#BASE_ASPECTS}.
+     *
      * @return The event aspects for this trace
      */
-    Iterable<ITmfEventAspect> getEventAspects();
+    @NonNull Iterable<ITmfEventAspect> getEventAspects();
 
     // ------------------------------------------------------------------------
     // Trace characteristics getters
index 07cc7d348eb0bbafebb7eed077fc75ed1157b62f..f3cebbde705acce7118d1ca8f321a17a980b21a7 100644 (file)
@@ -97,7 +97,8 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace, IT
     /**
      * Basic aspects that should be valid for all trace types.
      */
-    public static final Collection<ITmfEventAspect> BASE_ASPECTS =
+    @SuppressWarnings("null")
+    public static final @NonNull Collection<ITmfEventAspect> BASE_ASPECTS =
             ImmutableList.of(
                     ITmfEventAspect.BaseAspects.TIMESTAMP,
                     ITmfEventAspect.BaseAspects.EVENT_TYPE,
index 7020c4cdd1cf6cab931173b1048ef264575e1e45..2e28ce22ccc6efe5a537153aef77b962190ca3fa 100644 (file)
@@ -29,6 +29,7 @@ import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.ctf.core.event.CTFClock;
 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
 import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
@@ -91,7 +92,8 @@ public class CtfTmfTrace extends TmfTrace
     /**
      * Event aspects available for all CTF traces
      */
-    private static final Collection<ITmfEventAspect> CTF_ASPECTS =
+    @SuppressWarnings("null")
+    private static final @NonNull Collection<ITmfEventAspect> CTF_ASPECTS =
             ImmutableList.of(
                     ITmfEventAspect.BaseAspects.TIMESTAMP,
                     new CtfChannelAspect(),
index 34ac6d5fe6d306f6b37629125e31b1b022952276..42a2f0799a66afb79b2f3f8534833bb333770e48 100644 (file)
@@ -321,17 +321,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus
          * The trace type did not specify an event table, we will use a standard
          * table with the trace's advertised aspects (if any).
          */
-        Iterable<ITmfEventAspect> aspects = trace.getEventAspects();
-        if (aspects != null) {
-            return new TmfEventsTable(parent, cacheSize, aspects);
-        }
-
-        /*
-         * No columns were defined either, use a default table with the default
-         * columns.
-         */
-        return new TmfEventsTable(parent, cacheSize);
-
+        return new TmfEventsTable(parent, cacheSize, trace.getEventAspects());
     }
 
     /**
@@ -370,12 +360,8 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus
 
         for (ITmfTrace trace : traces) {
             Iterable<ITmfEventAspect> traceAspects = trace.getEventAspects();
-            if (traceAspects == null) {
-                aspects.addAll(TmfTrace.BASE_ASPECTS);
-            } else {
-                for (ITmfEventAspect aspect : traceAspects) {
-                    aspects.add(aspect);
-                }
+            for (ITmfEventAspect aspect : traceAspects) {
+                aspects.add(aspect);
             }
         }
 
index ba59d67d243371c7d95fb8ca0dbda35f1f550021..958ba549b769d63cf01cdbea57f9913e7d9aa6e6 100644 (file)
@@ -350,7 +350,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
     }
 
     @Deprecated
-    private static Iterable<ITmfEventAspect> convertFromColumnData(
+    private static @NonNull Iterable<ITmfEventAspect> convertFromColumnData(
             org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData[] columnData) {
 
         ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>();
@@ -360,7 +360,9 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                 builder.add(new TmfEventFieldAspect(fieldName, fieldName));
             }
         }
-        return builder.build();
+        @SuppressWarnings("null")
+        @NonNull Iterable<ITmfEventAspect> ret = builder.build();
+        return ret;
     }
 
     /**
@@ -380,7 +382,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
      * @since 3.1
      */
     public TmfEventsTable(final Composite parent, int cacheSize,
-            Iterable<ITmfEventAspect> aspects) {
+            @NonNull Iterable<ITmfEventAspect> aspects) {
         super("TmfEventsTable"); //$NON-NLS-1$
 
         fComposite = new Composite(parent, SWT.NONE);
@@ -406,11 +408,9 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
         fTable.setLinesVisible(true);
 
         // Setup the columns
-        if (aspects != null) {
-            for (ITmfEventAspect aspect : aspects) {
-                if (aspect != null) {
-                    fColumns.add(new TmfEventTableColumn(aspect));
-                }
+        for (ITmfEventAspect aspect : aspects) {
+            if (aspect != null) {
+                fColumns.add(new TmfEventTableColumn(aspect));
             }
         }
 
This page took 0.070768 seconds and 5 git commands to generate.