Package com.mebigfatguy.fbcontrib.detect
Class CollectionNamingConfusion
java.lang.Object
edu.umd.cs.findbugs.visitclass.BetterVisitor
edu.umd.cs.findbugs.visitclass.PreorderVisitor
com.mebigfatguy.fbcontrib.detect.CollectionNamingConfusion
- All Implemented Interfaces:
edu.umd.cs.findbugs.Detector,edu.umd.cs.findbugs.Priorities,org.apache.bcel.classfile.Visitor
public class CollectionNamingConfusion
extends edu.umd.cs.findbugs.visitclass.PreorderVisitor
implements edu.umd.cs.findbugs.Detector
looks for fields and local variables that have Map, Set, List, Queue, Deque, Stack in their names
but the variable is a collection of a different basic type.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate edu.umd.cs.findbugs.BugReporterprivate edu.umd.cs.findbugs.ba.ClassContextprivate org.apache.bcel.classfile.JavaClassprivate static final Patternprivate org.apache.bcel.classfile.JavaClassprivate org.apache.bcel.classfile.JavaClassprivate org.apache.bcel.classfile.JavaClassprivate org.apache.bcel.classfile.JavaClassprivate static final Patternprivate org.apache.bcel.classfile.JavaClassFields inherited from interface edu.umd.cs.findbugs.Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionCollectionNamingConfusion(edu.umd.cs.findbugs.BugReporter bugReporter) constructs a CNC detector given the reporter to report bugs on -
Method Summary
Modifier and TypeMethodDescriptionprivate booleancheckConfusedName(String methodOrVariableName, String signature) looks for a name that mentions a collection type but the wrong type for the variableprivate StringlastNameSegment(String variableName) voidreport()implements the visitor by does nothingvoidvisitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext) overrides the visitor to make sure that the static initializer was able to load the map classvoidvisitField(org.apache.bcel.classfile.Field obj) overrides the visitor to look for fields where the name has 'Map', 'Set', 'List' in it but the type of that field isn't that.voidvisitMethod(org.apache.bcel.classfile.Method obj) overrides the visitor to look for local variables where the name has 'Map', 'Set', 'List' in it but the type of that field isn't that.Methods inherited from class edu.umd.cs.findbugs.visitclass.PreorderVisitor
amVisitingMainMethod, asUnsignedByte, doVisitMethod, getClassDescriptor, getClassName, getCode, getConstantPool, getDottedClassName, getDottedFieldSig, getDottedMethodSig, getDottedSuperclassName, getField, getFieldDescriptor, getFieldIsStatic, getFieldName, getFieldSig, getFullyQualifiedFieldName, getFullyQualifiedMethodName, getMethod, getMethodDescriptor, getMethodName, getMethodSig, getMethodVisitOrder, getNumberArguments, getNumberMethodArguments, getPackageName, getSizeOfSurroundingTryBlock, getSizeOfSurroundingTryBlock, getSourceFile, getStringFromIndex, getSuperclassName, getSurroundingCaughtExceptions, getSurroundingCaughtExceptions, getSurroundingCaughtExceptionTypes, getSurroundingTryBlock, getSurroundingTryBlock, getThisClass, getXClass, getXField, getXMethod, hasInterestingClass, hasInterestingMethod, isVisitMethodsInCallOrder, setupVisitorForClass, setVisitMethodsInCallOrder, shouldVisit, toString, visitAfter, visitAfter, visitAnnotation, visitAnnotationDefault, visitAnnotationEntry, visitBootstrapMethods, visitCode, visitConstantInvokeDynamic, visitConstantMethodHandle, visitConstantMethodType, visitConstantModule, visitConstantPackage, visitConstantPool, visitEnclosingMethod, visitingField, visitingMethod, visitInnerClasses, visitJavaClass, visitLineNumberTable, visitLocalVariableTable, visitMethodParameters, visitParameterAnnotation, visitParameterAnnotationEntry, visitStackMap, visitStackMapEntryMethods inherited from class edu.umd.cs.findbugs.visitclass.BetterVisitor
clone, report, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitCodeException, visitConstantClass, visitConstantDouble, visitConstantFieldref, visitConstantFloat, visitConstantInteger, visitConstantInterfaceMethodref, visitConstantLong, visitConstantMethodref, visitConstantNameAndType, visitConstantString, visitConstantUtf8, visitConstantValue, visitDeprecated, visitExceptionTable, visitInnerClass, visitLineNumber, visitLocalVariable, visitLocalVariableTypeTable, visitSignature, visitSourceFile, visitSynthetic, visitUnknownMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.bcel.classfile.Visitor
visitConstantDynamic, visitMethodParameter, visitModule, visitModuleExports, visitModuleMainClass, visitModuleOpens, visitModulePackages, visitModuleProvides, visitModuleRequires, visitNestHost, visitNestMembers, visitRecord, visitRecordComponent, visitStackMapType
-
Field Details
-
LAST_SEGMENTED_VARIABLE
-
SINGLE_SEGMENTED_VARIABLE
-
mapInterface
private org.apache.bcel.classfile.JavaClass mapInterface -
setInterface
private org.apache.bcel.classfile.JavaClass setInterface -
listInterface
private org.apache.bcel.classfile.JavaClass listInterface -
queueInterface
private org.apache.bcel.classfile.JavaClass queueInterface -
dequeInterface
private org.apache.bcel.classfile.JavaClass dequeInterface -
stackClass
private org.apache.bcel.classfile.JavaClass stackClass -
bugReporter
private edu.umd.cs.findbugs.BugReporter bugReporter -
clsContext
private edu.umd.cs.findbugs.ba.ClassContext clsContext
-
-
Constructor Details
-
CollectionNamingConfusion
public CollectionNamingConfusion(edu.umd.cs.findbugs.BugReporter bugReporter) constructs a CNC detector given the reporter to report bugs on- Parameters:
bugReporter- the sync of bug reports
-
-
Method Details
-
visitClassContext
public void visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext) overrides the visitor to make sure that the static initializer was able to load the map class- Specified by:
visitClassContextin interfaceedu.umd.cs.findbugs.Detector- Parameters:
classContext- the currently parsed class
-
visitField
public void visitField(org.apache.bcel.classfile.Field obj) overrides the visitor to look for fields where the name has 'Map', 'Set', 'List' in it but the type of that field isn't that.- Specified by:
visitFieldin interfaceorg.apache.bcel.classfile.Visitor- Overrides:
visitFieldin classedu.umd.cs.findbugs.visitclass.BetterVisitor- Parameters:
obj- the currently parsed field
-
visitMethod
public void visitMethod(org.apache.bcel.classfile.Method obj) overrides the visitor to look for local variables where the name has 'Map', 'Set', 'List' in it but the type of that field isn't that. note that this only is useful if compiled with debug labels.- Specified by:
visitMethodin interfaceorg.apache.bcel.classfile.Visitor- Overrides:
visitMethodin classedu.umd.cs.findbugs.visitclass.BetterVisitor- Parameters:
obj- the currently parsed method
-
checkConfusedName
looks for a name that mentions a collection type but the wrong type for the variable- Parameters:
methodOrVariableName- the method or variable namesignature- the variable signature- Returns:
- whether the name doesn't match the type
-
lastNameSegment
-
report
public void report()implements the visitor by does nothing- Specified by:
reportin interfaceedu.umd.cs.findbugs.Detector
-