import java.util.Map;
import java.util.Map.Entry;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.btf.core.Messages;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
public class BTFPayload {
/** Description subfield name */
- public static final String DESCRIPTION = "description"; //$NON-NLS-1$
+ public static final @NonNull String DESCRIPTION = "description"; //$NON-NLS-1$
private static final Map<String, String> EVENT_DESCRIPTIONS;
private static final String EMPTY = ""; //$NON-NLS-1$
private static final String FLOAT = "float";
private static final String LEN = "len";
private static final String INT = "int";
- private static final String NAME = "test";
+ private static final @NonNull String NAME = "test";
private static final String STRUCT = "struct";
private static final String VARIANT = "variant";
private static final String ENUM = "enum";
package org.eclipse.tracecompass.tmf.ctf.core.event;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
if (structFields != null) {
if (structFields.getFieldNames() != null) {
for (String curFieldName : structFields.getFieldNames()) {
- fields.add(CtfTmfEventField.parseField((IDefinition) structFields.getDefinition(curFieldName), curFieldName));
+ String fn = checkNotNull(curFieldName);
+ fields.add(CtfTmfEventField.parseField((IDefinition) structFields.getDefinition(fn), fn));
}
}
}
package org.eclipse.tracecompass.tmf.ctf.core.event;
+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;
import org.eclipse.tracecompass.ctf.core.event.types.AbstractArrayDefinition;
import org.eclipse.tracecompass.ctf.core.event.types.CompoundDeclaration;
import org.eclipse.tracecompass.ctf.core.event.types.Definition;
* @param fields
* The children fields. Useful for composite fields
*/
- protected CtfTmfEventField(String name, Object value, ITmfEventField[] fields) {
+ protected CtfTmfEventField(@NonNull String name, Object value, ITmfEventField[] fields) {
super(/* Strip the underscore from the field name if there is one */
- name.startsWith("_") ? name.substring(1) : name, //$NON-NLS-1$
+ name.startsWith("_") ? checkNotNull(name.substring(1)) : name, //$NON-NLS-1$
value,
fields);
}
*/
@Deprecated
public static CtfTmfEventField parseField(Definition fieldDef,
- String fieldName) {
+ @NonNull String fieldName) {
return parseField((IDefinition) fieldDef, fieldName);
}
* @return The resulting CtfTmfEventField object
*/
public static CtfTmfEventField parseField(IDefinition fieldDef,
- String fieldName) {
+ @NonNull String fieldName) {
CtfTmfEventField field = null;
/* Determine the Definition type */
List<ITmfEventField> list = new ArrayList<>();
/* Recursively parse the fields */
for (String curFieldName : strDef.getFieldNames()) {
- list.add(CtfTmfEventField.parseField(strDef.getDefinition(curFieldName), curFieldName));
+ String fn = checkNotNull(curFieldName);
+ list.add(CtfTmfEventField.parseField((IDefinition) strDef.getDefinition(fn), fn));
}
field = new CTFStructField(fieldName, list.toArray(new CtfTmfEventField[list.size()]));
} else if (fieldDef instanceof VariantDefinition) {
VariantDefinition varDef = (VariantDefinition) fieldDef;
- String curFieldName = varDef.getCurrentFieldName();
+ String curFieldName = checkNotNull(varDef.getCurrentFieldName());
IDefinition curFieldDef = varDef.getCurrentField();
if (curFieldDef != null) {
CtfTmfEventField subField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
* @param signed
* Is the value signed or not
*/
- CTFIntegerField(String name, long longValue, int base, boolean signed) {
+ CTFIntegerField(@NonNull String name, long longValue, int base, boolean signed) {
super(name, longValue, null);
fSigned = signed;
fBase = base;
* @param name
* The name of this field
*/
- CTFStringField(String name, String strValue) {
+ CTFStringField(@NonNull String name, String strValue) {
super(name, strValue, null);
}
* @param signed
* Are the values in the array signed or not
*/
- CTFIntegerArrayField(String name, long[] longValues, int base, boolean signed) {
+ CTFIntegerArrayField(@NonNull String name, long[] longValues, int base, boolean signed) {
super(name, longValues, null);
fBase = base;
fSigned = signed;
* @param elements
* The array elements of this field
*/
- CTFArrayField(String name, CtfTmfEventField[] elements) {
+ CTFArrayField(@NonNull String name, CtfTmfEventField[] elements) {
super(name, elements, elements);
}
* @param name
* The name of this field
*/
- protected CTFFloatField(String name, double value) {
+ protected CTFFloatField(@NonNull String name, double value) {
super(name, value, null);
}
* @param name
* The name of this field
*/
- CTFEnumField(String name, CtfEnumPair enumValue) {
+ CTFEnumField(@NonNull String name, CtfEnumPair enumValue) {
super(name, new CtfEnumPair(enumValue.getFirst(),
enumValue.getSecond()), null);
}
* @param name
* The name of this field
*/
- CTFStructField(String name, CtfTmfEventField[] fields) {
+ CTFStructField(@NonNull String name, CtfTmfEventField[] fields) {
super(name, fields, fields);
}
* @param name
* The name of this field
*/
- CTFVariantField(String name, CtfTmfEventField field) {
+ CTFVariantField(@NonNull String name, CtfTmfEventField field) {
super(name, field, new CtfTmfEventField[] { field });
}
List<ITmfEventField> content = new ArrayList<>();
/* Should only return null the first time */
for (String fieldName : ied.getFields().getFieldsList()) {
- content.add(new TmfEventField(fieldName, null, null));
+ content.add(new TmfEventField(checkNotNull(fieldName), null, null));
}
ITmfEventField contentTree = new TmfEventField(
ITmfEventField.ROOT_FIELD_ID,
while (localPacket != null) {
subfieldList.clear();
for (Map.Entry<String, String> entry : localPacket.getFields().entrySet()) {
- String key = entry.getKey();
+ String key = checkNotNull(entry.getKey());
String value = entry.getValue();
subfieldList.add(new TmfEventField(key, value, null));
}
import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
// Variables
// ------------------------------------------------------------------------
- private final String fFieldName1 = "Field-1";
- private final String fFieldName2 = "Field-2";
+ private final @NonNull String fFieldName1 = "Field-1";
+ private final @NonNull String fFieldName2 = "Field-2";
private final Object fValue1 = "Value";
private final Object fValue2 = Integer.valueOf(10);
private final TmfEventField fField2 = new TmfEventField(fFieldName2, fValue2, null);
private final TmfEventField fField3 = new TmfEventField(fFieldName1, fValue2, null);
- private final String fStructRootFieldName = "Root-S";
+ private final @NonNull String fStructRootFieldName = "Root-S";
private final String[] fStructFieldNames = new String[] { fFieldName1, fFieldName2 };
private final TmfEventField fStructTerminalField1 = new TmfEventField(fFieldName1, null, null);
private final TmfEventField fStructTerminalField2 = new TmfEventField(fFieldName2, null, null);
private final TmfEventField fStructRootField = new TmfEventField(fStructRootFieldName, null,
new ITmfEventField[] { fStructTerminalField1, fStructTerminalField2 });
- private final String fRootFieldName = "Root";
+ private final @NonNull String fRootFieldName = "Root";
private final String[] fFieldNames = new String[] { fFieldName1, fFieldName2 };
private final TmfEventField fRootField = new TmfEventField(fRootFieldName, null,
new ITmfEventField[] { fField1, fField2 });
assertArrayEquals(fFieldNames, names.toArray(new String[names.size()]));
}
- @Test
- public void testConstructorBadArg() {
- try {
- new TmfEventField(null, fValue1, null);
- fail("Invalid (null) field name");
- } catch (final IllegalArgumentException e) {
- }
- }
-
@Test
public void testTerminalCopyConstructor() {
final TmfEventField copy = new TmfEventField(fField1);
private final @NonNull ITmfTrace fTrace = STUB_TRACE.getTrace();
private final String fTypeId = "TestType";
- private final String fLabel1 = "AString";
- private final String fLabel2 = "AnInteger";
+ private final @NonNull String fLabel1 = "AString";
+ private final @NonNull String fLabel2 = "AnInteger";
private final String[] fLabels = new String[] { fLabel1, fLabel2 };
private final TmfEventType fType = new TmfEventType(fTypeId, TmfEventField.makeRoot(fLabels));
private final ITmfEventField fField1a = new TmfEventField(fLabel1, fValue1a, null);
private final ITmfEventField fField1b = new TmfEventField(fLabel2, fValue1b, null);
private final ITmfEventField[] fFields1 = new ITmfEventField[] { fField1a, fField1b };
- private final String fRawContent1 = fField1a.toString() + fField1b.toString();
+ private final @NonNull String fRawContent1 = fField1a.toString() + fField1b.toString();
private final ITmfEventField fContent1 = new TmfEventField(fRawContent1, null, fFields1);
private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, 2);
private final @NonNull ITmfEvent fEvent1 = new TmfEvent(fTrace, 0, fTimestamp1, fType, fContent1);
private final ITmfEventField fField2a = new TmfEventField(fLabel1, fValue2a, null);
private final ITmfEventField fField2b = new TmfEventField(fLabel2, fValue2b, null);
private final ITmfEventField[] fFields2 = new ITmfEventField[] { fField2a, fField2b };
- private final String fRawContent2 = fField2a.toString() + fField2b.toString();
+ private final @NonNull String fRawContent2 = fField2a.toString() + fField2b.toString();
private final ITmfEventField fContent2 = new TmfEventField(fRawContent2, null, fFields2);
private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, 2);
private final @NonNull ITmfEvent fEvent2 = new TmfEvent(fTrace, 1, fTimestamp2, fType, fContent2);
package org.eclipse.tracecompass.tmf.tests.stubs.event;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
*/
public class TmfSyncEventStub extends TmfEvent {
- private static final String stub = "stub"; //$NON-NLS-1$
+ private static final @NonNull String stub = "stub"; //$NON-NLS-1$
/**
* Constructor
package org.eclipse.tracecompass.tmf.tests.stubs.trace.xml;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
break;
}
}
- fieldsArray[i] = new TmfEventField(fields[i], val, null);
+ fieldsArray[i] = new TmfEventField(checkNotNull(fields[i]), val, null);
}
/* Generate the aspects for this trace if it is the aspects special event */
/* Add custom aspects in between */
for (ITmfEventField field : fieldsArray) {
String name = field.getName();
- if (name == null) {
- break;
- }
final ITmfEventAspect aspect = new TmfContentFieldAspect(name, name);
if (name.equals(ASPECT_CPU)) {
builder.add(new TmfCpuAspect() {
/**
* @return the field name
*/
- String getName();
+ @NonNull String getName();
/**
* @return the field value
*
* @return The subfield names (empty Collection if none)
*/
- Collection<String> getFieldNames();
+ @NonNull Collection<String> getFieldNames();
/**
* Return the subfields. The iteration order is the same as
*
* @return The subfields (empty Collection if none)
*/
- Collection<? extends ITmfEventField> getFields();
+ @NonNull Collection<? extends ITmfEventField> getFields();
/**
* Return a subfield by its path relative to this field.
* @throws IllegalArgumentException
* If 'name' is null, or if 'fields' has duplicate field names.
*/
- public TmfEventField(String name, @Nullable Object value, @Nullable ITmfEventField[] fields) {
- if (name == null) {
- throw new IllegalArgumentException();
- }
+ public TmfEventField(@NonNull String name, @Nullable Object value, @Nullable ITmfEventField[] fields) {
fName = name;
fValue = value;
@Override
public Collection<String> getFieldNames() {
- return fFields.keySet();
+ return checkNotNull(fFields.keySet());
}
@Override
public Collection<ITmfEventField> getFields() {
- return fFields.values();
+ return checkNotNull(fFields.values());
}
@Override
public static final ITmfEventField makeRoot(final String[] labels) {
final ITmfEventField[] fields = new ITmfEventField[labels.length];
for (int i = 0; i < labels.length; i++) {
- fields[i] = new TmfEventField(labels[i], null, null);
+ String label = checkNotNull(labels[i]);
+ fields[i] = new TmfEventField(label, null, null);
}
// Return a new root field;
return new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fields);
package org.eclipse.tracecompass.tmf.core.parsers.custom;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
* @param fields
* The array of sub-fields
*/
- public CustomEventContent(String name, Object content, ITmfEventField[] fields) {
+ public CustomEventContent(@NonNull String name, Object content, ITmfEventField[] fields) {
super(name, content, fields);
}
@Override
public Object getPropertyValue(Object id) {
ITmfEventField field = (ITmfEventField) id;
- if (field.getFields() != null && field.getFields().size() > 0) {
+ if (!field.getFields().isEmpty()) {
return new ContentPropertySource(field);
}
return field.getFormattedValue();