
Yes, you could lose diff-ability with earlier versions of the class because Eclipse might reformat the whole file, especially if it’s not in your current coding standards. But it could mess up SCM/VCS diffs with earlier versions of the class
#JGRASP SHORTCUTS CODE#
Your version history comparisons become a lot easier as well because any developer working on the code would have done the same formatting and cleanup. You save time by not having to invoke these actions as well, ie. more chance of standardised code in your team. You don’t have to remember to ask Eclipse to organise imports or format code, ie. Remove trailing whitespace: Nice one if you’re obsessive about those blanks at the end of lines.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.

Convert for loops to enhanced: Replaces an index-based loop with an enhanced for loop.Can get annoying sometimes, but mostly worth the trouble. Use final modifier where possible: A nice thing if you want final variables to be marked as final automatically.Add and tags: Nice for compile-time checking.Make sure that Additional actions is ticked.Įclipse can clean up a lot of things, but here’s a list of some of the more useful ones I have enabled: You can see what they are and what you want done by clicking Configure on the same preference page. When you enabled the option “Additional actions”, you told Eclipse to do more cleanups. It basically does a Ctrl+Shift+O whenever you save. With “Organize imports” enabled, Eclipse will automatically reorder imports, prompt for imports to unresolved classes and remove unused imports. 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). Here’s what the settings should look like. Click Ok, edit some code, save it and watch Eclipse format it automatically.Make sure Organize imports is selected.Below I discuss when to use the other option. Select Perform the selected actions on save.Go to Window > Preferences > Java > Editor > Save Actions.

#JGRASP SHORTCUTS HOW TO#
How to enable automatic formatting and cleanupīy default automatic formatting and cleanup is disabled.
