tmf: Add generics to ITmfEventAspect
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / stubs / org / eclipse / tracecompass / tmf / tests / stubs / trace / xml / TmfXmlTraceStub.java
index f6c3ac83a1940941555ac1eaab3a643aae526512..ccb079d1a7961902dc2c19d5773b2515f76e8047 100644 (file)
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Collection;
+import java.util.HashSet;
 
 import javax.xml.XMLConstants;
 import javax.xml.transform.Source;
@@ -98,7 +99,8 @@ public class TmfXmlTraceStub extends TmfTrace {
     private final CustomXmlTraceDefinition fDefinition;
     private CustomXmlTrace fTrace;
 
-    private Collection<ITmfEventAspect> fAspects = TmfTrace.BASE_ASPECTS;
+    private Collection<ITmfEventAspect<?>> fAspects = TmfTrace.BASE_ASPECTS;
+    private final Collection<ITmfEventAspect<?>> fAdditionalAspects = new HashSet<>();
 
     /**
      * Constructor. Constructs the custom XML trace with the appropriate
@@ -293,7 +295,10 @@ public class TmfXmlTraceStub extends TmfTrace {
             fieldsArray[i] = new TmfEventField(checkNotNull(fields[i]), val, null);
         }
 
-        /* Generate the aspects for this trace if it is the 'set_aspects' definition */
+        /*
+         * Generate the aspects for this trace if it is the 'set_aspects'
+         * definition
+         */
         if (fTrace.getDefinition() != fDefinition) {
             generateAspects(fieldsArray);
             return null;
@@ -317,7 +322,7 @@ public class TmfXmlTraceStub extends TmfTrace {
     }
 
     private void generateAspects(ITmfEventField[] fieldsArray) {
-        ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>();
+        ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
 
         /* Initialize the first default trace aspects */
         builder.add(ITmfEventAspect.BaseAspects.TIMESTAMP);
@@ -326,7 +331,7 @@ public class TmfXmlTraceStub extends TmfTrace {
         /* Add custom aspects in between */
         for (ITmfEventField field : fieldsArray) {
             String name = field.getName();
-            final ITmfEventAspect aspect = new TmfContentFieldAspect(name, name);
+            final ITmfEventAspect<?> aspect = new TmfContentFieldAspect(name, name);
             if (name.equals(ASPECT_CPU)) {
                 builder.add(new TmfCpuAspect() {
                     @Override
@@ -345,12 +350,29 @@ public class TmfXmlTraceStub extends TmfTrace {
 
         /* Add the big content aspect */
         builder.add(ITmfEventAspect.BaseAspects.CONTENTS);
+        /* Add the additional aspects */
+        builder.addAll(fAdditionalAspects);
         fAspects = builder.build();
     }
 
     @Override
-    public Iterable<ITmfEventAspect> getEventAspects() {
+    public Iterable<ITmfEventAspect<?>> getEventAspects() {
         return fAspects;
     }
 
+    /**
+     * Adds a new event aspect to this type of trace. Since this trace type is
+     * used to build custom traces that mimic the behavior of real traces, the
+     * required aspects may be missing and this method allows to add them. This
+     * method should be called before calling
+     * {@link #initTrace(IResource, String, Class)} otherwise the additional
+     * aspects will not be picked up when generating the aspects.
+     *
+     * @param aspect
+     *            The aspect to have
+     */
+    public void addEventAspect(ITmfEventAspect<?> aspect) {
+        fAdditionalAspects.add(aspect);
+    }
+
 }
This page took 0.029088 seconds and 5 git commands to generate.