@ Override public void visitClassContext ( ClassContext classContext ) { try { localizableFields = new HashMap <> ( ) ; visitedBlocks = new BitSet ( ) ; clsContext = classContext ; clsName = clsContext . getJavaClass ( ) . getClassName ( ) ; clsSig = SignatureUtils . classToSignature ( clsName ) ; JavaClass cls = classContext . getJavaClass ( ) ; Field [ ] fields = cls . getFields ( ) ; ConstantPool cp = classContext . getConstantPoolGen ( ) . getConstantPool ( ) ; for ( Field f : fields ) { if ( ! f . isStatic ( ) && ! f . isVolatile ( ) && ( f . getName ( ) . indexOf ( Values . SYNTHETIC_MEMBER_CHAR ) < 0 ) && f . isPrivate ( ) ) { FieldAnnotation fa = new FieldAnnotation ( cls . getClassName ( ) , f . getName ( ) , f . getSignature ( ) , false ) ; boolean hasExternalAnnotation = false ; for ( AnnotationEntry entry : f . getAnnotationEntries ( ) ) { ConstantUtf8 cutf = ( ConstantUtf8 ) cp . getConstant ( entry . getTypeIndex ( ) ) ; if ( ! cutf . getBytes ( ) . startsWith ( Values . JAVA ) ) { hasExternalAnnotation = true ; break ; } } localizableFields . put ( f . getName ( ) , new FieldInfo ( fa , hasExternalAnnotation ) ) ; } } if ( ! localizableFields . isEmpty ( ) ) { buildMethodFieldModifiers ( classContext ) ; super . visitClassContext ( classContext ) ; for ( FieldInfo fi : localizableFields . values ( ) ) { FieldAnnotation fa = fi . getFieldAnnotation ( ) ; SourceLineAnnotation sla = fi . getSrcLineAnnotation ( ) ; BugInstance bug = new BugInstance ( this , BugType . FCBL_FIELD_COULD_BE_LOCAL . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addField ( fa ) ; if ( sla != null ) { bug . addSourceLine ( sla ) ; } bugReporter . reportBug ( bug ) ; } } } finally { localizableFields = null ; visitedBlocks = null ; clsContext = null ; methodFieldModifiers = null ; } }
overrides the visitor to collect localizable fields and then report those that survive all method checks .