edu.umd.cs.findbugs
Class FuzzyBugComparator

java.lang.Object
  extended by edu.umd.cs.findbugs.FuzzyBugComparator
All Implemented Interfaces:
WarningComparator, java.util.Comparator<BugInstance>

public class FuzzyBugComparator
extends java.lang.Object
implements WarningComparator

A slightly more intellegent way of comparing BugInstances from two versions to see if they are the "same". Uses class and method hashes to try to handle renamings, at least for simple cases. (Hashes disabled for the time being.) Uses opcode context to try to identify code that is the same, even if it moves within the method. Also compares by bug abbreviation rather than bug type, since the "same" bug can change type if the context changes (e.g., "definitely null" to "null on simple path" for a null pointer dereference). Also, we often change bug types between different versions of FindBugs.

Author:
David Hovemeyer
See Also:
BugInstance, VersionInsensitiveBugComparator

Constructor Summary
FuzzyBugComparator()
           
 
Method Summary
 int compare(BugInstance lhs, BugInstance rhs)
           
 int compareClasses(BugCollection lhsCollection, BugCollection rhsCollection, ClassAnnotation lhsClass, ClassAnnotation rhsClass)
           
 int compareClassesByName(BugCollection lhsCollection, BugCollection rhsCollection, java.lang.String lhsClassName, java.lang.String rhsClassName)
           
 int compareMethods(BugCollection lhsCollection, BugCollection rhsCollection, MethodAnnotation lhsMethod, MethodAnnotation rhsMethod)
           
 int compareSourceLines(BugCollection lhsCollection, BugCollection rhsCollection, SourceLineAnnotation lhs, SourceLineAnnotation rhs)
          Compare source line annotations.
static boolean ignore(BugAnnotation annotation)
           
 void registerBugCollection(BugCollection bugCollection)
          Register a BugCollection.
 void setClassNameRewriter(ClassNameRewriter classNameRewriter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

FuzzyBugComparator

public FuzzyBugComparator()
Method Detail

registerBugCollection

public void registerBugCollection(BugCollection bugCollection)
Register a BugCollection. This allows us to find the class and method hashes for BugInstances to be compared.

Parameters:
bugCollection - a BugCollection

setClassNameRewriter

public void setClassNameRewriter(ClassNameRewriter classNameRewriter)
Specified by:
setClassNameRewriter in interface WarningComparator
Parameters:
classNameRewriter - The classNameRewriter to set.

compare

public int compare(BugInstance lhs,
                   BugInstance rhs)
Specified by:
compare in interface WarningComparator
Specified by:
compare in interface java.util.Comparator<BugInstance>

compareClasses

public int compareClasses(BugCollection lhsCollection,
                          BugCollection rhsCollection,
                          ClassAnnotation lhsClass,
                          ClassAnnotation rhsClass)

compareClassesByName

public int compareClassesByName(BugCollection lhsCollection,
                                BugCollection rhsCollection,
                                java.lang.String lhsClassName,
                                java.lang.String rhsClassName)

compareMethods

public int compareMethods(BugCollection lhsCollection,
                          BugCollection rhsCollection,
                          MethodAnnotation lhsMethod,
                          MethodAnnotation rhsMethod)

compareSourceLines

public int compareSourceLines(BugCollection lhsCollection,
                              BugCollection rhsCollection,
                              SourceLineAnnotation lhs,
                              SourceLineAnnotation rhs)
Compare source line annotations.

Parameters:
rhsCollection - lhs BugCollection
lhsCollection - rhs BugCollection
lhs - a SourceLineAnnotation
rhs - another SourceLineAnnotation
Returns:
comparison of lhs and rhs

ignore

public static boolean ignore(BugAnnotation annotation)