28 January, 2018

How to add formatter in eclipse

How to add my own or your company specified code formatter into eclipse ? 


Everyday we are facing lots of issues with development environment and its quite genuine. I though to share this steps also to help you to format your code with best practice. Usually, we need to develop a clean, and most readable code. You can add your own formatter into eclipse IDE (I am using Eclipse Mars in my example). But, You can use any other eclipse release version.

Normally we use the formatter with .xml file format. Its, nothing but a set of rules defined in XML. It defines how your code should look like as a structure.

1. Go to ==> Windows ==> Preference 

The below screen will appear.




2. Select ==> Java ==> Code Style ==> Formatter

The below screen will appear.




3. Now click on ==> Import button to import your formatter xml .

 The below screen will appear.




Now you can see the active formatter in eclipse, please see the below image with highlighted area.



The above image shows your selected formatter, now you are ready to do the code formatting as per your defined rule in the formatter xml , that you have just now imported. Now, you can  see the active profile as your formatter. You can use your keyboard shortcut key (Ctrl+Shift+F) for format the code or you can use the code format option from menu options.

In my next post I will post how to define the rules for write your own formatter. So, please keep following me.



Hope it will help you.



No comments:

Post a Comment