- 1 Steps to Create Profile in Eclipse
- 1.1 Code Organization
- 1.2 Code Style
- 1.3 Member Access
- 1.4 Missing Code
- 1.5 Unnecessary Code
- 2 How to Import Profile XML
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 its 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 clean up 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 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 for you with preferred settings. Just import 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