KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2005, 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
28 public class BugAccumulator {
29     
30     private BugReporter reporter;
31     public BugAccumulator( BugReporter reporter) {
32         this.reporter = reporter;
33     }
34     
35     private Map JavaDoc<BugInstance, LinkedList JavaDoc<SourceLineAnnotation>> map
36             = new HashMap JavaDoc<BugInstance, LinkedList JavaDoc<SourceLineAnnotation>>();
37     
38     
39     public void accumulateBug(BugInstance bug, SourceLineAnnotation sourceLine) {
40         LinkedList JavaDoc<SourceLineAnnotation> where = map.get(bug);
41         if (where == null) {
42             where = new LinkedList JavaDoc<SourceLineAnnotation>();
43             map.put(bug,where);
44         }
45         where.add(sourceLine);
46     }
47     
48
49     public void accumulateBug(BugInstance bug, BytecodeScanningDetector visitor) {
50         SourceLineAnnotation source = SourceLineAnnotation.fromVisitedInstruction(visitor);
51         accumulateBug(bug, source);
52     }
53     public void reportAccumulatedBugs() {
54         for(Map.Entry JavaDoc<BugInstance,LinkedList JavaDoc<SourceLineAnnotation>> e : map.entrySet()) {
55             BugInstance bug = e.getKey();
56             for(SourceLineAnnotation source : e.getValue())
57                 if (source != null) bug.addSourceLine(source);
58             reporter.reportBug(bug);
59         }
60         map.clear();
61     }
62 }
63
Popular Tags