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
}
/**
- * 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
* 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;
--- /dev/null
+/*******************************************************************************
+ * 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
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public final class StructDefinition extends ScopedDefinition {
+public final class StructDefinition extends ScopedDefinition implements ICompositeDefinition {
// ------------------------------------------------------------------------
// Attributes
super(declaration, definitionScope, structFieldName, scope);
fFieldNames = ImmutableList.copyOf(fieldNames);
fDefinitions = definitions;
- if (fFieldNames == null) {
+ if (fFieldNames.isEmpty()) {
fDefinitionsMap = Collections.EMPTY_MAP;
}
}
// 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 */
}
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;
}
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;
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()) {
}
}
/* Add context information as CtfTmfEventField */
- StructDefinition structContext = eventDef.getContext();
+ ICompositeDefinition structContext = eventDef.getContext();
if (structContext != null) {
for (String contextName : structContext.getFieldNames()) {
/* Prefix field name */
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;
/* 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 */