01: /*
02: * FindBugs - Find bugs in Java programs
03: * Copyright (C) 2003,2004 University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs;
21:
22: import java.io.IOException;
23: import java.util.Collection;
24: import java.util.HashMap;
25: import java.util.LinkedList;
26: import java.util.Map;
27:
28: import edu.umd.cs.findbugs.filter.Matcher;
29: import edu.umd.cs.findbugs.xml.XMLOutput;
30:
31: public class SuppressionMatcher implements Matcher {
32: private Map<ClassAnnotation, Collection<WarningSuppressor>> suppressedWarnings = new HashMap<ClassAnnotation, Collection<WarningSuppressor>>();
33: private Map<String, Collection<WarningSuppressor>> suppressedPackageWarnings = new HashMap<String, Collection<WarningSuppressor>>();
34: int count = 0;
35:
36: public void addPackageSuppressor(PackageWarningSuppressor suppressor) {
37: String packageName = suppressor.getPackageName();
38:
39: Collection<WarningSuppressor> c = suppressedPackageWarnings
40: .get(packageName);
41: if (c == null) {
42: c = new LinkedList<WarningSuppressor>();
43: suppressedPackageWarnings.put(packageName, c);
44: }
45: c.add(suppressor);
46: }
47:
48: public void addSuppressor(ClassWarningSuppressor suppressor) {
49: ClassAnnotation clazz = suppressor.getClassAnnotation()
50: .getTopLevelClass();
51: Collection<WarningSuppressor> c = suppressedWarnings.get(clazz);
52: if (c == null) {
53: c = new LinkedList<WarningSuppressor>();
54: suppressedWarnings.put(clazz, c);
55: }
56: c.add(suppressor);
57: }
58:
59: public int count() {
60: return count;
61: }
62:
63: public boolean match(BugInstance b) {
64: ClassAnnotation clazz = b.getPrimaryClass().getTopLevelClass();
65: Collection<WarningSuppressor> c = suppressedWarnings.get(clazz);
66: if (c != null)
67: for (WarningSuppressor w : c)
68: if (w.match(b)) {
69: count++;
70: return true;
71: }
72: for (Collection<WarningSuppressor> c2 : suppressedPackageWarnings
73: .values())
74: for (WarningSuppressor w : c2) {
75: if (w.match(b)) {
76: count++;
77: return true;
78: }
79: }
80: return false;
81: }
82:
83: public void writeXML(XMLOutput xmlOutput, boolean disabled)
84: throws IOException {
85: // no-op; these aren't saved to XML
86: }
87:
88: }
89:
90: // vim:ts=4
|