Skip to content

Commit

Permalink
scripting: Move the getFieldValue method to trace module
Browse files Browse the repository at this point in the history
This method belongs more to the trace module than to the analysis one,
as an event is for a trace. Since they cannot share the exact same name,
the copy of the method is named getEventFieldValue.

[Deprecated] "/TraceCompass/Analysis" method getFieldValue moved to Trace

Change-Id: I287ac4d45417923eb83cf441cc9df0a2d760690b
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/151123
Tested-by: CI Bot
  • Loading branch information
tahini committed Oct 16, 2019
1 parent ff613fe commit 8b2cb50
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.eclipse.ease.modules.WrapToScript;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.incubator.scripting.core.trace.TraceScriptingModule;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
Expand All @@ -35,8 +36,9 @@
* provider</a> with script-defined entries and arrows (javascript)</li>
* <li><a href="../doc-files/basicAnalysis.js">A basic analysis</a> building an
* state system and showing its data in a time graph (javascript)</li>
* <li><a href="../doc-files/basicAnalysis.py">Same basic analysis as before,</a>
* building an state system and showing its data in a time graph, in python</li>
* <li><a href="../doc-files/basicAnalysis.py">Same basic analysis as
* before</a>, building a state system and showing its data in a time graph, in
* python</li>
* </ul>
*
* @author Geneviève Bastien
Expand Down Expand Up @@ -76,7 +78,11 @@ public class AnalysisScriptingModule {
* The name of the field to fetch
* @return The field value object, or <code>null</code> if the field is not
* found
* @deprecated This method has been moved to the
* {@link TraceScriptingModule#getEventFieldValue(ITmfEvent,
* String)} class.
*/
@Deprecated
@WrapToScript
public @Nullable Object getFieldValue(ITmfEvent event, String fieldName) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import org.eclipse.tracecompass.incubator.internal.scripting.core.trace.Messages;
import org.eclipse.tracecompass.incubator.internal.scripting.core.trace.ScriptEventRequest;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException;
import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;

/**
* Scripting modules to open and manipulate traces
Expand Down Expand Up @@ -176,4 +178,30 @@ public Iterator<ITmfEvent> getEventIterator(@Nullable ITmfTrace trace) {
trace.sendRequest(scriptEventRequest);
return scriptEventRequest.getEventIterator();
}

/**
* A wrapper method to get the value of an event field. If the field itself
* does not exist, it will try to resolve an aspect from the trace the event
* is from.
*
* @param event
* The event for which to get the field
* @param fieldName
* The name of the field to fetch
* @return The field value object, or <code>null</code> if the field is not
* found
*/
@WrapToScript
public @Nullable Object getEventFieldValue(ITmfEvent event, String fieldName) {

final ITmfEventField field = event.getContent().getField(fieldName);

/* If the field does not exist, see if it's a special case */
if (field == null) {
// This will allow to use any column as input
return TmfTraceUtils.resolveAspectOfNameForEvent(event.getTrace(), fieldName, event);
}
return field.getValue();

}
}

0 comments on commit 8b2cb50

Please sign in to comment.