@ Override public void visitCode ( Code obj ) { unusedParms . clear ( ) ; regToParm . clear ( ) ; stack . resetForMethodEntry ( this ) ; Method m = getMethod ( ) ; String methodName = m . getName ( ) ; if ( IGNORE_METHODS . contains ( methodName ) ) { return ; } int accessFlags = m . getAccessFlags ( ) ; if ( ( ( accessFlags & ( Const . ACC_STATIC | Const . ACC_PRIVATE ) ) == 0 ) || ( ( accessFlags & Const . ACC_SYNTHETIC ) != 0 ) ) { return ; } List < String > parmTypes = SignatureUtils . getParameterSignatures ( m . getSignature ( ) ) ; if ( parmTypes . isEmpty ( ) ) { return ; } int firstReg = 0 ; if ( ( accessFlags & Const . ACC_STATIC ) == 0 ) { ++ firstReg ; } int reg = firstReg ; for ( int i = 0 ; i < parmTypes . size ( ) ; ++ i ) { unusedParms . set ( reg ) ; regToParm . put ( Integer . valueOf ( reg ) , Integer . valueOf ( i + 1 ) ) ; String parmSig = parmTypes . get ( i ) ; reg += SignatureUtils . getSignatureSize ( parmSig ) ; } try { super . visitCode ( obj ) ; if ( ! unusedParms . isEmpty ( ) ) { LocalVariableTable lvt = m . getLocalVariableTable ( ) ; reg = unusedParms . nextSetBit ( firstReg ) ; while ( reg >= 0 ) { LocalVariable lv = ( lvt == null ) ? null : lvt . getLocalVariable ( reg , 0 ) ; if ( lv != null ) { String parmName = lv . getName ( ) ; bugReporter . reportBug ( new BugInstance ( this , BugType . UP_UNUSED_PARAMETER . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addString ( "Parameter " + regToParm . get ( Integer . valueOf ( reg ) ) + ": " + parmName ) ) ; } reg = unusedParms . nextSetBit ( reg + 1 ) ; } } } catch ( StopOpcodeParsingException e ) { // no unusedParms left } }
implements the visitor to clear the parm set and check for potential methods