Improving Code Consistency and Standards Compliance with Eclipse Preferences, Page 2
The menus are very intuitive, so if you already have coding standards written you should be able to configure the profile in less than an hour. Of course, if you don't, now is the perfect time to establish them. When you have completed each section, click Apply to save it to your profile.
Once your profile is completed, many aspects will take immediate effect, such as the formatting of braces when using wizard-generated code such as getters and setters. Other options, such as Align fields in columns, require using the Source\Format option from the menu.
Figure 4: Source\Format Option
This option can also be used on code written before the creation of the profile to quickly format using your profile.
Figure 5: Before: Old, Unformatted Code
Figure 6: After: Standardized Formatting in an Instant
Once you have your formatting profile defined, you can export it from the Formatter Edit menu.
Figure 7: Exporting Custom Format Profile
This XML file can be imported into a team member's installations from the initial Formatter dialog screen. For the curious, below is an example of the exported XML (which can be edited by hand for those who prefer that approach):
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <profiles version="11"> <profile kind="CodeFormatterProfile" name="Scott" version="11"> <setting id="org.eclipse.jdt.core.formatter. comment.insert_new_line_before_root_tags" value="insert"/> <setting id="org.eclipse.jdt.core.formatter. insert_space_after_comma_in_annotation" value="insert"/> <setting id="org.eclipse.jdt.core.formatter. insert_space_before_comma_in_type_parameters" value="do not insert"/>