ctf: Explicitly create a Long object for Integer fields
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core / src / org / eclipse / tracecompass / tmf / ctf / core / event / CtfTmfEventField.java
index 6bc6d92e10581e6035dc6f4293d88a1e574299c6..4f502d68f0bdd8323424cfe49102a5888b6de383 100644 (file)
@@ -21,7 +21,6 @@ import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
@@ -37,6 +36,7 @@ import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
 import org.eclipse.tracecompass.ctf.core.event.types.StringDefinition;
 import org.eclipse.tracecompass.ctf.core.event.types.VariantDefinition;
+import org.eclipse.tracecompass.internal.ctf.core.event.types.ByteArrayDefinition;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
 import org.eclipse.tracecompass.tmf.ctf.core.CtfEnumPair;
@@ -67,7 +67,7 @@ public abstract class CtfTmfEventField extends TmfEventField {
      */
     protected CtfTmfEventField(@NonNull String name, Object value, ITmfEventField[] fields) {
         super(/* Strip the underscore from the field name if there is one */
-                name.startsWith("_") ? checkNotNull(name.substring(1)) : name, //$NON-NLS-1$
+                name.startsWith("_") ? name.substring(1) : name, //$NON-NLS-1$
                 value,
                 fields);
     }
@@ -101,7 +101,7 @@ public abstract class CtfTmfEventField extends TmfEventField {
      *            String The name to assign to this field
      * @return The resulting CtfTmfEventField object
      */
-    public static CtfTmfEventField parseField(IDefinition fieldDef,
+    public static @NonNull CtfTmfEventField parseField(IDefinition fieldDef,
             @NonNull String fieldName) {
         CtfTmfEventField field = null;
 
@@ -130,8 +130,20 @@ public abstract class CtfTmfEventField extends TmfEventField {
             }
             CompoundDeclaration arrDecl = (CompoundDeclaration) decl;
             IDeclaration elemType = null;
-            Collection<Definition> definitions = arrayDef.getDefinitions();
             elemType = arrDecl.getElementType();
+            if (arrayDef instanceof ByteArrayDefinition) {
+                ByteArrayDefinition byteArrayDefinition = (ByteArrayDefinition) arrayDef;
+                /* it's a CTFIntegerArrayField */
+                int size = arrayDef.getLength();
+                long[] values = new long[size];
+                for (int i = 0; i < size; i++) {
+                    values[i] = Byte.toUnsignedLong(byteArrayDefinition.getByte(i));
+                }
+                field = new CTFIntegerArrayField(fieldName, values,
+                        16,
+                        false);
+
+            }
             if (elemType instanceof IntegerDeclaration) {
                 /*
                  * Array of integers => CTFIntegerArrayField, unless it's a
@@ -144,7 +156,7 @@ public abstract class CtfTmfEventField extends TmfEventField {
                     field = new CTFStringField(fieldName, arrayDef.toString());
                 } else {
                     /* it's a CTFIntegerArrayField */
-                    int size = arrayDef.getDefinitions().size();
+                    int size = arrayDef.getLength();
                     long[] values = new long[size];
                     for (int i = 0; i < size; i++) {
                         IDefinition elem = arrayDef.getDefinitions().get(i);
@@ -162,6 +174,7 @@ public abstract class CtfTmfEventField extends TmfEventField {
                 CtfTmfEventField[] elements = new CtfTmfEventField[arrayDef.getLength()];
                 /* Parse the elements of the array. */
                 int i = 0;
+                List<Definition> definitions = arrayDef.getDefinitions();
                 for (IDefinition definition : definitions) {
                     CtfTmfEventField curField = CtfTmfEventField.parseField(
                             definition, fieldName + '[' + i + ']');
@@ -176,8 +189,7 @@ public abstract class CtfTmfEventField extends TmfEventField {
 
             List<ITmfEventField> list = new ArrayList<>();
             /* Recursively parse the fields */
-            for (String curFieldName : strDef.getFieldNames()) {
-                String fn = checkNotNull(curFieldName);
+            for (String fn : strDef.getFieldNames()) {
                 list.add(CtfTmfEventField.parseField((IDefinition) strDef.getDefinition(fn), fn));
             }
             field = new CTFStructField(fieldName, list.toArray(new CtfTmfEventField[list.size()]));
@@ -234,7 +246,7 @@ final class CTFIntegerField extends CtfTmfEventField {
      *            Is the value signed or not
      */
     CTFIntegerField(@NonNull String name, long longValue, int base, boolean signed) {
-        super(name, longValue, null);
+        super(name, Long.valueOf(longValue), null);
         fSigned = signed;
         fBase = base;
     }
This page took 0.025361 seconds and 5 git commands to generate.