Package edu.umd.cs.findbugs
Class FuzzyBugComparator
- java.lang.Object
-
- edu.umd.cs.findbugs.FuzzyBugComparator
-
- All Implemented Interfaces:
WarningComparator
,java.io.Serializable
,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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FuzzyBugComparator.FilteringBugAnnotationIterator
Filter ignored BugAnnotations from given Iterator.
-
Field Summary
Fields Modifier and Type Field Description private java.util.IdentityHashMap<BugInstance,BugCollection>
bugCollectionMap
Keep track of which BugCollections the various BugInstances have come from.private ClassNameRewriter
classNameRewriter
private static boolean
DEBUG
private static java.util.HashSet<java.lang.String>
significantDescriptionSet
-
Constructor Summary
Constructors Constructor Description FuzzyBugComparator()
Map of class hashes to canonicate class names used for comparison purposes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
private static int
compareNullElements(java.lang.Object a, java.lang.Object b)
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.private java.lang.String
rewriteClassName(java.lang.String className)
void
setClassNameRewriter(ClassNameRewriter classNameRewriter)
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
-
bugCollectionMap
private final java.util.IdentityHashMap<BugInstance,BugCollection> bugCollectionMap
Keep track of which BugCollections the various BugInstances have come from.
-
classNameRewriter
private ClassNameRewriter classNameRewriter
-
significantDescriptionSet
@StaticConstant private static final java.util.HashSet<java.lang.String> significantDescriptionSet
-
-
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 interfaceWarningComparator
-
compare
public int compare(BugInstance lhs, BugInstance rhs)
- Specified by:
compare
in interfacejava.util.Comparator<BugInstance>
- Specified by:
compare
in interfaceWarningComparator
-
compareNullElements
private static int compareNullElements(java.lang.Object a, java.lang.Object b)
-
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)
-
rewriteClassName
private java.lang.String rewriteClassName(java.lang.String className)
- Parameters:
className
-- Returns:
- the rewritten class name
-
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 BugCollectionlhsCollection
- rhs BugCollectionlhs
- a SourceLineAnnotationrhs
- another SourceLineAnnotation- Returns:
- comparison of lhs and rhs
-
ignore
public static boolean ignore(BugAnnotation annotation)
-
-