Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove unused variable declarations automatically - Android Studio/Inteiij

Is there a way to remove all unused field declarations automatically in Android Studio/Intellij ?

like image 610
Vivek Malhotra Avatar asked Jun 05 '15 14:06

Vivek Malhotra


People also ask

How do I delete unused variables in 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.

How do I find unused variables in IntelliJ?

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.

How do you remove unused variables in Java?

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.


1 Answers

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:

enter image description here

like image 197
Darek Kay Avatar answered Oct 18 '22 22:10

Darek Kay