private void removeDeadFields ( String clazz , List < BodyDeclaration > declarations ) { Iterator < BodyDeclaration > declarationsIter = declarations . iterator ( ) ; while ( declarationsIter . hasNext ( ) ) { BodyDeclaration declaration = declarationsIter . next ( ) ; if ( declaration instanceof FieldDeclaration ) { FieldDeclaration field = ( FieldDeclaration ) declaration ; Iterator < VariableDeclarationFragment > fragmentsIter = field . getFragments ( ) . iterator ( ) ; while ( fragmentsIter . hasNext ( ) ) { VariableDeclarationFragment fragment = fragmentsIter . next ( ) ; // Don't delete any constants because we can't detect their use. Instead, // these are translated by the TypeDeclarationGenerator as #define directives, // so the enclosing type can still be deleted if otherwise empty. VariableElement var = fragment . getVariableElement ( ) ; if ( var . getConstantValue ( ) == null && deadCodeMap . containsField ( clazz , ElementUtil . getName ( var ) ) ) { fragmentsIter . remove ( ) ; } } if ( field . getFragments ( ) . isEmpty ( ) ) { declarationsIter . remove ( ) ; } } } }
Deletes non - constant dead fields from a type s body declarations list .