Skip to content

Commit

Permalink
tmf: reduce code duplication for trace type extension point handling
Browse files Browse the repository at this point in the history
[Changed] reduce code duplication for traceType extension point handling

Change-Id: Ie1521d6bcd21d802c91b920e1a5c4d9bda8fe6bd
Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/202662
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
  • Loading branch information
bhufmann committed Jun 22, 2023
1 parent 525d178 commit 06d205b
Showing 1 changed file with 13 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr

// The mapping of available trace type IDs to their corresponding
// configuration element
private static final Map<String, IConfigurationElement> TRACE_TYPE_ATTRIBUTES = new HashMap<>();
private static final Map<String, IConfigurationElement> TRACE_TYPE_UI_ATTRIBUTES = new HashMap<>();
private static final Map<String, IConfigurationElement> TRACE_CATEGORIES = new HashMap<>();

// ------------------------------------------------------------------------
// Static initialization
Expand All @@ -118,23 +116,11 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
* extension registry.
*/
public static void init() {
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType.TMF_TRACE_TYPE_ID);
for (IConfigurationElement ce : config) {
String elementName = ce.getName();
if (elementName.equals(TmfTraceType.EXPERIMENT_ELEM)) {
String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
TRACE_TYPE_ATTRIBUTES.put(traceTypeId, ce);
} else if (elementName.equals(TmfTraceType.CATEGORY_ELEM)) {
String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
TRACE_CATEGORIES.put(categoryId, ce);
}
}

/*
* Read the corresponding tmf.ui "tracetypeui" extension point for this
* trace type, if it exists.
*/
config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils.TMF_TRACE_TYPE_UI_ID);
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils.TMF_TRACE_TYPE_UI_ID);
for (IConfigurationElement ce : config) {
String elemName = ce.getName();
if (TmfTraceTypeUIUtils.EXPERIMENT_ELEM.equals(elemName)) {
Expand Down Expand Up @@ -582,26 +568,22 @@ public Object getPropertyValue(Object id) {
return getLocation().toString();
}

if (EXPERIMENT_TYPE.equals(id) && getTraceType() != null) {
IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType());
if (ce == null) {
return ""; //$NON-NLS-1$
}
String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR);
if (categoryId != null) {
IConfigurationElement category = TRACE_CATEGORIES.get(categoryId);
if (category != null) {
return category.getAttribute(TmfTraceType.NAME_ATTR) + ':' + ce.getAttribute(TmfTraceType.NAME_ATTR);
String typeId = getTraceType();
if (EXPERIMENT_TYPE.equals(id)) {
if (typeId != null) {
TraceTypeHelper helper = TmfTraceType.getTraceType(getTraceType());
if (helper != null) {
return helper.getLabel();
}
}
return ce.getAttribute(TmfTraceType.NAME_ATTR);
return ""; //$NON-NLS-1$
}
if (EXPERIMENT_TYPE_ID.equals(id) && getTraceType() != null) {
IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType());
if (ce == null) {
return ""; //$NON-NLS-1$

if (EXPERIMENT_TYPE_ID.equals(id)) {
if (typeId != null) {
return typeId;
}
return ce.getAttribute(TmfTraceType.ID_ATTR);
return ""; //$NON-NLS-1$
}

return null;
Expand Down

0 comments on commit 06d205b

Please sign in to comment.