From 51cc7ef4899e270546cc80b7d1fc5b3689a84468 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Thu, 28 Mar 2013 11:59:01 -0400 Subject: [PATCH] TMF: Add Variant field class to CtfTmfEventField MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://git.eclipse.org/r/11550 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir IP-Clean: Alexandre Montplaisir Reviewed-by: Matthew Khouzam IP-Clean: Matthew Khouzam Tested-by: Matthew Khouzam --- .../ctfadaptor/CtfTmfEventFieldTest.java | 2 +- .../tmf/core/ctfadaptor/CtfTmfEventField.java | 58 ++++++++++++------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java index aff0160355..b874071ea0 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java +++ b/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/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java index 3485d5f8f4..6ac34e30d8 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java +++ b/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... */ -- 2.34.1