1 19 20 package edu.umd.cs.findbugs; 21 22 import java.util.Collection ; 23 import java.util.HashMap ; 24 import java.util.LinkedList ; 25 import java.util.Map ; 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 <BugInstance, LinkedList <SourceLineAnnotation>> map 36 = new HashMap <BugInstance, LinkedList <SourceLineAnnotation>>(); 37 38 39 public void accumulateBug(BugInstance bug, SourceLineAnnotation sourceLine) { 40 LinkedList <SourceLineAnnotation> where = map.get(bug); 41 if (where == null) { 42 where = new LinkedList <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 <BugInstance,LinkedList <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 |