I am able to format my Java code by configuring it in Save Actions. What I get after Saving the file is that the whole code gets formatted according to my settings. What I need is, that only a part of code gets formatted according to the settings. Say, there are 10 methods in my code and I add one more to it. What I want is that only my 11th method gets formatted and the previous 10 gets untouched. Is that possible? I am using Eclipse Mars NOTE: The format includes, removing unnecessary casts, parenthesis, etc.
5 Answers
Source code formatting on save can be limited to edited lines only:
The other save actions however are applied to the whole file.
1 Comment
Telling Eclipse "manually" which parts of your code to format and which not can be a daunting task. Especially if others work on the same project and don't know which parts of the code have to be left out.
Because of this Eclipse allows you to set "markers", simply surround your code with these tags:
// @formatter:off
Here goes your code
// @formatter:on
In order to make this work you have to adjust the Java Code Formatter (it can be reached via Window / Preferences) settings like this:
As far as I know this has been in Eclipse since version 3.6.


