ctf: introducing the ICompositeDefinition
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 8 Jul 2014 20:04:30 +0000 (16:04 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 10 Jul 2014 01:29:15 +0000 (21:29 -0400)
This is a definition that contains subfields.

Change-Id: I347de51cb12022262891b59c00d0342c52bc7439
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/29628
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ICompositeDefinition.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java
org.eclipse.linuxtools.tmf.ctf.core/src/org/eclipse/linuxtools/tmf/ctf/core/CtfTmfEvent.java
org.eclipse.linuxtools.tmf.ctf.core/src/org/eclipse/linuxtools/tmf/ctf/core/CtfTmfEventField.java

index e56b9d681238843d8ee065e81684d687a421cacf..97e67908b508ca6000dd4ea7fc96c199de5d2d3c 100644 (file)
@@ -69,7 +69,8 @@ public abstract class Definition implements IDefinition {
     }
 
     /**
-     * Constructor This one takes the scope and thus speeds up definition creation
+     * Constructor This one takes the scope and thus speeds up definition
+     * creation
      *
      *
      * @param declaration
@@ -85,7 +86,7 @@ public abstract class Definition implements IDefinition {
      *            the scope
      * @since 3.1
      */
-    public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, LexicalScope scope) {
+    public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull LexicalScope scope) {
         fDeclaration = declaration;
         fDefinitionScope = definitionScope;
         fFieldName = fieldName;
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ICompositeDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ICompositeDefinition.java
new file mode 100644 (file)
index 0000000..12b122e
--- /dev/null
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.types;
+
+import java.util.List;
+
+/**
+ * Interface for data definitions containing heterogenous definitions
+ * (subfields)
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+public interface ICompositeDefinition extends IDefinition {
+
+    /**
+     * Gets the definition of the field
+     *
+     * @param fieldName
+     *            the fieldname
+     * @return The definitions of all the fields
+     */
+    Definition getDefinition(String fieldName);
+
+    /**
+     * Gets an array of the field names
+     *
+     * @return the field names array
+     */
+    List<String> getFieldNames();
+
+}
\ No newline at end of file
index fde0ef4431ddfeca24a8ebdb321e1b1e17660517..c91b570c6c3db1e342f4c5d1073eb0349124574c 100644 (file)
@@ -37,7 +37,7 @@ import com.google.common.collect.ImmutableMap.Builder;
  * @author Matthew Khouzam
  * @author Simon Marchi
  */
-public final class StructDefinition extends ScopedDefinition {
+public final class StructDefinition extends ScopedDefinition implements ICompositeDefinition {
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -130,7 +130,7 @@ public final class StructDefinition extends ScopedDefinition {
         super(declaration, definitionScope, structFieldName, scope);
         fFieldNames = ImmutableList.copyOf(fieldNames);
         fDefinitions = definitions;
-        if (fFieldNames == null) {
+        if (fFieldNames.isEmpty()) {
             fDefinitionsMap = Collections.EMPTY_MAP;
         }
     }
@@ -139,14 +139,7 @@ public final class StructDefinition extends ScopedDefinition {
     // Getters/Setters/Predicates
     // ------------------------------------------------------------------------
 
-    /**
-     * Gets the definition of the field
-     *
-     * @param fieldName
-     *            the fieldname
-     * @return The definitions of all the fields
-     * @since 3.0
-     */
+    @Override
     public Definition getDefinition(String fieldName) {
         if (fDefinitionsMap == null) {
             /* Build the definitions map */
@@ -158,16 +151,10 @@ public final class StructDefinition extends ScopedDefinition {
             }
             fDefinitionsMap = mapBuilder.build();
         }
-
         return fDefinitionsMap.get(fieldName);
     }
 
-    /**
-     * Gets an array of the field names
-     *
-     * @return the field names array
-     * @since 3.0
-     */
+    @Override
     public List<String> getFieldNames() {
         return fFieldNames;
     }
index eaa3978d14b2646bcd6ebb1c75f3eabc7f94b363..733bca86ab48ab629fbe2b30e8a2dc1459d201e3 100644 (file)
@@ -22,8 +22,8 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.ICompositeDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.tmf.core.event.ITmfCustomAttributes;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
@@ -238,7 +238,7 @@ public class CtfTmfEvent extends TmfEvent
     private static CtfTmfEventField[] parseFields(@NonNull EventDefinition eventDef) {
         List<CtfTmfEventField> fields = new ArrayList<>();
 
-        StructDefinition structFields = eventDef.getFields();
+        ICompositeDefinition structFields = eventDef.getFields();
         if (structFields != null) {
             if (structFields.getFieldNames() != null) {
                 for (String curFieldName : structFields.getFieldNames()) {
@@ -247,7 +247,7 @@ public class CtfTmfEvent extends TmfEvent
             }
         }
         /* Add context information as CtfTmfEventField */
-        StructDefinition structContext = eventDef.getContext();
+        ICompositeDefinition structContext = eventDef.getContext();
         if (structContext != null) {
             for (String contextName : structContext.getFieldNames()) {
                 /* Prefix field name */
index 0251e3fa20b95d5cbc0086effbc2b1feae8c7de4..34e1ae9548008c772083573acbd85fadd94ec296 100644 (file)
@@ -26,12 +26,12 @@ import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.ICompositeDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
 import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
 import org.eclipse.linuxtools.internal.ctf.core.event.types.ByteArrayDefinition;
@@ -164,8 +164,8 @@ public abstract class CtfTmfEventField extends TmfEventField {
             /* This is an array of ascii bytes, a.k.a. a String! */
             field = new CTFStringField(fieldName, fieldDef.toString());
 
-        } else if (fieldDef instanceof StructDefinition) {
-            StructDefinition strDef = (StructDefinition) fieldDef;
+        } else if (fieldDef instanceof ICompositeDefinition) {
+            ICompositeDefinition strDef = (ICompositeDefinition) fieldDef;
 
             List<ITmfEventField> list = new ArrayList<>();
             /* Recursively parse the fields */
This page took 0.03038 seconds and 5 git commands to generate.