Thursday, August 11, 2011

CleanUp Unused Code - Eclipse rocks!!!!

We have serious discussions in our organization on cleaning up unused code.

What the heck is that unused code? 

Went back to my code and was figuring out what does that unused code mean. Then i was able to see yellow marks in my side bar in eclipse saying "The import is not used anywhere", "This local variable is never read locally", "This private method is never getting called".

Now i got what is meant by unused code. So was trying how can i remove this nonsense in few clicks as i don't want to go each file or see all the warnings and do the code cleanup. Eclipse is one such a software that i used to get amazed often. Here we go with the below steps..boommm...all the unused code is gone.


Window - > Preferences -> Java -> Code Style -> Clean Up


















Click New to create our own Custom Profile.















Since we are concentrated on removing unnecessary code we can remove the options in other tabs and just concentrate on the options in “Unnecessary Code” tab.

















By doing above we have created a profile for doing clean up and now right click on any project in eclipse, go to Source -> CleanUp. By default the project points to Eclipse-built in clean up. You can change this to your custom profile and click Next.
Here you go and it cleans hell a lot of code for us.


2 comments: