Eclipse has one beautiful feature to create a new rule to format code in eclipse and then export the same set of rules in XML format and import the same set of rules(XML File) and hence supports quick formatting.
It is used for formatting indentation,braces,white spacing,blank lines,new line,control statement,line wrapping and comment section.
Steps to follow to create a set of rules for formatting the code according to your business requirements are described below:-
It is used for formatting indentation,braces,white spacing,blank lines,new line,control statement,line wrapping and comment section.
Steps to follow to create a set of rules for formatting the code according to your business requirements are described below:-
- Go to Windows(Ctrl + W) -> Preferences(P).Now select Java -> Code Style -> Formatter.
Formatting in Eclipse - Create a new profile.Click on new and give a name to your profile.
Creating new Formatting Profile - Set the rules for formatting by checking the rules that you want to use in your application.
Create rules for formatting Line Wrapping rules for formatting - Click on Export in top right corner to export these settings.Give a name to the file and Click on Save.
Export these Settings - To use these settings throughout the project team,import these settings by importing the XML file created above and click on Apply-> OK.
- If you want this setting to be applicable for a particular project.Go to Project Properties,select Formatter from Java Code Style and click on the check-box Enable project specific settings.Select the Active Profile and click on Apply.
Project Specific Formatting - Now to apply formatting to the code everytime you save a File,follow following process:-
Under Preferences, choose Java -> Editor -> Save Actions. Check the "Perform the selected actions on save", and check the "Format source code" box.You can select the profile to be used for formatting from there.
Njoy...:)