public static Filter parseFilter(String fileName) throws IOException { return new Filter(fileName); }
@Override public boolean match(BugInstance bugInstance) { Iterator<Matcher> i = childIterator(); while (i.hasNext()) { Matcher child = i.next(); if (isEnabled(child) && child.match(bugInstance)) { return true; } } return false; }
public static void main(String[] argv) { try { if (argv.length != 1) { System.err.println("Usage: " + Filter.class.getName() + " <filename>"); System.exit(1); } Filter filter = new Filter(argv[0]); filter.writeAsXML(System.out); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
if (!applySuppressions || !project.getSuppressionFilter().match(bugInstance)) { bugInstance.writeXML(xmlOutput, this, withMessages);
@Test public void readXML() throws Exception { SourceMatcher sm = new SourceMatcher(fileName); String xml = writeXMLAndGetStringOutput(sm, false); xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n<FindBugsFilter>" + "\n<Match>" + "\n" + xml + "\n</Match>" + "\n</FindBugsFilter>\n"; Filter filter = new Filter(new StringInputStream(xml)); assertFalse(filter.match(bug)); bug.addClass("bla", fileName); assertTrue(filter.match(bug)); }
if (!suppressionFilter.isEmpty()) { xmlOutput.openTag("SuppressionFilter"); suppressionFilter.writeBodyAsXML(xmlOutput); xmlOutput.closeTag("SuppressionFilter");
/** * Constructor. * * @param stream * content of the filter file * @throws IOException */ public Filter(InputStream stream) throws IOException { try { parse("", stream); } catch (SAXException e) { throw new IOException(e.getMessage()); } }
void updateFilterPanel() { ArrayList<MatchBox> boxes = new ArrayList<MatchBox>(); final Filter f = MainFrame.getInstance().getProject().getSuppressionFilter(); for (final Matcher m : f.getChildren()) { MatchBox box = new MatchBox(m.toString(), m); box.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent 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()])); }
filter = Filter.parseFilter(f.getPath()); } catch (IOException e) { JOptionPane.showMessageDialog(filterOpenFileChooser, "Could not load filter."); Filter suppressionFilter = mainFrame.getProject().getSuppressionFilter(); for (Matcher m : filter.getChildren()) { suppressionFilter.addChild(m);
public void writeBodyAsXML(XMLOutput xmlOutput) throws IOException { Iterator<Matcher> i = childIterator(); while (i.hasNext()) { Matcher child = i.next(); child.writeXML(xmlOutput, disabled.containsKey(child)); } }
@Override public void removeChild(Matcher child) { enable(child);// Remove from disabled before removing it super.removeChild(child); }
@Override public void itemStateChanged(ItemEvent evt) { boolean isSelected = ((JCheckBox) evt.getSource()).isSelected(); boolean wasSelected = f.isEnabled(m); if (isSelected == wasSelected) { return; } f.setEnabled(m, isSelected); updateFilters(isSelected); } });
@Override public void actionPerformed(ActionEvent evt) { boolean needsRebuild = false; Filter suppressionFilter = MainFrame.getInstance().getProject().getSuppressionFilter(); if (!suppressionFilter.isEmpty()) { needsRebuild = true; } suppressionFilter.clear(); if (needsRebuild) { // filters being cleared were disabled FilterActivity.notifyListeners(FilterListener.Action.UNFILTERING, null); } MainFrame.getInstance().setProjectChanged(true); updateFilterPanel(); } });
private void addMatcher(Matcher m) { if (m == null) { throw new IllegalArgumentException("matcher must not be null"); } CompoundMatcher peek = matcherStack.peek(); if (peek == null) { throw new NullPointerException("Top of stack is null"); } peek.addChild(m); if (nextMatchedIsDisabled) { if (peek instanceof Filter) { ((Filter) peek).disable(m); } else { assert false; } nextMatchedIsDisabled = false; } }
project.setSuppressionFilter(Filter.parseFilter(commandLine.exclusionFilterFile));
if (!reporter.isApplySuppressions() || !bugCollection.getProject().getSuppressionFilter().match(warning)) { int rank = warning.getBugRank(); BugPattern pattern = warning.getBugPattern();
public static void main(String[] argv) { try { if (argv.length != 1) { System.err.println("Usage: " + Filter.class.getName() + " <filename>"); System.exit(1); } Filter filter = new Filter(argv[0]); filter.writeAsXML(System.out); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
if (!suppressionFilter.isEmpty()) { xmlOutput.openTag("SuppressionFilter"); suppressionFilter.writeBodyAsXML(xmlOutput); xmlOutput.closeTag("SuppressionFilter");
/** * Constructor. * * @param fileName * name of the filter file * @throws IOException */ public Filter(String fileName) throws IOException { try { parse(fileName); } catch (SAXException e) { throw new IOException(e.getMessage()); } }