use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode in project tracecompass by tracecompass.
the class TmfFilterHelperTest method testInputRegexNoField.
/**
* Test a regex with no parameter
*/
@Test
public void testInputRegexNoField() {
String regex = "afield";
ITmfFilter filter = getFilter(regex);
assertTrue(filter instanceof TmfFilterRootNode);
TmfFilterRootNode node = (TmfFilterRootNode) filter;
assertEquals(1, node.getChildrenCount());
ITmfFilterTreeNode child = node.getChild(0);
assertTrue(child instanceof TmfFilterOrNode);
// Verify the orNode
TmfFilterOrNode orNode = (TmfFilterOrNode) child;
ITmfTrace trace = STUB_TRACE;
assertNotNull(trace);
Iterable<@NonNull ITmfEventAspect<?>> eventAspects = trace.getEventAspects();
// Verify that each child is a matches node and there's one per aspect
assertEquals(Iterables.size(eventAspects), orNode.getChildrenCount());
for (int i = 0; i < orNode.getChildrenCount(); i++) {
assertTrue(orNode.getChild(i) instanceof TmfFilterMatchesNode);
}
for (ITmfEventAspect<?> aspect : eventAspects) {
// Find a contains condition for each aspect
ITmfFilterTreeNode[] children = orNode.getChildren();
TmfFilterMatchesNode found = null;
for (int i = 0; i < children.length; i++) {
TmfFilterMatchesNode childFilter = (TmfFilterMatchesNode) children[i];
if (aspect.equals(childFilter.getEventAspect())) {
found = childFilter;
break;
}
}
assertNotNull("found aspect " + aspect.getName(), found);
assertEquals(regex, found.getRegex());
}
// Test expected behavior on events
assertTrue(filter.matches(fEvent1));
assertFalse(filter.matches(fEvent2));
assertTrue(filter.matches(fEvent3));
}
use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode in project tracecompass by tracecompass.
the class TmfFilterOrNodeTest method createFilter.
// ------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------
@Before
public void createFilter() {
fFilter = new TmfFilterOrNode(null);
fFilterNode = fFilter;
}
use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode in project tracecompass by tracecompass.
the class FilterSimpleExpressionCu method getEventFilter.
@Override
public ITmfFilterTreeNode getEventFilter(ITmfTrace trace) {
if (fField.equals(IFilterStrings.WILDCARD)) {
// Make a OR on all aspects
TmfFilterOrNode orNode = new TmfFilterOrNode(null);
for (ITmfEventAspect<?> aspect : trace.getEventAspects()) {
TmfFilterMatchesNode node = new TmfFilterMatchesNode(null);
node.setEventAspect(aspect);
node.setRegex(fValue);
orNode.addChild(node);
}
orNode.setNot(getNot());
return orNode;
}
// Find an event aspect corresponding to the field
ITmfEventAspect<?> filterAspect = null;
for (ITmfEventAspect<?> aspect : trace.getEventAspects()) {
if (aspect.getName().equals(fField)) {
filterAspect = aspect;
break;
}
}
if (filterAspect == null) {
// Fallback to a field aspect
filterAspect = TmfBaseAspects.getContentsAspect().forField(fField);
}
TmfFilterAspectNode conditionNode = createConditionNode();
conditionNode.setEventAspect(filterAspect);
return conditionNode;
}
use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode in project tracecompass by tracecompass.
the class TmfFilterContentHandler method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
ITmfFilterTreeNode node = null;
if (localName.equalsIgnoreCase(TmfFilterRootNode.NODE_NAME)) {
node = new TmfFilterRootNode();
} else if (localName.equals(TmfFilterNode.NODE_NAME)) {
node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));
} else if (localName.equals(TmfFilterTraceTypeNode.NODE_NAME)) {
node = new TmfFilterTraceTypeNode(null);
String traceTypeId = atts.getValue(TmfFilterTraceTypeNode.TYPE_ATTR);
traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
((TmfFilterTraceTypeNode) node).setTraceTypeId(traceTypeId);
TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
if (helper != null) {
((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
}
((TmfFilterTraceTypeNode) node).setName(atts.getValue(TmfFilterTraceTypeNode.NAME_ATTR));
} else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {
node = new TmfFilterAndNode(null);
} else if (localName.equals(TmfFilterOrNode.NODE_NAME)) {
node = new TmfFilterOrNode(null);
} else if (localName.equals(TmfFilterContainsNode.NODE_NAME)) {
node = new TmfFilterContainsNode(null);
createEventAspect((TmfFilterAspectNode) node, atts);
String value = atts.getValue(TmfFilterContainsNode.IGNORECASE_ATTR);
if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
((TmfFilterContainsNode) node).setIgnoreCase(true);
}
} else if (localName.equals(TmfFilterEqualsNode.NODE_NAME)) {
node = new TmfFilterEqualsNode(null);
createEventAspect((TmfFilterAspectNode) node, atts);
String value = atts.getValue(TmfFilterEqualsNode.IGNORECASE_ATTR);
if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
((TmfFilterEqualsNode) node).setIgnoreCase(true);
}
} else if (localName.equals(TmfFilterMatchesNode.NODE_NAME)) {
node = new TmfFilterMatchesNode(null);
createEventAspect((TmfFilterAspectNode) node, atts);
((TmfFilterMatchesNode) node).setRegex(atts.getValue(TmfFilterMatchesNode.REGEX_ATTR));
} else if (localName.equals(TmfFilterCompareNode.NODE_NAME)) {
node = new TmfFilterCompareNode(null);
createEventAspect((TmfFilterAspectNode) node, atts);
String value = atts.getValue(TmfFilterCompareNode.TYPE_ATTR);
if (value != null) {
((TmfFilterCompareNode) node).setType(Type.valueOf(value));
}
value = atts.getValue(TmfFilterCompareNode.RESULT_ATTR);
if (value != null) {
if (value.equals(Integer.toString(-1))) {
((TmfFilterCompareNode) node).setResult(-1);
} else if (value.equals(Integer.toString(1))) {
((TmfFilterCompareNode) node).setResult(1);
} else {
((TmfFilterCompareNode) node).setResult(0);
}
}
// Backward compatibility with event type filter node
} else if (localName.equals(EVENTTYPE_NODE_NAME)) {
node = new TmfFilterTraceTypeNode(null);
String label = atts.getValue(NAME_ATTR);
if (label != null) {
// Backward compatibility with renamed LTTng Kernel Trace
if (label.equals(LTTNG_KERNEL_TRACE)) {
label = LINUX_KERNEL_TRACE;
}
String traceTypeId = TmfTraceType.getTraceTypeId(label);
TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
if (helper == null) {
// Backward compatibility with category-less custom trace types
for (TraceTypeHelper h : TmfTraceType.getTraceTypeHelpers()) {
if (h.getName().equals(label)) {
label = h.getLabel();
helper = h;
break;
}
}
}
if (helper != null) {
((TmfFilterTraceTypeNode) node).setTraceTypeId(helper.getTraceTypeId());
((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
}
((TmfFilterTraceTypeNode) node).setName(label);
}
}
String value = atts.getValue(ITmfFilterWithNot.NOT_ATTRIBUTE);
if (node instanceof ITmfFilterWithNot && Boolean.TRUE.toString().equalsIgnoreCase(value)) {
((ITmfFilterWithNot) node).setNot(true);
}
if (node instanceof ITmfFilterWithValue) {
((ITmfFilterWithValue) node).setValue(atts.getValue(ITmfFilterWithValue.VALUE_ATTRIBUTE));
}
fFilterTreeStack.addFirst(node);
}
use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode in project tracecompass by tracecompass.
the class FilterTreeLabelProvider method getText.
@Override
public String getText(Object element) {
StringBuilder label = new StringBuilder();
if (element instanceof TmfFilterNode) {
TmfFilterNode node = (TmfFilterNode) element;
label.append(node.getNodeName()).append(' ').append(node.getFilterName() != null && !node.getFilterName().isEmpty() ? node.getFilterName() : Messages.FilterTreeLabelProvider_FilterNameHint);
} else if (element instanceof TmfFilterTraceTypeNode) {
TmfFilterTraceTypeNode node = (TmfFilterTraceTypeNode) element;
// $NON-NLS-1$
label.append(node.isNot() ? NOT : EMPTY_STRING).append("WITH ").append(node.getNodeName()).append(' ').append((node.getName() != null ? node.getName() : Messages.FilterTreeLabelProvider_TraceTypeHint));
} else if (element instanceof TmfFilterAndNode) {
TmfFilterAndNode node = (TmfFilterAndNode) element;
label.append((node.isNot() ? NOT : EMPTY_STRING)).append(node.getNodeName());
} else if (element instanceof TmfFilterOrNode) {
TmfFilterOrNode node = (TmfFilterOrNode) element;
label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getNodeName());
} else if (element instanceof TmfFilterContainsNode) {
TmfFilterContainsNode node = (TmfFilterContainsNode) element;
label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(' ').append(node.getNodeName()).append(node.getValue() != null ? new StringBuilder().append(SPACE_QUOTE).append(node.getValue()).append(QUOTE).toString() : EMPTY_STRING);
} else if (element instanceof TmfFilterEqualsNode) {
TmfFilterEqualsNode node = (TmfFilterEqualsNode) element;
label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(' ').append(node.getNodeName()).append(node.getValue() != null ? new StringBuilder().append(SPACE_QUOTE).append(node.getValue()).append(QUOTE).toString() : EMPTY_STRING);
} else if (element instanceof TmfFilterMatchesNode) {
TmfFilterMatchesNode node = (TmfFilterMatchesNode) element;
label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(' ').append(node.getNodeName()).append(node.getRegex() != null ? new StringBuilder().append(SPACE_QUOTE).append(node.getRegex()).append(QUOTE).toString() : EMPTY_STRING);
} else if (element instanceof TmfFilterCompareNode) {
TmfFilterCompareNode node = (TmfFilterCompareNode) element;
label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
node.getResult() < 0 ? " <" : (node.getResult() > 0 ? " >" : " =")).append(// $NON-NLS-1$
node.getType() == Type.ALPHA ? SPACE_QUOTE : node.getType() == Type.TIMESTAMP ? " [" : ' ').append(node.hasValidValue() ? node.getValue() : Messages.FilterTreeLabelProvider_ValueHint).append(node.getType() == Type.ALPHA ? '\"' : node.getType() == Type.TIMESTAMP ? ']' : EMPTY_STRING);
}
return label.toString();
}
Aggregations