tmf: bug 494698 Add per-event fields to custom parsers
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / parsers / custom / CustomEventAspects.java
index 060532013c46fb7f040cc7f21a68b547055ca503..4b52cebad7093bcc8f532dacbc65bd57f5a60d0c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
 
 package org.eclipse.tracecompass.internal.tmf.core.parsers.custom;
 
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
+import java.util.ArrayList;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
-import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomEvent;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 
 import com.google.common.collect.ImmutableList;
 
@@ -39,48 +39,6 @@ import com.google.common.collect.ImmutableList;
  */
 public class CustomEventAspects {
 
-    /**
-     * Aspects for custom events, which use an integer ID to represent each
-     * field.
-     */
-    private static final class CustomEventFieldAspect implements ITmfEventAspect {
-
-        private final @NonNull String fName;
-        private final int fIndex;
-
-        /**
-         * Constructor
-         *
-         * @param name
-         *            The name of this aspect
-         * @param idx
-         *            The index of this field in the event's content to display
-         */
-        public CustomEventFieldAspect(@NonNull String name, int idx) {
-            fName = name;
-            fIndex = idx;
-        }
-
-        @Override
-        public String getName() {
-            return fName;
-        }
-
-        @Override
-        public String getHelpText() {
-            return EMPTY_STRING;
-        }
-
-        @Override
-        public String resolve(ITmfEvent event) {
-            if (event instanceof CustomEvent) {
-                String ret = ((CustomEvent) event).getEventString(fIndex);
-                return (ret == null ? EMPTY_STRING : ret);
-            }
-            return EMPTY_STRING;
-        }
-    }
-
     /**
      * Build a set of event aspects for a given trace definition
      *
@@ -89,15 +47,28 @@ public class CustomEventAspects {
      *            want the aspects
      * @return The set of event aspects for the given trace
      */
-    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++) {
-            String name = outputs.get(i).name;
-            if (name != null) {
-                builder.add(new CustomEventFieldAspect(name, i));
+    public static @NonNull Iterable<ITmfEventAspect<?>> generateAspects(CustomTraceDefinition definition) {
+        List<String> fieldNames = new ArrayList<>();
+        ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
+        for (OutputColumn output : definition.outputs) {
+
+            if (output.tag.equals(Tag.TIMESTAMP) &&
+                    (definition.timeStampOutputFormat == null || definition.timeStampOutputFormat.isEmpty())) {
+                builder.add(TmfBaseAspects.getTimestampAspect());
+                fieldNames.add(output.name);
+            } else if (output.tag.equals(Tag.EVENT_TYPE)) {
+                builder.add(TmfBaseAspects.getEventTypeAspect());
+                fieldNames.add(output.name);
+            } else if (output.tag.equals(Tag.EXTRA_FIELD_NAME) || output.tag.equals(Tag.EXTRA_FIELD_VALUE)) {
+                // These tags should have been substituted with Tag.EXTRA_FIELDS
+                continue;
+            } else if (output.tag.equals(Tag.EXTRA_FIELDS)) {
+                builder.add(new CustomExtraFieldsAspect());
+            } else {
+                builder.add(new TmfContentFieldAspect(output.name, output.name));
+                fieldNames.add(output.name);
             }
         }
-        return checkNotNull(builder.build());
+        return builder.build();
     }
 }
This page took 0.024784 seconds and 5 git commands to generate.