Class UnboundMethodTemplateParameter

java.lang.Object
edu.umd.cs.findbugs.visitclass.BetterVisitor
edu.umd.cs.findbugs.visitclass.PreorderVisitor
com.mebigfatguy.fbcontrib.detect.UnboundMethodTemplateParameter
All Implemented Interfaces:
edu.umd.cs.findbugs.Detector, edu.umd.cs.findbugs.Priorities, org.apache.bcel.classfile.Visitor

public class UnboundMethodTemplateParameter extends edu.umd.cs.findbugs.visitclass.PreorderVisitor implements edu.umd.cs.findbugs.Detector
Looks for methods that declare method level template parameter(s) that are not bound to any of the method's parameters, and thus is not adding any validation/type safety to the method, and is just confusing.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static class 
     
    (package private) static class 
    a simple data only class for holding the template parameters and method signature
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final edu.umd.cs.findbugs.BugReporter
     
    private static final Pattern
     
    private static final Pattern
     

    Fields inherited from interface edu.umd.cs.findbugs.Priorities

    EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
  • Constructor Summary

    Constructors
    Constructor
    Description
    UnboundMethodTemplateParameter(edu.umd.cs.findbugs.BugReporter bugReporter)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private boolean
    looks to see if this templateType is a parent of another template type
    parseSignatureAttribute(org.apache.bcel.classfile.Signature signatureAttribute)
    builds a template signature object based on the signature attribute of the method
    void
     
    void
    visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
    implements the visitor to accept the class for visiting
    void
    visitMethod(org.apache.bcel.classfile.Method obj)
    implements the visitor to find methods that declare template parameters that are not bound to any parameter.

    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, visitStackMapEntry

    Methods 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, visitField, visitInnerClass, visitLineNumber, visitLocalVariable, visitLocalVariableTypeTable, visitSignature, visitSourceFile, visitSynthetic, visitUnknown

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.bcel.classfile.Visitor

    visitConstantDynamic, visitMethodParameter, visitModule, visitModuleExports, visitModuleMainClass, visitModuleOpens, visitModulePackages, visitModuleProvides, visitModuleRequires, visitNestHost, visitNestMembers, visitRecord, visitRecordComponent, visitStackMapType
  • Field Details

    • TEMPLATED_SIGNATURE

      private static final Pattern TEMPLATED_SIGNATURE
    • TEMPLATE

      private static final Pattern TEMPLATE
    • bugReporter

      private final edu.umd.cs.findbugs.BugReporter bugReporter
  • Constructor Details

    • UnboundMethodTemplateParameter

      public UnboundMethodTemplateParameter(edu.umd.cs.findbugs.BugReporter bugReporter)
  • Method Details

    • visitClassContext

      public void visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
      implements the visitor to accept the class for visiting
      Specified by:
      visitClassContext in interface edu.umd.cs.findbugs.Detector
      Parameters:
      classContext - the context object of the currently parsed class
    • visitMethod

      public void visitMethod(org.apache.bcel.classfile.Method obj)
      implements the visitor to find methods that declare template parameters that are not bound to any parameter.
      Specified by:
      visitMethod in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitMethod in class edu.umd.cs.findbugs.visitclass.BetterVisitor
      Parameters:
      obj - the context object of the currently parsed method
    • report

      public void report()
      Specified by:
      report in interface edu.umd.cs.findbugs.Detector
    • isTemplateParent

      private boolean isTemplateParent(String templateType, UnboundMethodTemplateParameter.TemplateItem... items)
      looks to see if this templateType is a parent of another template type
      Parameters:
      templateType - the type to look for
      items - the items to search
      Returns:
      whether this template type is something another template type extends
    • parseSignatureAttribute

      @Nullable private static UnboundMethodTemplateParameter.TemplateSignature parseSignatureAttribute(org.apache.bcel.classfile.Signature signatureAttribute)
      builds a template signature object based on the signature attribute of the method
      Parameters:
      signatureAttribute - the signature attribute
      Returns:
      a template signature if there are templates defined, otherwise null