Package com.mebigfatguy.fbcontrib.detect
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 ClassesModifier and TypeClassDescription(package private) static enum(package private) static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate static final Patternprivate edu.umd.cs.findbugs.BugReporterprivate booleanprivate ImmatureClass.FieldStatusprivate booleanprivate static final intprivate static final intprivate static final intprivate static final Stringprivate static org.apache.bcel.classfile.JavaClassprivate edu.umd.cs.findbugs.OpcodeStackFields inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode
codeBytes, lineNumberTable, M_BR, M_CP, M_INT, M_PAD, M_R, M_UINTFields inherited from interface edu.umd.cs.findbugs.Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckIDEGeneratedParmNames(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 itprivate static booleanclassHasRuntimeVisibleAnnotation(org.apache.bcel.classfile.JavaClass cls) determines if class has a runtime annotation.private static booleanclassIsJPAEntity(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 booleanfieldHasRuntimeVisibleAnnotation(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 booleanhasMethodInHierarchy(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 booleanisIDEGeneratedMethodWithCode(org.apache.bcel.classfile.Method m) private static booleanisTestClass(org.apache.bcel.classfile.JavaClass cls) checks to see if it this class has unit test related annotations attached to methodsvoidsawOpcode(int seen) implements the visitor to check for calls to Throwable.printStackTrace()voidvisitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext) overrides the visitor to report on classes without toStrings that have fieldsvoidvisitCode(org.apache.bcel.classfile.Code obj) voidvisitField(org.apache.bcel.classfile.Field f) voidvisitMethod(org.apache.bcel.classfile.Method m) Methods inherited from class edu.umd.cs.findbugs.BytecodeScanningDetector
getClassContext, report, shouldVisitCodeMethods 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, visitMethods inherited from class edu.umd.cs.findbugs.visitclass.AnnotationVisitor
getAnnotationParameterAsEnum, getAnnotationParameterAsString, getAnnotationParameterAsStringArray, visitAnnotation, visitAnnotation, visitParameterAnnotation, visitParameterAnnotation, visitSyntheticParameterAnnotationMethods 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, 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, 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
-
ARG_PATTERN
-
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
-
classIsJPAEntity
private boolean classIsJPAEntity -
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:
visitClassContextin interfaceedu.umd.cs.findbugs.Detector- Overrides:
visitClassContextin classedu.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:
visitFieldin interfaceorg.apache.bcel.classfile.Visitor- Overrides:
visitFieldin classedu.umd.cs.findbugs.visitclass.BetterVisitor
-
visitMethod
public void visitMethod(org.apache.bcel.classfile.Method m) - Specified by:
visitMethodin interfaceorg.apache.bcel.classfile.Visitor- Overrides:
visitMethodin classedu.umd.cs.findbugs.visitclass.BetterVisitor
-
visitCode
public void visitCode(org.apache.bcel.classfile.Code obj) - Specified by:
visitCodein interfaceorg.apache.bcel.classfile.Visitor- Overrides:
visitCodein classedu.umd.cs.findbugs.visitclass.PreorderVisitor
-
sawOpcode
public void sawOpcode(int seen) implements the visitor to check for calls to Throwable.printStackTrace()- Overrides:
sawOpcodein classedu.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 inmethodName- the method name to look formethodSig- 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)
-