ctf: remove field list from constructor of StructDefinition
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 15 May 2015 19:51:52 +0000 (15:51 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 15 May 2015 21:40:56 +0000 (17:40 -0400)
This makes no sense to have as structs have the field list internally.
Moreover this leads to more complicated and error prone struct initialization.
It also hides potential bugs in the tests. As highlighted in CTFEventDefinitionTest

Change-Id: I25bf18bf9be23fb2af17f52de9cf677bea1b4833
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/47992
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-by: Hudson CI
12 files changed:
org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventDefinitionTest.java
org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventFieldTest.java
org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputReaderTest.java
org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/SequenceDeclaration2Test.java
org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/SequenceDefinition2Test.java
org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDeclarationTest.java
org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDefinitionTest.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/EventDefinition.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDefinition.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInputPacketReader.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java

index 9ef88f695eac9f6d5ee0ab175193b6bb119a672e..f67138c3273f6a4e39ffde0ccb6c470724120f09 100644 (file)
@@ -18,8 +18,6 @@ import static org.junit.Assert.assertTrue;
 
 import java.nio.ByteOrder;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 
 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
@@ -59,8 +57,8 @@ public class CTFEventDefinitionTest {
         streamContextDec.addField("pid", pidDec);
         streamContextDec.addField("ctx", ctxDec);
         StructDeclaration eventContextDec = new StructDeclaration(8);
-        streamContextDec.addField("pod", pidDec);
-        streamContextDec.addField("ctx", pidDec);
+        eventContextDec.addField("pod", pidDec);
+        eventContextDec.addField("ctx", pidDec);
         StructDeclaration fDec = new StructDeclaration(8);
         EventDeclaration eventDeclaration = new EventDeclaration();
 
@@ -68,20 +66,16 @@ public class CTFEventDefinitionTest {
         fDec.addField("ctx", ctxDec);
         fDec.addField("pod", pidDec);
 
-        List<String> sFieldNames = Arrays.asList("pid", "ctx");
-        List<String> eFieldNames = Arrays.asList("pod", "ctx");
-        List<String> fieldNames = Arrays.asList("pid", "ctx", "pod");
-
         Definition[] sDefs = { pid, ctx };
         Definition[] eDefs = { pod, ctx };
         Definition[] fDefs = { pid, ctx, pod };
 
         StructDeclaration pContextDec = new StructDeclaration(8);
 
-        StructDefinition sContext = new StructDefinition(streamContextDec, null, ILexicalScope.STREAM_PACKET_CONTEXT.getPath(), sFieldNames, sDefs);
-        StructDefinition eContext = new StructDefinition(eventContextDec, null, ILexicalScope.STREAM_EVENT_CONTEXT.getPath(), eFieldNames, eDefs);
-        StructDefinition pContext = new StructDefinition(pContextDec, null, ILexicalScope.FIELDS.getPath(), Collections.EMPTY_LIST, new Definition[0]);
-        StructDefinition fields = new StructDefinition(fDec, null, ILexicalScope.FIELDS.getPath(), fieldNames, fDefs);
+        StructDefinition sContext = new StructDefinition(streamContextDec, null, ILexicalScope.STREAM_PACKET_CONTEXT.getPath(), sDefs);
+        StructDefinition eContext = new StructDefinition(eventContextDec, null, ILexicalScope.STREAM_EVENT_CONTEXT.getPath(), eDefs);
+        StructDefinition pContext = new StructDefinition(pContextDec, null, ILexicalScope.FIELDS.getPath(), new Definition[0]);
+        StructDefinition fields = new StructDefinition(fDec, null, ILexicalScope.FIELDS.getPath(), fDefs);
 
         fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, null, null));
         fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, null, fields));
index 7a4d5477652d7929c147d08752717a0fd1b672df..e008760527758eeb9592fe274eb7d09384d6d9c9 100644 (file)
@@ -32,8 +32,6 @@ import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
 import org.eclipse.tracecompass.internal.ctf.core.event.types.SequenceDeclaration;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableList;
-
 /**
  * The class <code>CTFEventFieldTest</code> contains tests for the class
  * <code>{@link CTFEventField}</code>.
@@ -70,7 +68,6 @@ public class CTFEventFieldTest {
                 structDec,
                 null,
                 lengthName,
-                ImmutableList.of(lengthName),
                 new Definition[] {
                         new IntegerDefinition(
                                 id,
index 8cc449d60ca4fc6e0f6f4e60f0b2d098f8f41fa9..a7e4e70e339781218e5b903ab9a50427b9038dc6 100644 (file)
@@ -37,8 +37,6 @@ import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableList;
-
 /**
  * The class <code>StreamInputReaderTest</code> contains tests for the class
  * <code>{@link CTFStreamInputReader}</code>.
@@ -53,10 +51,6 @@ public class CTFStreamInputReaderTest {
 
     private CTFStreamInputReader fixture;
 
-    private static ImmutableList<String> wrap(String s) {
-        return ImmutableList.<String> builder().add(s).build();
-    }
-
     /**
      * Perform pre-test initialization.
      *
@@ -72,7 +66,6 @@ public class CTFStreamInputReaderTest {
                         new StructDeclaration(0),
                         null,
                         "packet",
-                        wrap("field"),
                         new Definition[] { new StringDefinition(StringDeclaration.getStringDeclaration(Encoding.UTF8), null, "field", "test") }),
                 null)
                 );
index 79d389695b69ea71f8a251fe22f40de764b78b45..7b2295848d47d3946c6cb218dcf922c7b4b8dd4f 100644 (file)
@@ -36,8 +36,6 @@ import org.eclipse.tracecompass.internal.ctf.core.event.types.SequenceDeclaratio
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableList;
-
 /**
  * The class <code>SequenceDeclarationTest</code> contains tests for the class
  * <code>{@link SequenceDeclaration}</code>.
@@ -98,7 +96,6 @@ public class SequenceDeclaration2Test {
                 structDec,
                 null,
                 "x",
-                ImmutableList.of(FIELD_NAME),
                 new Definition[] {
                         new IntegerDefinition(
                                 id,
index e6728abc6ab8543cc8374f098770fddeadddd5a1..5258ccf105698a95e357ed4fcde79450858fdf10 100644 (file)
@@ -30,8 +30,6 @@ import org.eclipse.tracecompass.internal.ctf.core.event.types.SequenceDeclaratio
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableList;
-
 /**
  * The class <code>SequenceDefinition2Test</code> contains tests for the class
  * <code>{@link SequenceDefinition2}</code>.
@@ -45,10 +43,6 @@ public class SequenceDefinition2Test {
     private ByteArrayDefinition fixture;
     private final static int seqLen = 15;
 
-    private static ImmutableList<String> wrap(String s) {
-        return ImmutableList.<String> builder().add(s).build();
-    }
-
     /**
      * Perform pre-test initialization.
      *
@@ -70,7 +64,7 @@ public class SequenceDefinition2Test {
         structDec = new StructDeclaration(0);
         structDec.addField(lengthName, id);
 
-        structDef = new StructDefinition(structDec, null, "x", wrap(lengthName), new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
+        structDef = new StructDefinition(structDec, null, "x",  new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
 
         SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
         ByteBuffer allocateDirect = java.nio.ByteBuffer.allocateDirect(seqLen * len);
index f8564e82843670c7b0745e82d8f9464ba63b302f..a5a5b2fb7d8c623fc6f71745631ce0e79b109b27 100644 (file)
@@ -38,8 +38,6 @@ import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableList;
-
 /**
  * The class <code>VariantDeclarationTest</code> contains tests for the class
  * <code>{@link VariantDeclaration}</code>.
@@ -100,7 +98,6 @@ public class VariantDeclarationTest {
                 declaration,
                 variantDefinition,
                 "",
-                ImmutableList.of("tag", variantDefinition.getCurrentFieldName()),
                 new Definition[] { tagDef, variantDefinition }
                 );
 
index 7e9bd86cfd8407d1e0cebcab784c325a5b8742ba..4cb9b4b591a9842643188d612542c54a14cea148 100644 (file)
@@ -43,8 +43,6 @@ import org.eclipse.tracecompass.internal.ctf.core.event.types.ArrayDeclaration;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableList;
-
 /**
  * The class <code>VariantDefinitionTest</code> contains tests for the class
  * <code>{@link VariantDefinition}</code>.
@@ -158,11 +156,13 @@ public class VariantDefinitionTest {
                         "A",
                         1
                 ));
+        final StructDeclaration declarationScope = new StructDeclaration(1L);
+        declarationScope.addField("", enumDefinition.getDeclaration());
+        declarationScope.addField("variant", variantDeclaration);
         IDefinitionScope definitionScope = new StructDefinition(
-                new StructDeclaration(1L),
+                declarationScope,
                 variantDefinition,
                 "",
-                ImmutableList.<String> of("", "variant"),
                 new Definition[] { enumDefinition, variantDefinition }
                 );
         String fieldName = "";
index b145b58ebe3b4890e82b3fb77ccb58f70ee19e1e..3a8d027d7e96bf47d754f6438e336f3d269d0cd5 100644 (file)
@@ -208,7 +208,6 @@ public final class EventDefinition implements IDefinitionScope {
         }
         fieldNames = builder.build();
         StructDefinition mergedContext = new StructDefinition(mergedDeclaration, this, "context", //$NON-NLS-1$
-                fieldNames,
                 fieldValues.toArray(new Definition[fieldValues.size()]));
         return mergedContext;
     }
@@ -275,7 +274,7 @@ public final class EventDefinition implements IDefinitionScope {
         retString.append("Timestamp: " + Long.toString(fTimestamp) + cr); //$NON-NLS-1$
 
         if (fEventContext != null) {
-            list = fEventContext.getDeclaration().getFieldsList();
+            list = fEventContext.getFieldNames();
 
             for (String field : list) {
                 retString.append(field
@@ -284,7 +283,7 @@ public final class EventDefinition implements IDefinitionScope {
         }
 
         if (fFields != null) {
-            list = fFields.getDeclaration().getFieldsList();
+            list = fFields.getFieldNames();
 
             for (String field : list) {
                 retString.append(field
index 6ac65cd786b8757f8fd205b137810b202e2f1b0d..90f6efc67e674f55f12d7a2349674e3221baf1a8 100644 (file)
@@ -67,22 +67,6 @@ public class StructDeclaration extends Declaration {
         fMaxAlign = Math.max(align, 1);
     }
 
-    /**
-     * Struct declaration constructor
-     *
-     * @param names
-     *            the names of all the fields
-     * @param declarations
-     *            all the fields
-     */
-    public StructDeclaration(String[] names, Declaration[] declarations) {
-        fMaxAlign = 1;
-
-        for (int i = 0; i < names.length; i++) {
-            addField(names[i], declarations[i]);
-        }
-    }
-
     // ------------------------------------------------------------------------
     // Getters/Setters/Predicates
     // ------------------------------------------------------------------------
@@ -161,7 +145,7 @@ public class StructDeclaration extends Declaration {
             String fieldName, BitBuffer input) throws CTFException {
         alignRead(input);
         final Definition[] myFields = new Definition[fFieldMap.size()];
-        StructDefinition structDefinition = new StructDefinition(this, definitionScope, fieldName, fFieldMap.keySet(), myFields);
+        StructDefinition structDefinition = new StructDefinition(this, definitionScope, fieldName, myFields);
         fillStruct(input, myFields, structDefinition);
         return structDefinition;
     }
index 7ffa125d9616e67ce1da8272cdb762213bc0fd24..a3bbd14edaecd4879e93a7f197aa095ce5b0c0df 100644 (file)
@@ -62,18 +62,16 @@ public final class StructDefinition extends ScopedDefinition implements IComposi
      *            the parent scope
      * @param structFieldName
      *            the field name
-     * @param fieldNames
-     *            the list of fields
      * @param definitions
      *            the definitions
+     * @since 1.0
      */
     public StructDefinition(@NonNull StructDeclaration declaration,
             IDefinitionScope definitionScope,
             @NonNull String structFieldName,
-            Iterable<String> fieldNames,
             Definition[] definitions) {
         super(declaration, definitionScope, structFieldName);
-        fFieldNames = ImmutableList.copyOf(fieldNames);
+        fFieldNames = ImmutableList.copyOf(declaration.getFieldsList());
         fDefinitions = definitions;
         if (fFieldNames.isEmpty()) {
             fDefinitionsMap = Collections.EMPTY_MAP;
index 8f664358269d2c738d857da55a82445136e69456..5456f77d18498af03dca89fe39960f53f4b7e1fb 100644 (file)
@@ -40,8 +40,6 @@ import org.eclipse.tracecompass.internal.ctf.core.SafeMappedByteBuffer;
 import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
 import org.eclipse.tracecompass.internal.ctf.core.event.types.composite.EventHeaderDefinition;
 
-import com.google.common.collect.ImmutableList;
-
 /**
  * CTF trace packet reader. Reads the events of a packet of a trace file.
  *
@@ -332,8 +330,6 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab
             IntegerDefinition lostDurationDef = new IntegerDefinition(lostFieldsDecl, null, CTFStrings.LOST_EVENTS_DURATION, fLostEventsDuration);
             IntegerDefinition lostCountDef = new IntegerDefinition(lostEventsDurationDecl, null, CTFStrings.LOST_EVENTS_FIELD, fLostEventsInThisPacket);
             IntegerDefinition[] fields = new IntegerDefinition[] { lostCountDef, lostDurationDef };
-            /* this is weird notation, but it's the java notation */
-            final ImmutableList<String> fieldNameList = ImmutableList.<String> builder().add(CTFStrings.LOST_EVENTS_FIELD).add(CTFStrings.LOST_EVENTS_DURATION).build();
             return new EventDefinition(
                     lostEventDeclaration,
                     fStreamInputReader,
@@ -344,7 +340,6 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab
                     new StructDefinition(
                             lostFields,
                             this, "fields", //$NON-NLS-1$
-                            fieldNameList,
                             fields
                     ));
 
index f0f0801a7963ba9681f2db1a918435e81a9c8a65..4dfd8d5ad3a40595a9901fb911f73b05f1bfcb18 100644 (file)
@@ -23,7 +23,6 @@ import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
 import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
-import org.eclipse.tracecompass.ctf.core.event.types.Declaration;
 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
@@ -116,11 +115,11 @@ public class EventDeclaration implements IEventDeclaration {
      */
     public static synchronized EventDeclaration getLostEventDeclaration() {
         EventDeclaration lostEvent = new EventDeclaration();
-        String[] fieldNames = new String[] { CTFStrings.LOST_EVENTS_FIELD, CTFStrings.LOST_EVENTS_DURATION };
-        Declaration[] fieldDeclarations = new Declaration[] { IntegerDeclaration.UINT_32B_DECL, IntegerDeclaration.UINT_64B_DECL };
-        lostEvent.fFields = new StructDeclaration(fieldNames, fieldDeclarations);
+        lostEvent.fFields = new StructDeclaration(0);
         lostEvent.fId = (int) LOST_EVENT_ID;
         lostEvent.fName = CTFStrings.LOST_EVENT_NAME;
+        lostEvent.getFields().addField(CTFStrings.LOST_EVENTS_FIELD, IntegerDeclaration.UINT_32B_DECL);
+        lostEvent.getFields().addField(CTFStrings.LOST_EVENTS_DURATION, IntegerDeclaration.UINT_64B_DECL);
         return lostEvent;
     }
 
@@ -248,7 +247,7 @@ public class EventDeclaration implements IEventDeclaration {
      * @return is the id set?
      */
     public boolean idIsSet() {
-        return (fId  != UNSET_EVENT_ID);
+        return (fId != UNSET_EVENT_ID);
     }
 
     /**
This page took 0.031678 seconds and 5 git commands to generate.