use of edu.umd.cs.findbugs.filter.Matcher in project spotbugs by spotbugs.
the class FilterFromBugPicker method makeMatcherFromSelection.
public Matcher makeMatcherFromSelection() {
HashSet<Sortables> set = new HashSet<>();
for (Map.Entry<JCheckBox, Sortables> e : map.entrySet()) {
if (e.getKey().isSelected()) {
set.add(e.getValue());
}
}
Matcher matcher = null;
if (!set.isEmpty()) {
matcher = FilterFactory.makeMatcher(set, bug);
if (notFilterCheck.isSelected()) {
matcher = FilterFactory.invertMatcher(matcher);
}
}
return matcher;
}
use of edu.umd.cs.findbugs.filter.Matcher in project spotbugs by spotbugs.
the class FilterFactoryTest method shouldReturnTheOriginalMatcherWhenAskedToInvertANotMatcher.
@Test
public void shouldReturnTheOriginalMatcherWhenAskedToInvertANotMatcher() {
BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0);
Matcher originalMatcher = FilterFactory.makeMatcher(asList(Sortables.BUGCODE), bug);
Matcher notMatcher = FilterFactory.invertMatcher(originalMatcher);
Matcher notNotMatcher = FilterFactory.invertMatcher(notMatcher);
assertSame("Should return the originally wrapped matcher.", originalMatcher, notNotMatcher);
assertTrue("Original matcher should now not match.", notNotMatcher.match(bug));
}
use of edu.umd.cs.findbugs.filter.Matcher in project spotbugs by spotbugs.
the class MainFrameLoadSaveHelper method importFilter.
/**
* This method is for when the user wants to open a file.
*/
void importFilter() {
filterOpenFileChooser.setDialogTitle(L10N.getLocalString("dlg.importFilter_ttl", "Import and merge filter..."));
boolean retry = true;
File f;
while (retry) {
retry = false;
int value = filterOpenFileChooser.showOpenDialog(mainFrame);
if (value != JFileChooser.APPROVE_OPTION) {
return;
}
f = filterOpenFileChooser.getSelectedFile();
if (!f.exists()) {
JOptionPane.showMessageDialog(filterOpenFileChooser, "No such file", "Invalid File", JOptionPane.WARNING_MESSAGE);
retry = true;
continue;
}
Filter filter;
try {
filter = Filter.parseFilter(f.getPath());
} catch (IOException e) {
JOptionPane.showMessageDialog(filterOpenFileChooser, "Could not load filter.");
retry = true;
continue;
}
mainFrame.setProjectChanged(true);
Filter suppressionFilter = mainFrame.getProject().getSuppressionFilter();
for (Matcher m : filter.getChildren()) {
suppressionFilter.addChild(m);
}
PreferencesFrame.getInstance().updateFilterPanel();
}
}
use of edu.umd.cs.findbugs.filter.Matcher in project spotbugs by spotbugs.
the class MainFrameTree method createBranchPopUpMenu.
/**
* Creates the branch pop up menu that ask if the user wants to hide all the
* bugs in that branch.
*/
JPopupMenu createBranchPopUpMenu() {
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem filterMenuItem = MainFrameHelper.newJMenuItem("menu.filterTheseBugs", "Filter these bugs");
filterMenuItem.addActionListener(evt -> {
try {
int startCount;
TreePath path = MainFrame.getInstance().getTree().getSelectionPath();
TreePath deletePath = path;
startCount = ((BugAspects) (path.getLastPathComponent())).getCount();
int count = ((BugAspects) (path.getParentPath().getLastPathComponent())).getCount();
while (count == startCount) {
deletePath = deletePath.getParentPath();
if (// We are at the
deletePath.getParentPath() == null) // top of the
// tree, don't
// let this be
// removed,
// rebuild tree
// from root.
{
Matcher m1 = mainFrame.getCurrentSelectedBugAspects().getMatcher();
Filter suppressionFilter1 = MainFrame.getInstance().getProject().getSuppressionFilter();
suppressionFilter1.addChild(m1);
PreferencesFrame.getInstance().updateFilterPanel();
FilterActivity.notifyListeners(FilterListener.Action.FILTERING, null);
return;
}
count = ((BugAspects) (deletePath.getParentPath().getLastPathComponent())).getCount();
}
/*
* deletePath should now be a path to the highest ancestor
* branch with the same number of elements as the branch to
* be deleted in other words, the branch that we actually
* have to remove in order to correctly remove the selected
* branch.
*/
BugTreeModel model = MainFrame.getInstance().getBugTreeModel();
TreeModelEvent event = new TreeModelEvent(mainFrame, deletePath.getParentPath(), new int[] { model.getIndexOfChild(deletePath.getParentPath().getLastPathComponent(), deletePath.getLastPathComponent()) }, new Object[] { deletePath.getLastPathComponent() });
Matcher m2 = mainFrame.getCurrentSelectedBugAspects().getMatcher();
Filter suppressionFilter2 = MainFrame.getInstance().getProject().getSuppressionFilter();
suppressionFilter2.addChild(m2);
PreferencesFrame.getInstance().updateFilterPanel();
model.sendEvent(event, BugTreeModel.TreeModification.REMOVE);
// FilterActivity.notifyListeners(FilterListener.Action.FILTERING,
// null);
mainFrame.setProjectChanged(true);
// Selects
MainFrame.getInstance().getTree().setSelectionRow(0);
// the
// top
// of
// the
// Jtree
// so
// the
// CommentsArea
// syncs
// up.
} catch (RuntimeException e) {
MainFrame.getInstance().showMessageDialog("Unable to create filter: " + e.getMessage());
}
});
popupMenu.add(filterMenuItem);
return popupMenu;
}
use of edu.umd.cs.findbugs.filter.Matcher in project spotbugs by spotbugs.
the class PreferencesFrame method updateFilterPanel.
void updateFilterPanel() {
ArrayList<MatchBox> boxes = new ArrayList<>();
final Filter f = MainFrame.getInstance().getProject().getSuppressionFilter();
for (final Matcher m : f.getChildren()) {
MatchBox box = new MatchBox(m.toString(), m);
box.addItemListener(evt -> {
boolean isSelected = ((JCheckBox) evt.getSource()).isSelected();
boolean wasSelected = f.isEnabled(m);
if (isSelected == wasSelected) {
return;
}
f.setEnabled(m, isSelected);
updateFilters(isSelected);
});
box.setSelected(f.isEnabled(m));
boxes.add(box);
}
filterCheckBoxList.setListData(boxes.toArray(new MatchBox[boxes.size()]));
}
Aggregations