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
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;
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();
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));
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>.
structDec,
null,
lengthName,
- ImmutableList.of(lengthName),
new Definition[] {
new IntegerDefinition(
id,
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>.
private CTFStreamInputReader fixture;
- private static ImmutableList<String> wrap(String s) {
- return ImmutableList.<String> builder().add(s).build();
- }
-
/**
* Perform pre-test initialization.
*
new StructDeclaration(0),
null,
"packet",
- wrap("field"),
new Definition[] { new StringDefinition(StringDeclaration.getStringDeclaration(Encoding.UTF8), null, "field", "test") }),
null)
);
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>.
structDec,
null,
"x",
- ImmutableList.of(FIELD_NAME),
new Definition[] {
new IntegerDefinition(
id,
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>.
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.
*
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);
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>.
declaration,
variantDefinition,
"",
- ImmutableList.of("tag", variantDefinition.getCurrentFieldName()),
new Definition[] { tagDef, variantDefinition }
);
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>.
"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 = "";
}
fieldNames = builder.build();
StructDefinition mergedContext = new StructDefinition(mergedDeclaration, this, "context", //$NON-NLS-1$
- fieldNames,
fieldValues.toArray(new Definition[fieldValues.size()]));
return mergedContext;
}
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
}
if (fFields != null) {
- list = fFields.getDeclaration().getFieldsList();
+ list = fFields.getFieldNames();
for (String field : list) {
retString.append(field
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
// ------------------------------------------------------------------------
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;
}
* 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;
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.
*
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,
new StructDefinition(
lostFields,
this, "fields", //$NON-NLS-1$
- fieldNameList,
fields
));
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;
*/
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;
}
* @return is the id set?
*/
public boolean idIsSet() {
- return (fId != UNSET_EVENT_ID);
+ return (fId != UNSET_EVENT_ID);
}
/**