Class ImmatureClass

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

public class ImmatureClass extends edu.umd.cs.findbugs.BytecodeScanningDetector
looks for classes that aren't fully flushed out to be easily usable for various reasons. While the class will most likely work fine, it is more difficult to use than necessary.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static enum 
     
    (package private) static enum 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
     
    private static final Pattern
     
    private edu.umd.cs.findbugs.BugReporter
     
    private boolean
     
     
    private boolean
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final String
     
    private static org.apache.bcel.classfile.JavaClass
     
    private edu.umd.cs.findbugs.OpcodeStack
     

    Fields inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode

    codeBytes, lineNumberTable, M_BR, M_CP, M_INT, M_PAD, M_R, M_UINT

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

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

    Constructors
    Constructor
    Description
    ImmatureClass(edu.umd.cs.findbugs.BugReporter reporter)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    checkIDEGeneratedParmNames(org.apache.bcel.classfile.JavaClass cls)
    looks for methods that have it's parameters all follow the form arg0, arg1, arg2, or parm0, parm1, parm2 etc, where the method actually has code in it
    private static boolean
    classHasRuntimeVisibleAnnotation(org.apache.bcel.classfile.JavaClass cls)
    determines if class has a runtime annotation.
    private static boolean
    classIsJPAEntity(org.apache.bcel.classfile.JavaClass cls)
    returns whether this class is a JPA Entity, as such it shouldn't really have a toString()
    private static boolean
    fieldHasRuntimeVisibleAnnotation(org.apache.bcel.classfile.Field f)
    looks to see the field has a runtime visible annotation, if it does it might be autowired or some other mechanism attached that makes them less interesting for a toString call.
    private static boolean
    hasMethodInHierarchy(org.apache.bcel.classfile.JavaClass cls, String methodName, String methodSig)
    looks to see if this class (or some class in its hierarchy (besides Object) has implemented the specified method.
    private boolean
    isIDEGeneratedMethodWithCode(org.apache.bcel.classfile.Method m)
     
    private static boolean
    isTestClass(org.apache.bcel.classfile.JavaClass cls)
    checks to see if it this class has unit test related annotations attached to methods
    void
    sawOpcode(int seen)
    implements the visitor to check for calls to Throwable.printStackTrace()
    void
    visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
    overrides the visitor to report on classes without toStrings that have fields
    void
    visitCode(org.apache.bcel.classfile.Code obj)
     
    void
    visitField(org.apache.bcel.classfile.Field f)
     
    void
    visitMethod(org.apache.bcel.classfile.Method m)
     

    Methods inherited from class edu.umd.cs.findbugs.BytecodeScanningDetector

    getClassContext, report, shouldVisitCode

    Methods inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode

    afterOpcode, areOppositeBranches, atCatchBlock, beforeOpcode, getBranchFallThrough, getBranchOffset, getBranchTarget, getClassConstantOperand, getClassDescriptorOperand, getCodeByte, getConstantRefOperand, getDefaultSwitchOffset, getDottedClassConstantOperand, getFieldDescriptorOperand, getIntConstant, getLongConstant, getMaxPC, getMethodDescriptorOperand, getNameConstantOperand, getNextCodeByte, getNextOpcode, getNextPC, getOpcode, getPC, getPrevOpcode, getRefConstantOperand, getRefFieldIsStatic, getRegisterOperand, getSigConstantOperand, getStringConstantOperand, getSwitchLabels, getSwitchOffsets, getXClassOperand, getXFieldOperand, getXMethodOperand, isBranch, isMethodCall, isRegisterLoad, isRegisterStore, isRegisterStore, isReturn, isShift, isSwitch, isWideOpcode, printOpCode, sawBranchTo, sawClass, sawDouble, sawField, sawFloat, sawIMethod, sawInt, sawLong, sawMethod, sawRegister, sawString, visit

    Methods inherited from class edu.umd.cs.findbugs.visitclass.AnnotationVisitor

    getAnnotationParameterAsEnum, getAnnotationParameterAsString, getAnnotationParameterAsStringArray, visitAnnotation, visitAnnotation, visitParameterAnnotation, visitParameterAnnotation, visitSyntheticParameterAnnotation

    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, visitAnnotationDefault, visitAnnotationEntry, visitBootstrapMethods, visitConstantInvokeDynamic, visitConstantMethodHandle, visitConstantMethodType, visitConstantModule, visitConstantPackage, visitConstantPool, visitEnclosingMethod, visitingField, visitingMethod, visitInnerClasses, visitJavaClass, visitLineNumberTable, visitLocalVariableTable, visitMethodParameters, 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, visitCodeException, visitConstantClass, visitConstantDouble, visitConstantFieldref, visitConstantFloat, visitConstantInteger, visitConstantInterfaceMethodref, visitConstantLong, visitConstantMethodref, visitConstantNameAndType, visitConstantString, visitConstantUtf8, visitConstantValue, visitDeprecated, visitExceptionTable, 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

    • ARG_PATTERN

      private static final Pattern ARG_PATTERN
    • PACKAGE_INFO

      private static final String PACKAGE_INFO
      See Also:
    • MAX_EMPTY_METHOD_SIZE

      private static final int MAX_EMPTY_METHOD_SIZE
      See Also:
    • MANUAL_SERIALVERSION_ID_LOWER_BOUND

      private static final int MANUAL_SERIALVERSION_ID_LOWER_BOUND
      See Also:
    • MANUAL_SERIALVERSION_ID_UPPER_BOUND

      private static final int MANUAL_SERIALVERSION_ID_UPPER_BOUND
      See Also:
    • serializableClass

      private static org.apache.bcel.classfile.JavaClass serializableClass
    • bugReporter

      private edu.umd.cs.findbugs.BugReporter bugReporter
    • stack

      private edu.umd.cs.findbugs.OpcodeStack stack
    • fieldStatus

      private ImmatureClass.FieldStatus fieldStatus
    • classIsJPAEntity

      private boolean classIsJPAEntity
    • actualReturnType

      private String actualReturnType
    • isRecord

      private boolean isRecord
  • Constructor Details

    • ImmatureClass

      public ImmatureClass(edu.umd.cs.findbugs.BugReporter reporter)
  • Method Details

    • visitClassContext

      public void visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
      overrides the visitor to report on classes without toStrings that have fields
      Specified by:
      visitClassContext in interface edu.umd.cs.findbugs.Detector
      Overrides:
      visitClassContext in class edu.umd.cs.findbugs.BytecodeScanningDetector
      Parameters:
      classContext - the context object of the currently parsed class
    • visitField

      public void visitField(org.apache.bcel.classfile.Field f)
      Specified by:
      visitField in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitField in class edu.umd.cs.findbugs.visitclass.BetterVisitor
    • visitMethod

      public void visitMethod(org.apache.bcel.classfile.Method m)
      Specified by:
      visitMethod in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitMethod in class edu.umd.cs.findbugs.visitclass.BetterVisitor
    • visitCode

      public void visitCode(org.apache.bcel.classfile.Code obj)
      Specified by:
      visitCode in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitCode in class edu.umd.cs.findbugs.visitclass.PreorderVisitor
    • sawOpcode

      public void sawOpcode(int seen)
      implements the visitor to check for calls to Throwable.printStackTrace()
      Overrides:
      sawOpcode in class edu.umd.cs.findbugs.visitclass.DismantleBytecode
      Parameters:
      seen - the currently parsed opcode
    • hasMethodInHierarchy

      private static boolean hasMethodInHierarchy(org.apache.bcel.classfile.JavaClass cls, String methodName, String methodSig) throws ClassNotFoundException
      looks to see if this class (or some class in its hierarchy (besides Object) has implemented the specified method.
      Parameters:
      cls - the class to look in
      methodName - the method name to look for
      methodSig - the method signature to look for
      Returns:
      when toString is found
      Throws:
      ClassNotFoundException - if a super class can't be found
    • classHasRuntimeVisibleAnnotation

      private static boolean classHasRuntimeVisibleAnnotation(org.apache.bcel.classfile.JavaClass cls)
      determines if class has a runtime annotation. If it does it is likely to be a singleton, or handled specially where hashCode/equals isn't of importance.
      Parameters:
      cls - the class to check
      Returns:
      if runtime annotations are found
    • classIsJPAEntity

      private static boolean classIsJPAEntity(org.apache.bcel.classfile.JavaClass cls)
      returns whether this class is a JPA Entity, as such it shouldn't really have a toString()
      Parameters:
      cls - the class to check
      Returns:
      if the class is a jpa entity
    • fieldHasRuntimeVisibleAnnotation

      private static boolean fieldHasRuntimeVisibleAnnotation(org.apache.bcel.classfile.Field f)
      looks to see the field has a runtime visible annotation, if it does it might be autowired or some other mechanism attached that makes them less interesting for a toString call.
      Parameters:
      f - the field to check
      Returns:
      if the field has a runtime visible annotation
    • isTestClass

      private static boolean isTestClass(org.apache.bcel.classfile.JavaClass cls)
      checks to see if it this class has unit test related annotations attached to methods
      Parameters:
      cls - the class to check
      Returns:
      if a unit test annotation was found
    • checkIDEGeneratedParmNames

      private void checkIDEGeneratedParmNames(org.apache.bcel.classfile.JavaClass cls)
      looks for methods that have it's parameters all follow the form arg0, arg1, arg2, or parm0, parm1, parm2 etc, where the method actually has code in it
      Parameters:
      cls - the class to check
    • isIDEGeneratedMethodWithCode

      private boolean isIDEGeneratedMethodWithCode(org.apache.bcel.classfile.Method m)