1 19 20 package edu.umd.cs.findbugs.plan; 21 22 import java.util.Collection ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.LinkedList ; 26 import java.util.Set ; 27 28 import edu.umd.cs.findbugs.BugReporter; 29 import edu.umd.cs.findbugs.Detector; 30 import edu.umd.cs.findbugs.Detector2; 31 import edu.umd.cs.findbugs.DetectorFactory; 32 import edu.umd.cs.findbugs.FindBugs2; 33 34 41 public class AnalysisPass { 42 private LinkedList <DetectorFactory> orderedFactoryList; 43 private HashSet <DetectorFactory> memberSet; 44 46 51 public AnalysisPass() { 52 this.orderedFactoryList = new LinkedList <DetectorFactory>(); 53 this.memberSet = new HashSet <DetectorFactory>(); 54 } 55 56 62 public void addToPass(DetectorFactory factory) { 63 this.memberSet.add(factory); 64 } 65 66 72 public void append(DetectorFactory factory) { 73 if (!memberSet.contains(factory)) 74 throw new IllegalArgumentException ("Detector " + factory.getFullName() + " appended to pass it doesn't belong to"); 75 this.orderedFactoryList.addLast(factory); 76 } 77 78 83 public Collection <DetectorFactory> getMembers() { 84 return memberSet; 85 } 86 87 90 public Set <DetectorFactory> getUnpositionedMembers() { 91 HashSet <DetectorFactory> result = new HashSet <DetectorFactory>(memberSet); 92 result.removeAll(orderedFactoryList); 93 return result; 94 } 95 96 100 public Iterator <DetectorFactory> iterator() { 101 return orderedFactoryList.iterator(); 102 } 103 104 110 public boolean contains(DetectorFactory factory) { 111 return memberSet.contains(factory); 112 } 113 114 121 public Detector2[] instantiateDetector2sInPass(BugReporter bugReporter) { 122 Detector2[] detectorList = new Detector2[orderedFactoryList.size()]; 123 int count = 0; 124 for (Iterator <DetectorFactory> j = iterator(); j.hasNext();) { 125 detectorList[count++] = j.next().createDetector2(bugReporter); 126 } 127 return detectorList; 128 } 129 130 140 public Detector[] instantiateDetectorsInPass(BugReporter bugReporter) { 141 int count; 142 143 count = 0; 144 for (DetectorFactory factory : orderedFactoryList) { 145 if (factory.isDetectorClassSubtypeOf(Detector.class)) { 146 count++; 147 } 148 } 149 150 Detector[] detectorList = new Detector[count]; 151 152 count = 0; 153 for (DetectorFactory factory : orderedFactoryList) { 154 if (factory.isDetectorClassSubtypeOf(Detector.class)) { 155 detectorList[count++] = factory.create(bugReporter); 156 } 157 } 158 159 return detectorList; 160 } 161 } 162 163 | Popular Tags |