KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > SuppressionMatcher


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2003,2004 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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.util.Collection JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import edu.umd.cs.findbugs.filter.Matcher;
28
29 public class SuppressionMatcher implements Matcher {
30     private Map JavaDoc <ClassAnnotation, Collection JavaDoc<WarningSuppressor>> suppressedWarnings
31             = new HashMap JavaDoc<ClassAnnotation, Collection JavaDoc<WarningSuppressor>>();
32     private Map JavaDoc <String JavaDoc, Collection JavaDoc<WarningSuppressor>> suppressedPackageWarnings
33             = new HashMap JavaDoc<String JavaDoc, Collection JavaDoc<WarningSuppressor>>();
34     int count = 0;
35
36     public void addPackageSuppressor(PackageWarningSuppressor suppressor) {
37         String JavaDoc packageName = suppressor.getPackageName();
38
39         Collection JavaDoc<WarningSuppressor> c = suppressedPackageWarnings.get(packageName);
40         if (c == null) {
41             c = new LinkedList JavaDoc<WarningSuppressor>();
42             suppressedPackageWarnings.put(packageName,c);
43             }
44             c.add(suppressor);
45         }
46         
47     public void addSuppressor(ClassWarningSuppressor suppressor) {
48         ClassAnnotation clazz = suppressor.getClassAnnotation().getTopLevelClass();
49         Collection JavaDoc<WarningSuppressor> c = suppressedWarnings.get(clazz);
50         if (c == null) {
51             c = new LinkedList JavaDoc<WarningSuppressor>();
52             suppressedWarnings.put(clazz,c);
53             }
54             c.add(suppressor);
55     }
56     public int count() {
57         return count;
58         }
59     public boolean match(BugInstance b) {
60         ClassAnnotation clazz = b.getPrimaryClass().getTopLevelClass();
61         Collection JavaDoc<WarningSuppressor> c = suppressedWarnings.get(clazz);
62         if (c != null)
63         for(WarningSuppressor w : c)
64             if (w.match(b)) {
65                 count++;
66                 return true;
67                 }
68         for(Collection JavaDoc<WarningSuppressor> c2 : suppressedPackageWarnings.values())
69           for(WarningSuppressor w : c2) {
70             if (w.match(b)) {
71                 count++;
72                 return true;
73                 }
74             }
75         return false;
76         }
77         
78
79 }
80
81 // vim:ts=4
82
Popular Tags