tmf: bug 494698 Add per-event fields to custom parsers
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / parsers / custom / CustomExtraFieldsAspect.java
1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.tmf.core.parsers.custom;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.eclipse.tracecompass.common.core.NonNullUtils;
18 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
19 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
20 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
21 import org.eclipse.tracecompass.tmf.core.parsers.custom.Messages;
22
23 /**
24 * An aspect for a custom event's extra fields
25 *
26 * @author Geneviève Bastien
27 */
28 public class CustomExtraFieldsAspect implements ITmfEventAspect<String> {
29
30 /**
31 * Constructor
32 */
33 public CustomExtraFieldsAspect() {
34 }
35
36 @Override
37 public @NonNull String getName() {
38 return NonNullUtils.nullToEmptyString(Messages.CustomExtraFieldsAspect_extraFieldsAspectName);
39 }
40
41 @Override
42 public @NonNull String getHelpText() {
43 return NonNullUtils.nullToEmptyString(Messages.CustomExtraFieldsAspect_extraFieldsAspectHelp);
44 }
45
46 @Override
47 public @Nullable String resolve(@NonNull ITmfEvent event) {
48 List<String> fields = new ArrayList<>();
49 for (ITmfEventField field : event.getContent().getFields()) {
50 // Add the fields that do not have another aspect associated
51 if (field instanceof CustomExtraField) {
52 fields.add(field.getName() + '=' + field.getValue());
53 }
54 }
55 return String.join(", ", fields); //$NON-NLS-1$
56 }
57
58 }
This page took 0.050366 seconds and 5 git commands to generate.