Is there a way to remove all unused field declarations automatically in Android Studio/Intellij ?
In IntelliJ, in a . java file, some unused code is greyed out indicating that the declared variable or function is never used. Unused imports are removed using Ctrl+Alt+O.
Just use Analyze | Inspect Code with appropriate inspection enabled (Unused declaration under Declaration redundancy group). @CrazyCoder This shows unused fields and methods too, any way to show only unused classes? My 2 cents: on IntelliJ 2016.3. 4 the option is under Analyze > Run Inspection By Name.
You can use 'Source > Clean Up...' to remove unused local variables and private members. Yout will have to configure a custom profile to do this. You can do this in the Clean Up dialog or in the 'Java > Code Style > Clean Up' page in the Preferences.
Select Analyze > Run Inspection by Name...
, type unused declaration
and confirm with Enter. When the search is finished, select Unused declaration
from the result tab, right click and select Safe delete
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With