summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorGeneviève Bastien2013-03-28 11:59:01 (EDT)
committer Matthew Khouzam2013-04-18 16:20:13 (EDT)
commitae07876ea98922d0b04ecaf480aae1cd9f58ad8e (patch)
tree189f0bc50c3e2f6381f481c1d97b42744d0e04b3
parent15edf0d41e8fd713633bc3c347be3d6b3f35e6d8 (diff)
downloadorg.eclipse.linuxtools-ae07876ea98922d0b04ecaf480aae1cd9f58ad8e.zip
org.eclipse.linuxtools-ae07876ea98922d0b04ecaf480aae1cd9f58ad8e.tar.gz
org.eclipse.linuxtools-ae07876ea98922d0b04ecaf480aae1cd9f58ad8e.tar.bz2
TMF: Add Variant field class to CtfTmfEventFieldrefs/changes/50/11550/4
A variant field class was necessary to not lose the name of the variant field. The output of a variant field type is now identical to that of babeltrace. Modified some comments and added the getFormattedValue to CTFStructField to correctly handle empty structs. Removed overriden toString functions that are not overridden anymore. Change-Id: Iccffc6a2375df54945ff41614628760afcdf147f Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net> Reviewed-on: https://git.eclipse.org/r/11550 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java58
2 files changed, 37 insertions, 23 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java
index aff0160..b874071 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java
@@ -192,6 +192,6 @@ public class CtfTmfEventFieldTest {
public void testParseField_variant() {
Definition fieldDef = fixture.lookupDefinition(VARIANT);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("float=9.551467814359616E-38", result.toString());
+ assertEquals("test=float=9.551467814359616E-38", result.toString());
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java
index 3485d5f..6ac34e3 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java
@@ -162,7 +162,8 @@ public abstract class CtfTmfEventField extends TmfEventField {
String curFieldName = varDef.getCurrentFieldName();
Definition curFieldDef = varDef.getDefinitions().get(curFieldName);
if (curFieldDef != null) {
- field = CtfTmfEventField.parseField(curFieldDef, curFieldName);
+ CtfTmfEventField subField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
+ field = new CTFVariantField(fieldName, subField);
} else {
/* A safe-guard, but curFieldDef should never be null */
field = new CTFStringField(curFieldName, ""); //$NON-NLS-1$
@@ -177,7 +178,7 @@ public abstract class CtfTmfEventField extends TmfEventField {
@Override
public String toString() {
- return getName() + '=' + getValue().toString();
+ return getName() + '=' + getFormattedValue();
}
/**
@@ -249,13 +250,6 @@ final class CTFIntegerField extends CtfTmfEventField {
return formatNumber(getValue(), base);
}
- /**
- * Custom-format the integer values depending on their base.
- */
- @Override
- public String toString() {
- return getName() + '=' + formatNumber(getValue(), base);
- }
}
/**
@@ -324,13 +318,6 @@ final class CTFIntegerArrayField extends CtfTmfEventField {
return formattedValue;
}
- /**
- * Custom-format the integer values depending on their base.
- */
- @Override
- public String toString() {
- return getName() + '=' + getFormattedValue();
- }
}
/**
@@ -385,17 +372,17 @@ final class CTFEnumField extends CtfTmfEventField {
}
/**
- * The CTF field implementation for struct fields with sub-types
+ * The CTF field implementation for struct fields with sub-fields
*
* @author gbastien
*/
final class CTFStructField extends CtfTmfEventField {
/**
- * Constructor for CTFStringField.
+ * Constructor for CTFStructField.
*
- * @param strValue
- * The string value of this field
+ * @param fields
+ * The children of this field
* @param name
* The name of this field
*/
@@ -409,9 +396,36 @@ final class CTFStructField extends CtfTmfEventField {
}
@Override
- public String toString() {
- return getName() + '=' + Arrays.toString(getValue());
+ public String getFormattedValue() {
+ return Arrays.toString(getValue());
}
+
+}
+
+/**
+ * The CTF field implementation for variant fields its child
+ *
+ * @author gbastien
+ */
+final class CTFVariantField extends CtfTmfEventField {
+
+ /**
+ * Constructor for CTFVariantField.
+ *
+ * @param field
+ * The field selected for this variant
+ * @param name
+ * The name of this field
+ */
+ CTFVariantField(String name, CtfTmfEventField field) {
+ super(name, field, new CtfTmfEventField[]{ field });
+ }
+
+ @Override
+ public CtfTmfEventField getValue() {
+ return (CtfTmfEventField) super.getValue();
+ }
+
}
/* Implement other possible fields types here... */