use of edu.umd.cs.findbugs.plan.ExecutionPlan in project wcomponents by BorderTech.
the class CheckExpectedWarningsCustom method visitClass.
/**
* {@inheritDoc}
*/
@Override
public void visitClass(final ClassDescriptor classDescriptor) throws CheckedAnalysisException {
if (reporter == null) {
if (!warned) {
System.err.println("*** NOTE ***: CheckExpectedWarnings disabled because bug reporter doesn't use a BugCollection");
warned = true;
}
return;
}
if (warningsByMethod == null) {
//
// Build index of all warnings reported so far, by method.
// Because this detector runs in a later pass than any
// reporting detector, all warnings should have been
// produced by this point.
//
warningsByMethod = new HashMap<>();
warningsByField = new HashMap<>();
warningsByClass = new HashMap<>();
BugCollection bugCollection = reporter.getBugCollection();
for (Iterator<BugInstance> i = bugCollection.iterator(); i.hasNext(); ) {
BugInstance warning = i.next();
MethodAnnotation method = warning.getPrimaryMethod();
FieldAnnotation field = warning.getPrimaryField();
ClassAnnotation clazz = warning.getPrimaryClass();
if (method != null) {
MethodDescriptor methodDesc = method.toXMethod().getMethodDescriptor();
Collection<BugInstance> warnings = warningsByMethod.get(methodDesc);
if (warnings == null) {
warnings = new LinkedList<>();
warningsByMethod.put(methodDesc, warnings);
}
warnings.add(warning);
} else if (field != null) {
FieldDescriptor fieldDesc = XFactory.createXField(field).getFieldDescriptor();
Collection<BugInstance> warnings = warningsByField.get(fieldDesc);
if (warnings == null) {
warnings = new LinkedList<>();
warningsByField.put(fieldDesc, warnings);
}
warnings.add(warning);
} else if (clazz != null) {
ClassDescriptor classDesc = DescriptorFactory.createClassDescriptorFromDottedClassName(clazz.getClassName());
Collection<BugInstance> warnings = warningsByClass.get(classDesc);
if (warnings == null) {
warnings = new LinkedList<>();
warningsByClass.put(classDesc, warnings);
}
warnings.add(warning);
}
}
//
// Based on enabled detectors, figure out which bug codes
// could possibly be reported. Don't complain about
// expected warnings that would be produced by detectors
// that aren't enabled.
//
possibleBugCodes = new HashSet<>();
ExecutionPlan executionPlan = Global.getAnalysisCache().getDatabase(ExecutionPlan.class);
for (Iterator<AnalysisPass> i = executionPlan.passIterator(); i.hasNext(); ) {
AnalysisPass pass = i.next();
for (Iterator<DetectorFactory> j = pass.iterator(); j.hasNext(); ) {
DetectorFactory factory = j.next();
Collection<BugPattern> reportedPatterns = factory.getReportedBugPatterns();
for (BugPattern pattern : reportedPatterns) {
possibleBugCodes.add(pattern.getAbbrev());
}
}
}
if (DEBUG) {
log("CEW: possible warnings are " + possibleBugCodes);
}
}
XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, classDescriptor);
for (XMethod xmethod : xclass.getXMethods()) {
if (DEBUG) {
log("CEW: checking " + xmethod.toString());
}
check(xmethod, expectWarning, true);
check(xmethod, noWarning, false);
}
for (XField xfield : xclass.getXFields()) {
if (DEBUG) {
log("CEW: checking " + xfield.toString());
}
check(xfield, expectWarning, true);
check(xfield, noWarning, false);
}
check(xclass, expectWarning, true);
check(xclass, noWarning, false);
}
Aggregations