Have you ever wanted to clean up your code? Remove unused imports or variables? Eclipse provides this feature, all you have to do is to create a profile !! Here’s how it’s done.
Steps to Create Profile in Eclipse
Go to Windows >> Preferences >> Java >> Code Style >> Clean-Up Click on New button.
In the next window provide a Profile Name of your choice for eg. JBT and click “OK”. It will take you to a new window where you can configure your clean up options.
There are different tabs provided that allows one to set their preferences for the profile.
Listed below are the cleanup options.
- Format Source Code
- Remove Trailing Whitespace
- Correct Indention
- Organize Import
- Sort Members (Caution)
- Use blocks in loop Statements
- Convert for Loops to Enhanced for loops
- Use Parentheses in Expression (Caution)
- Use final modifier wherever possible (Caution)
Non Static Access
- Use ‘this’ qualifier for field access
- Use ‘this’ qualifier for method access
- Use Declaring class as a qualifier (Caution)
- Add missing Annotation (Caution)
Potential Programming Model
- Add Serial Version Id
- Add unimplemented Method (Caution)
- Remove unused Imports
- Remove Unused Private Members
- Remove Unused local Variables
- Remove Unnecessary Cast
How to Apply the Profile
Select an application where you want to apply the newly created profile (JBT). Right-click on it and go to Source >> Clean Up. A window will appear as below.
Select Project and Profile and click “Finish”.
Now you know how to clean up your code with the help of Eclipse. I have already created a profile and added it for you with preferred settings. Just import the attached file in your eclipse and start using it with your code.
How to Import Profile XML
Go to Windows >> Preferences >> Java >> Code Style >> Clean Up Click Import button and select XML file. JBT