Automatically format and cleanup code every time you save | Eclipse On E
How does Eclipse "clean up" the code
With "Format source code" enabled, the code is formatted according to the formatting rules you've specified under Java > Code Style > Formatter (or project-specific formatting if enabled).
With "Organize imports" enabled, Eclipse will automatically reorder imports, prompt for imports to unresolved classes and remove unused imports. It basically does a Ctrl+Shift+O whenever you save.
When you enabled the option "Additional actions", you told Eclipse to do more cleanups. You can see what they are and what you want done by clicking Configure on the same preference page. Make sure that Additional actions is ticked.
Eclipse can clean up a lot of things, but here's a list of some of the more useful ones I have enabled:
- Add @Override and @Deprecated tags: Nice for compile-time checking. Under the Missing Code tab.
- Use final modifier where possible: A nice thing if you want final variables to be marked as final automatically. Can get annoying sometimes, but mostly worth the trouble. Under the Code Style tab.
- Convert for loops to enhanced: Replaces an index-based loop with an enhanced for loop. It just reads better. Under the Code Style tab.
- Use blocks in if/while/for/do statements: Forget religious wars, I've programmed long enough to know that you always use braces even for single line blocks. Eclipse can do this automatically. Under the Code Style tab.
- Remove trailing whitespace: Nice one if you're obsessive about those blanks at the end of lines. Under the Code Organizing tab.
Read full article from Automatically format and cleanup code every time you save | Eclipse On E
No comments:
Post a Comment